Punktzahlverlauf\n"; // geometry defaults $MainWidth = isset($_GET['w']) ? intval($_GET['w']) : (MatchCount * 8); $MainHeight = isset($_GET['h']) ? intval($_GET['h']) : 400; $LabelWidth = 240; $ArrowWidth = 32; $LabelSize = 13; $LabelSpacing = 4; // top-N selection defaults $endrank = isset($_GET['top']) ? intval($_GET['top']) : 10; $endhist = isset($_GET['add']) ? intval($_GET['add']) : 1; // prepare group picker $gid = isset($_GET['gid']) ? strval(intval($_GET['gid'])) : 0; if (IsAdmin) $groups = Query("SELECT id, name FROM wm_groups"); else $groups = Query(<<0, 'name'=>"Gesamt"); $sep = "

Gruppen:\n"; foreach ($groups as $group) { $name = htmlescape($group['name']); if ($group['id'] == $gid) { echo "$sep$name"; } else { echo "$sep$name"; } $sep = " •\n"; } echo "

"; // group validity check if ($gid && !isset($groups[$gid])) { echo "

Ungültige Gruppe!

"; EndPage(); CloseDB(); die; } // end-rank and historical rank picker echo "

Anzeige:\n"; foreach (array( "nur Sieger" => 1, "Top 3" => 3, "Top 5" => 5, "Top 10" => 10, "alle" => 999, ) as $name => $v) { if ($endrank == $v) echo "$name\n"; else echo "$name\n"; } echo "
Zwischenzeitliche Sieger einschließen:\n"; foreach (array( "ja" => 1, "nein" => 0, ) as $name => $v) { if ($endhist == $v) echo "$name\n"; else echo "$name\n"; } echo "

\n"; // horizontal geometry picker echo "

Breite:\n"; foreach (array( "winzig" => MatchCount, "schmal" => MatchCount * 3, "normal" => MatchCount * 8, "breit" => MatchCount * 24 ) as $name => $w) { if ($MainWidth == $w) echo "$name\n"; else echo "$name\n"; } echo "

\n"; // vertical geometry picker echo "

Höhe:\n"; foreach (array( "flach" => 200, "normal" => 400, "hoch" => 800 ) as $name => $h) { if ($MainHeight == $h) echo "$name\n"; else echo "$name\n"; } echo "

\n"; // collect users and matches $matches = Query("SELECT id, goalsA, goalsB FROM wm_matches WHERE goalsA IS NOT NULL AND goalsB IS NOT NULL ORDER BY time ASC"); $ufields = "wm_users.id, name, bet0, bet16, bet8, bet4, bet2"; if ($gid) $users = Query("SELECT $ufields FROM wm_group_assoc JOIN wm_users ON wm_group_assoc.user = wm_users.id WHERE `group` = $gid", RESOLVE_IDS); else $users = Query("SELECT $ufields FROM wm_users", RESOLVE_IDS); //echo "
"; print_r($users); echo "
"; foreach ($users as &$user) { $user['score'] = 0; $user['rank'] = count($users); $user['maxrank'] = count($users); $user['maxat'] = 9999; $user['graph'] = array(0); } // don't rank the first few matches, as data is too volatile at this point $rankstart = intval(ceil(sqrt(count($matches)))); //echo "rankstart=$rankstart
\n"; // sort users by score, rank them, and add an entry to their graph function add_graph_entry() { global $users, $rankstart; uasort($users, function ($a, $b) { return $b['score'] - $a['score']; }); $rank = 0; $cnt = 0; $score = 9999; foreach ($users as &$user) { $cnt++; if ($user['score'] < $score) { $score = $user['score']; $rank = $cnt; } $user['rank'] = $rank; if ((count($user['graph']) > $rankstart) && ($user['maxrank'] >= $rank)) { $user['maxrank'] = $rank; $user['maxat'] = count($user['graph']); } $user['graph'][] = $user['score']; } } // process regular match bets foreach ($matches as $match) { $dmatch = $match['goalsA'] - $match['goalsB']; $bets = Query("SELECT user, goalsA, goalsB FROM wm_bets WHERE `match`=${match['id']} AND goalsA IS NOT NULL AND goalsB IS NOT NULL"); foreach ($bets as $bet) { $uid = $bet['user']; if (!isset($users[$uid])) { continue; } $user = &$users[$uid]; $dbet = $bet['goalsA'] - $bet['goalsB']; if ($dmatch == $dbet) { $user['score'] += ($match['goalsA'] == $bet['goalsA']) ? ScoreExact : ($dmatch ? ScoreDiff : ScoreEven); } else if ($dmatch * $dbet > 0) { $user['score'] += ScoreWin; } } add_graph_entry(); } // add end-of-tournament bonuses as a pseudo-match $champ = GetChampion(); if ($champ) { foreach ($users as &$user) { $bonus = 0; if ($user['bet0'] == $champ) $bonus += BonusBetScore(0); if ($user['bet16'] == $champ) $bonus += BonusBetScore(16); if ($user['bet8'] == $champ) $bonus += BonusBetScore(8); if ($user['bet4'] == $champ) $bonus += BonusBetScore(4); if ($user['bet2'] == $champ) $bonus += BonusBetScore(2); $user['score'] += $bonus; } add_graph_entry(); } //echo "
"; print_r($users); echo "
"; // select users to be included in the graph $filtered = array(); $maxscore = 0; foreach ($users as &$user) { if (($user['rank'] <= $endrank) || ($user['maxrank'] <= $endhist)) { $filtered[] = $user; } if (!$maxscore) { $maxscore = $user['score']; } } $users = $filtered; // compute graph geometry $TotalWidth = $MainWidth + 2 + $LabelWidth + $ArrowWidth; $TotalHeight = $MainHeight + 2; $xscale = $MainWidth / count($matches); $yscale = floor($MainHeight / $maxscore * 4) / 4; $yuser = $LabelSize + $LabelSpacing; $arrowX0 = $MainWidth + 1; $arrowX1 = $arrowX0 + $ArrowWidth; // list of possible colors; // source: https://sashamaps.net/docs/resources/20-colors/ $colors = array( '#e6194B', '#ffe119', '#4363d8', '#f58231', '#42d4f4', '#911eb4', '#bfef45', '#f032e6', '#469990', '#fabed4', '#9A6324', '#dcbeff', '#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1', '#000075', '#a9a9a9', '#ffffff', '#000000', '#3cb44b' ); //$colors = null; // enable this line to fall back to auto-generated HSV colors // assign colors and Y coordinates $y = -intval($LabelSize * 0.65); $lastY = $y; $cH = 0.0; $cS = 1.0; $cV = 255.0; $cIdx = 0; function clamp($x) { return ($x < 0.0) ? 0.0 : (($x > 1.0) ? 1.0 : $x); } foreach ($users as &$user) { $y = min(max($y + $yuser, intval($MainHeight + 1 - $user['score'] * $yscale)), $TotalHeight - intval($LabelSize * 0.5)); if (($y - $lastY) < $LabelSize) { break; } $lastY = $y; $user['y'] = $y; if ($colors) { $user['color'] = $colors[$cIdx]; $cIdx++; if ($cIdx >= count($colors)) { $cIdx = 0; } } else { $user['color'] = sprintf("#%02X%02X%02X", intval(((clamp(abs($cH - 3.0) - 1.0) - 1.0) * $cS + 1.0) * $cV + 0.5), intval(((clamp(2.0 - abs($cH - 2.0)) - 1.0) * $cS + 1.0) * $cV + 0.5), intval(((clamp(2.0 - abs($cH - 4.0)) - 1.0) * $cS + 1.0) * $cV + 0.5)); $cH += 3.70820393249937; // golden ratio (0.618...), but cH goes from 0...6 if (abs($cH - 2.0) < 1.0) { $cH += 2.0; } // don't get too close to green if ($cH > 6.0) { $cH -= 6.0; } $cV -= 13.37; if ($cV < 160.0) { $cV += 255.0 - 160.0; } $cS -= 0.123; if ($cS < 0.5) { $cS += 0.5; } } } $users = array_reverse($users); // give highest-scoring users the highest Z order //echo "xscale $xscale yscale $yscale yuser $yuser totalsize ${TotalWidth}x$TotalHeight
\n"; // begin of graphics echo "

\n"; echo "\n"; // background frame echo "\n"; // user graphs foreach ($users as &$user) { if (!isset($user['y'])) { continue; } echo "\n"; $n = htmlescape($user['name']); $ty = $user['y'] + intval($LabelSize * 0.35); echo "\n"; echo "${user['rank']}.$n\n"; } // outer frame echo "\n"; // end of graphics echo "

\n"; if (IsAdmin) echo "

Zurück zum Admin-Menü

\n"; EndPage(); CloseDB(); ?>