// ========================================================================= // HOT & COLD PLAYERS WIDGET (Compact Flow Version with Full List Link) // ========================================================================= add_shortcode('otg_hot_cold_widget', 'otg_render_hot_cold_widget'); function otg_get_hot_cold_rangers() { global $wpdb; // 1. Get the Rangers' last 10 completed game IDs $recent_games = $wpdb->get_results(" SELECT game_id, game_date FROM otg_rangers_games WHERE game_state IS NULL AND game_type IN (2, 3) ORDER BY game_date DESC, game_id DESC LIMIT 10 "); if (empty($recent_games)) { return ['hot' => [], 'not' => []]; } // Reverse to chronological order (oldest to newest) $recent_games = array_reverse($recent_games); $total_team_games = count($recent_games); // Extract ordered game_ids array for SQL IN clause $game_ids = array_map(function($g) { return intval($g->game_id); }, $recent_games); $game_ids_placeholder = implode(',', $game_ids); // 2. Fetch active Rangers skaters (Strictly excluding Goalies/G) $active_skaters = $wpdb->get_results(" SELECT ID, Name, nhl_id, Position FROM otg_players WHERE Status = 'Rangers' AND nhl_id > 0 AND LOWER(TRIM(Position)) NOT IN ('g', 'goalie', 'goaltender') "); $player_scores = array(); foreach ($active_skaters as $player) { // 3. Fetch player stats across these exact 10 team games $boxscores = $wpdb->get_results($wpdb->prepare(" SELECT game_id, goals, assists, shots FROM otg_rangers_player_boxscores WHERE player_id = %d AND team_abbr = 'NYR' AND game_id IN ($game_ids_placeholder) ", $player->nhl_id), OBJECT_K); // Index array by game_id for O(1) lookup $score = 0; $games_played_count = 0; // 4. Calculate score with recency weight across all 10 Rangers games foreach ($recent_games as $index => $g) { $gid = $g->game_id; // Recency multiplier: 0.1 for oldest of the 10 games, 1.0 for the most recent game $recency_weight = ($index + 1) / $total_team_games; // If player played in this game, use stats; otherwise 0 if (isset($boxscores[$gid])) { $goals = intval($boxscores[$gid]->goals); $assists = intval($boxscores[$gid]->assists); $shots = intval($boxscores[$gid]->shots); $games_played_count++; } else { $goals = 0; $assists = 0; $shots = 0; } // Weighting: Goals (5.0) > Assists (3.0) > SOG (0.4) $game_points = ($goals * 5.0) + ($assists * 3.0) + ($shots * 0.4); $score += ($game_points * $recency_weight); } $player_scores[] = [ 'id' => $player->ID, 'name' => $player->Name, 'score' => round($score, 2), 'games_played' => $games_played_count ]; } // 5. Sort players by score descending usort($player_scores, function($a, $b) { return $b['score'] <=> $a['score']; }); // Top 5 Hottest $hot = array_slice($player_scores, 0, 5); // Coldest (Filter out players who played 0 games in this stretch) $eligible_for_cold = array_filter($player_scores, function($p) { return $p['games_played'] > 0; }); // Re-index and grab bottom 5 from active participants $eligible_for_cold = array_values($eligible_for_cold); $not = array_slice(array_reverse($eligible_for_cold), 0, 5); return [ 'hot' => $hot, 'not' => $not ]; } function otg_render_hot_cold_widget() { $data = otg_get_hot_cold_rangers(); $hot = $data['hot']; $not = $data['not']; // Outer wrapper fills container width naturally $html = '
'; // Flex container for the two lists side by side $html .= '
'; // Who is Hot Box (Orange theme) $html .= '
'; $html .= '

🔥 Who Is Hot

'; $html .= '
    '; if (!empty($hot)) { foreach ($hot as $p) { $formatted_score = number_format($p['score'], 2); $html .= '
  • '; $html .= ''.esc_html($p['name']).''; $html .= ''.$formatted_score.''; $html .= '
  • '; } } else { $html .= '
  • No data available
  • '; } $html .= '
'; // Who is Not Box (Blue theme) $html .= '
'; $html .= '

❄️ Who Is Not

'; $html .= '
    '; if (!empty($not)) { foreach ($not as $p) { $formatted_score = number_format($p['score'], 2); $html .= '
  • '; $html .= ''.esc_html($p['name']).''; $html .= ''.$formatted_score.''; $html .= '
  • '; } } else { $html .= '
  • No data available
  • '; } $html .= '
'; $html .= '
'; // End flex row // Link to Full List Page below the widget $html .= '
'; $html .= 'View Full Rankings →'; $html .= '
'; $html .= '
'; // End outer wrapper return $html; } CuyllRanger – Activity – OutsideTheGarden Boards – Page 52
APRIL
«
Sun
27
Mon
28
Tue
29
Wed
30
Thu
1
Fri
2
Sat
3
»
CuyllRanger
CuyllRanger
Group: Registered
Joined: 2024-12-02
Hall of Famer
3
Follow
I’m not so sure McDavid who has expressed how important a Cu...

In forum Where Smit Hits The Fan

1 year ago
Lmao watching the guy climb out of the pond every time I see...

In forum Where Smit Hits The Fan

1 year ago
I don’t get Carolina at all signing Ehlers now and trading f...

In forum Where Smit Hits The Fan

1 year ago
This pick screams Why?

In forum Where Smit Hits The Fan

1 year ago
In his defence he was a AHL all star last year.

In forum Where Smit Hits The Fan

1 year ago
I hope it was a ECHL contract .

In forum Where Smit Hits The Fan

1 year ago
Goodrow and Trouba were important members of the Rangers. Bu...

In forum Where Smit Hits The Fan

1 year ago
Don’t like him in Carolina. Can’t forget Miller was pretty g...

In forum Where Smit Hits The Fan

1 year ago
Figures.

In forum Where Smit Hits The Fan

1 year ago
There is that and I hear you. But St. Louis showed that don'...

In forum Where Smit Hits The Fan

1 year ago
I think he's going to get a offer Drury can't match unless i...

In forum Where Smit Hits The Fan

1 year ago
Provorov contract a good example why Waddell needs supervisi...

In forum Where Smit Hits The Fan

1 year ago
Some team is going to overpay for Cuylle forcing a Drury mat...

In forum Where Smit Hits The Fan

1 year ago
Ekblad signs for 8 years $6.1 mill per. And watch who Drury ...

In forum Where Smit Hits The Fan

1 year ago
That's what it is. But will a team actually deem him worth t...

In forum Where Smit Hits The Fan

1 year ago
Page 52 / 213