From a431308aa3c6c698d23b45bf5e1f905123e0cba5 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Tue, 8 Jan 2013 01:50:53 -0800 Subject: Fixes/adjustments for the Leaderboard --- pages/leaderboard.php | 103 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 37 deletions(-) (limited to 'pages') diff --git a/pages/leaderboard.php b/pages/leaderboard.php index a457a8d..9f40d8b 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -47,12 +47,20 @@ $datePrevDay = date('Y-m-d', strtotime("-1 day", $dateAgo)); if ($daysAgo < 1) die("You must specify a date previous to today."); + + +$time_start = microtime(true); + $tStats = getStat(1, $daysAgo); $yStats = getStat(2, $daysAgo); - $wStats = getStat(3, $daysAgo); $mStats = getStat(4, $daysAgo); +$time_end = microtime(true); +$time = $time_end - $time_start; + +if ($_GET['debug'] == true) echo "XX StatContent getStat Rechieve: $time seconds XX\n"; + function getStat ($type, $daysAgo = 1) { switch ($type) { @@ -122,7 +130,10 @@ function getStat ($type, $daysAgo = 1) {
-Showing scores for the maps played on +12-28-12. I plan on making considerable changes to this page in the near future. +
Thank you for your patience!
+
+
Showing scores for the maps played on
@@ -133,11 +144,21 @@ if ($daysAgo > 1) { } echo "Previous Day"; + + +$time_start = microtime(true); + $statContent .= displayPastMaze(1, 'Simple', $daysAgo); $statContent .= displayPastMaze(2, 'Normal', $daysAgo); $statContent .= displayPastMaze(3, 'Complex', $daysAgo); $statContent .= displayPastMaze(4, 'Special', $daysAgo); +$time_end = microtime(true); +$time = $time_end - $time_start; + +if ($_GET['debug'] == true) echo "StatContent Rechieve: $time seconds\n"; + + $special = 'Special'; if ($specialMapName != '') $special = $specialMapName; @@ -163,6 +184,11 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { if ($daysAgo < 1) return; + $pastMap = pastMap($mapType, $daysAgo); + $mapID = $pastMap; + $mapcode = getMapCode($mapID); + $map = GenerateMapByCode($mapcode); + $sql = "SELECT maps.ID as mapID, solution, @@ -182,42 +208,33 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { ON maps.ID = mapOfTheDay.mapID LEFT JOIN `userData` ON users.ID = userData.userID - WHERE DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) = - DATE_FORMAT(solutions.dateModified,'%Y-%m-%d') - AND DATE_ADD(CURDATE(), INTERVAL -$daysAgo DAY) = - DATE_FORMAT(maps.dateCreated,'%Y-%m-%d') - AND `mapType` = '$mapType' + WHERE + maps.ID = '$mapID' GROUP BY solutions.userID ORDER BY Moves DESC, `dateModified` ASC "; - $result = mysql_query($sql); - + + $result = mysql_query($sql) or die(mysql_error()); + $statname = "Yesterday's Best $name:"; if ($daysAgo > 1) { $statname = "$daysAgo days ago's Best $name:"; } $stats = displayStats($result, $statname); - $pastMap = pastMap($mapType, $daysAgo); - $mapID = $pastMap; - $mapcode = getMapCode($mapID); - $map = GenerateMapByCode($mapcode); - //Sucky temporary solution: $GLOBALS['specialMapName'] = $map[0][6]; $sql = "SELECT `moves`, `displayName`, `solution` - FROM `solutions`, `users` - WHERE `mapID` = '$mapID' AND - `userID` = users.ID + FROM `solutions` + LEFT JOIN `users` + ON solutions.userID = users.ID + WHERE `mapID` = '$mapID' ORDER BY `moves` DESC, `dateModified` ASC LIMIT 1"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { list($bestMoves, $byName, $solution) = mysql_fetch_row($result); - //echo "Best solution for this map: $bestMoves by $byName"; - //$map = MergeMapSolution($map, $solution); - //echo DisplayMap($map, $mapID); } $r = ''; @@ -229,7 +246,7 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { $r .= '
'; $r .= "Best solution for this map: $bestMoves by $byName "; - $r .= DisplayMap($map, $mapID, 'example', 2); + $r .= DisplayMap($map, $mapID, 'normal', 2); $r .= '
'; $r .= '
'; return $r; @@ -237,17 +254,19 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { function displaystats($result, $caption = NULL) { //Get names. + $headers = ""; $headers .= "Rank"; $headers .= "Name"; $headers .= "Moves"; $headers .= "Time taken"; + $headers .= ""; //Start table - $r .= ""; - $r .= ""; + //$r .= "
$caption
"; + //$r .= ""; //Headers on the top. including Rank. - $r .= ""; - $r .= $headers; - $r .= ""; + //$r .= ""; + //$r .= $headers; + //$r .= ""; $i = 1; while ($row = mysql_fetch_assoc($result)) { @@ -263,16 +282,30 @@ function displaystats($result, $caption = NULL) { //Default if ($wallColor == '') $wallColor = '#666666'; + + $x = "\n"; + $x .= ""; + $x .= ""; + //$x .= "'; + $x .= ''; + $x .= ''; + $x .= ""; + + if ($userID == $_SESSION['userID']) { + $promotedContent .= $x; + } else { + $content .= $x; + } - $r .= "\n"; - $r .= ""; - $r .= ""; - //$r .= "'; - $r .= ''; - $r .= ''; - $r .= ""; $i++; } + + $r = "
$caption
$i$displayName" . $row['Name'] . '' . $row['Moves'] . '' . $row['Timetaken'] . '
$i$displayName" . $row['Name'] . '' . $row['Moves'] . '' . $row['Timetaken'] . '
"; + $r .= ""; + $r .= $headers; + $r .= $promotedContent; + $r .= $content; + $r .= "
$caption
"; return $r; } @@ -329,10 +362,6 @@ function showStats(type) { showStats(1); -
- Copyright © 2011-2012 pathery.com -
- -- cgit v1.2.3