// ========================================================================= // HOT & COLD PLAYERS WIDGET // ========================================================================= add_shortcode('otg_hot_cold_widget', 'otg_render_hot_cold_widget'); function otg_get_hot_cold_rangers() { global $wpdb; // 1. Fetch players where Status is 'Rangers' and nhl_id is valid $active_rangers = $wpdb->get_results(" SELECT ID, Name, nhl_id FROM otg_players WHERE Status = 'Rangers' AND nhl_id > 0 "); $player_scores = array(); foreach ($active_rangers as $player) { // 2. Fetch the last 10 games specifically played FOR the Rangers (team_abbr = 'NYR') $games = $wpdb->get_results($wpdb->prepare(" SELECT b.goals, b.assists, b.shots, g.game_date FROM otg_rangers_player_boxscores b JOIN otg_rangers_games g ON b.game_id = g.game_id WHERE b.player_id = %d AND b.team_abbr = 'NYR' ORDER BY g.game_date DESC, g.game_id DESC LIMIT 10 ", $player->nhl_id)); if (empty($games)) { continue; } // Reverse to chronological order: oldest to newest $games = array_reverse($games); $total_games = count($games); $score = 0; // 3. Apply weighted calculation (more recent games get a higher multiplier weight) foreach ($games as $index => $g) { $recency_weight = ($index + 1) / $total_games; $goals = intval($g->goals); $assists = intval($g->assists); $shots = intval($g->shots); // Goal weight > Assist weight > Shot (SOG) weight $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_analyzed' => $total_games ]; } // 4. Sort players by score descending usort($player_scores, function($a, $b) { return $b['score'] <=> $a['score']; }); // Split into Hot (top 5) and Not (bottom 5) $hot = array_slice($player_scores, 0, 5); $not = array_slice(array_reverse($player_scores), 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']; $html = '
'; // Who is Hot Box (Orange theme) $html .= '
'; $html .= '

🔥 Who Is Hot

'; $html .= '
'; // Who is Not Box (Blue theme) $html .= '
'; $html .= '

❄️ Who Is Not

'; $html .= '
'; $html .= '
'; return $html; } Gerard Gallant – Activity – OutsideTheGarden Boards – Page 40
DECEMBER
«
Sat
18
Sun
19
Mon
20
Tue
21
Wed
22
Thu
23
Fri
24
»
Gerard Gallant
Gerard Gallant
Group: Registered
Joined: 2023-10-19
Team MVP
1
Follow