From f972ce9c56f0bf2201cd302c0055c6ebd06be34b Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 00:43:06 -0600 Subject: Added code for generating and using champion points, and for recalculating them from scratch in the admin panel. Now just need to add them to the scoreboard and the leadboard pages... --- includes/championPoints.php | 180 ++++++++++++++++++++++++++++++++++++++++++++ includes/mapoftheday.php | 2 +- pages/admin.php | 26 +++++-- 3 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 includes/championPoints.php diff --git a/includes/championPoints.php b/includes/championPoints.php new file mode 100644 index 0000000..e824c0c --- /dev/null +++ b/includes/championPoints.php @@ -0,0 +1,180 @@ += '$fromDate' + "; + + mysql_query($sql); +} + +/** + * Adds the champion points for each player for every day after the given date, but before today. + * Thus, if you're using this to add points from yesterday's maps, this should be done + * after the date has changed. + * @param $fromDate The earliest date to count from. SQL date-string format. + * Pass in yesterday's date, for example, to add champion points from yesterday's maps + */ +function addPlayerChampionPointsForMapsOfTheDay($fromDate) +{ + $fromDate = mysql_escape_string($fromDate); + + //TODO: How do you know when an ultra-complex map has completed? + + //Weird syntax of these queries is necessary due to a bug in MySQL with updating a table and selecting a table + //in the same query. See http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/ + $sql1 = " + -- Add the points for tying the map + UPDATE solutions + INNER JOIN + ( + SELECT mapID, MAX(moves) AS moves + FROM solutions AS s2 + GROUP BY mapID + ) AS maxMoves ON maxMoves.mapID = solutions.mapID + INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID + SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth + WHERE mapOfTheDay.mapDate >= '$fromDate' + AND mapOfTheDay.mapType <> 5 + AND solutions.moves = maxMoves.moves + "; + + $sql2 = " + -- Add the extra for being the first to tie the map + UPDATE solutions + SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.") + WHERE solutions.ID IN + ( + SELECT s2.ID + FROM (SELECT * FROM solutions) AS s2 + INNER JOIN mapOfTheDay ON s2.mapID = mapOfTheDay.mapID + WHERE s2.moves = + ( + SELECT MAX(moves) + FROM (SELECT * FROM solutions) AS s3 + WHERE s3.mapID = mapOfTheDay.mapID + ) + AND mapOfTheDay.mapDate >= '$fromDate' + ) + "; + + $sql3 = " + -- Add the points for doing the weekly maps + UPDATE solutions + SET championPointsWorth = + ( + SELECT SUM(".CP_MAX_WORTH_WEEKLY." * + ( + SELECT COUNT(*) + FROM (SELECT * FROM solutions) AS s2 + WHERE s2.mapID = mapOfTheDay.mapID + AND s2.moves < usersSolutions.moves + ) / ( + SELECT GREATEST(COUNT(*)-1, 1) + FROM (SELECT * FROM solutions) AS s2 + WHERE s2.mapID = mapOfTheDay.mapID + ) + ".CP_MIN_WORTH_WEEKLY.") + FROM mapOfTheDay + INNER JOIN (SELECT * FROM solutions) AS usersSolutions ON usersSolutions.mapID = mapOfTheDay.mapID + WHERE usersSolutions.ID = solutions.ID + AND mapOfTheDay.mapType = 5 + ); + "; + + $sql4 = " + -- Add the points for attempting the map + UPDATE solutions + SET championPointsWorth = ".CP_POINTS_FOR_ATTEMPTING." + WHERE championPointsWorth = 0 + AND dateModified >= $fromDate + AND dateModified < CURDATE() + "; + + //TODO: Points for doing challenges too + //TODO: Is summing the entire table every time slow? If so, we should just add the points instead + $sql5 = " + -- Simply re-sum all the points + UPDATE users + SET championPoints = + ( + SELECT SUM(championPointsWorth) + FROM solutions + WHERE solutions.userID = users.ID + ) + "; + + mysql_query($sql1); + mysql_query($sql2); + mysql_query($sql3); + mysql_query($sql4); + mysql_query($sql5); +} + +/** + * Calculates the worth of the maps for yesterday, and distributes points for them + */ +function addChampionPointsForYesterdaysMaps() +{ + $yesterday = strtotime('-1 day', time()); + $yesterdayStr = date('Y-m-d', $yesterday); + calculateMapsChampionPointWorth($yesterdayStr); + addPlayerChampionPointsForMapsOfTheDay($yesterdayStr); +} + +/** + * Recalculates all player's total champion points. + * Will probably be extremely slow, so should not be called often! + */ +function recalculateAllPlayersChampionPoints() +{ + calculateMapsChampionPointWorth(CP_EARLIEST_DATE); + addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE); + //TODO: Champion points for challenges! +} +?> diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index d244635..a8042c7 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/pages/admin.php b/pages/admin.php index 983c4bc..afac6c4 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -6,10 +6,11 @@ htmlHeader();

Administrators Page

News:

+

Buttons:
+ + +

Hello admins, this is our current userlist.

- +
-"; +'; while (list($CUID, $CUsername, $Joined, $LastLogon, $email, $isAdmin) = mysql_fetch_row($result)) { -- cgit v1.2.3 From bc85a3f1cf8030f1d6400f24b70ea16f717350bd Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 00:43:23 -0600 Subject: don't mind me; minor cleanup --- includes/datas.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/datas.php b/includes/datas.php index e99e347..ef978c8 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -781,8 +781,6 @@ function trackMOTDstats($mapType) { return true; } - - //Select Members function getMembers($order, $pageNumber = 1, $pageDivide = 50) { -- cgit v1.2.3 From 468e9a700736166f175b974e185d24d0d2a4f33e Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 00:48:07 -0600 Subject: db.inc.php now only contains the database login info; the actual connection to the DB has been moved to includes/sqlEmbedded. This was done so we don't need to have the db info in two separate files (one of which is in the repo, derp) --- app.php | 2 +- do.php | 4 ++-- globe.php | 4 ++-- includes/datas.php | 4 ++-- includes/mapoftheday.php | 2 +- includes/maps.php | 6 +++--- includes/sqlEmbedded.php | 7 +++++++ includes/sqli.php | 10 +--------- index.php | 2 +- pages/achievements.php | 2 +- pages/admin.php | 2 +- pages/challenge.php | 2 +- pages/challengelist.php | 2 +- pages/cp.php | 2 +- pages/feedback.php | 2 +- pages/gallery.php | 2 +- pages/home.php | 2 +- pages/leaderboard.php | 2 +- pages/login.php | 2 +- pages/massemail.php | 4 ++-- pages/memberlist.php | 2 +- pages/tutorial.php | 2 +- 22 files changed, 34 insertions(+), 35 deletions(-) create mode 100644 includes/sqlEmbedded.php diff --git a/app.php b/app.php index d799a97..7f0ab30 100644 --- a/app.php +++ b/app.php @@ -1,7 +1,7 @@ \ No newline at end of file + \ No newline at end of file diff --git a/includes/maps.php b/includes/maps.php index 6a831c8..03bcd81 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -769,7 +769,7 @@ function formSolution($solution) { //Returns the best solution. function getSolution($userID, $mapID) { - include_once('db.inc.php'); + include_once('sqlEmbedded.php'); $sql = "SELECT `solution`, `moves` FROM `solutions` WHERE `userID` = '$userID' AND @@ -782,7 +782,7 @@ function getSolution($userID, $mapID) { } function getChallengeSolution($userID, $challengeID) { - include_once('db.inc.php'); + include_once('sqlEmbedded.php'); $sql = "SELECT `solution`, `moves` FROM `challengeSolutions` WHERE `userID` = '$userID' AND @@ -795,7 +795,7 @@ function getChallengeSolution($userID, $challengeID) { } function getMapCode($mapID) { - include_once('db.inc.php'); + include_once('sqlEmbedded.php'); $sql = "SELECT `code` FROM `maps` WHERE `ID` = '$mapID' diff --git a/includes/sqlEmbedded.php b/includes/sqlEmbedded.php new file mode 100644 index 0000000..b7a32b5 --- /dev/null +++ b/includes/sqlEmbedded.php @@ -0,0 +1,7 @@ + diff --git a/includes/sqli.php b/includes/sqli.php index 0974380..d19069b 100644 --- a/includes/sqli.php +++ b/includes/sqli.php @@ -1,12 +1,4 @@ \ No newline at end of file diff --git a/index.php b/index.php index 4a69a4e..88172e3 100644 --- a/index.php +++ b/index.php @@ -27,7 +27,7 @@ if (isset($_SESSION['accepted']) AND $_SESSION['accepted'] == 1) //TODO: We could store this data in the session if ($accepted) { $userID = $_SESSION['userID']; - include_once ('./includes/db.inc.php'); + include_once ('./includes/sqlEmbedded.php'); $sql = " SELECT userData.wallColor, diff --git a/pages/achievements.php b/pages/achievements.php index ac7aded..1bb2195 100644 --- a/pages/achievements.php +++ b/pages/achievements.php @@ -7,7 +7,7 @@ htmlHeader(array('profile'), 'Pathery Achievements'); __get('identity'); //I know just where to put this stuff! - require './includes/db.inc.php'; + require './includes/sqlEmbedded.php'; //Unless I already have this information... //* Modify this to WHERE `email` //$sql = "SELECT `ID`, `isAdmin`, `openID`, `displayName` FROM `users` WHERE `email` = '$email'"; diff --git a/pages/massemail.php b/pages/massemail.php index a861500..d45588b 100644 --- a/pages/massemail.php +++ b/pages/massemail.php @@ -6,7 +6,7 @@ htmlHeader(); topbar($Links); include('./includes/datas.php'); -include('./includes/db.inc.php'); +include('./includes/sqlEmbedded.php'); if (isset($_POST['massemail']) AND isset($_SESSION['accepted'])) { @@ -22,7 +22,7 @@ if (isset($_POST['massemail']) AND isset($_SESSION['accepted'])) { if (!is_int($userID)) return; - include_once "includes/db.inc.php"; + include_once "includes/sqlEmbedded.php"; $sql = "SELECT `email` FROM `users` WHERE `ID` = '$userID'"; $result = mysql_query($sql); diff --git a/pages/memberlist.php b/pages/memberlist.php index 22d88b4..3baf456 100644 --- a/pages/memberlist.php +++ b/pages/memberlist.php @@ -13,7 +13,7 @@ htmlHeader( topbar($Links); -include_once ('./includes/db.inc.php'); +include_once ('./includes/sqlEmbedded.php'); include_once ('./includes/datas.php'); diff --git a/pages/tutorial.php b/pages/tutorial.php index 4d2446f..5208a57 100644 --- a/pages/tutorial.php +++ b/pages/tutorial.php @@ -13,7 +13,7 @@ topbar($Links); //TODO: Turn this into a function? if ($accepted) { - include_once ('./includes/db.inc.php'); + include_once ('./includes/sqlEmbedded.php'); $userID = $_SESSION['userID']; $sql = " -- cgit v1.2.3 From 159992a5fa3456e036888c9e9d8a06409f272db6 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 02:46:45 -0600 Subject: Added champion points to leaderboard page --- css/stats.css | 10 ++++++++++ includes/championPoints.php | 7 ++++--- pages/leaderboard.php | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/css/stats.css b/css/stats.css index ab4cb96..23a6003 100644 --- a/css/stats.css +++ b/css/stats.css @@ -112,3 +112,13 @@ td, th { white-space:nowrap; } +.wrapper .col1 #myPoints +{ + text-align: center; + color: #00DDFF; +} + +.wrapper .col1 #myPoints #myPointsValue +{ + font-weight: bold; +} \ No newline at end of file diff --git a/includes/championPoints.php b/includes/championPoints.php index e824c0c..b99fde3 100644 --- a/includes/championPoints.php +++ b/includes/championPoints.php @@ -107,9 +107,9 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate) $sql3 = " -- Add the points for doing the weekly maps UPDATE solutions - SET championPointsWorth = + SET championPointsWorth = championPointsWorth + ( - SELECT SUM(".CP_MAX_WORTH_WEEKLY." * + SELECT IFNULL(SUM(".CP_MAX_WORTH_WEEKLY." * ( SELECT COUNT(*) FROM (SELECT * FROM solutions) AS s2 @@ -119,11 +119,12 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate) SELECT GREATEST(COUNT(*)-1, 1) FROM (SELECT * FROM solutions) AS s2 WHERE s2.mapID = mapOfTheDay.mapID - ) + ".CP_MIN_WORTH_WEEKLY.") + ) + ".CP_MIN_WORTH_WEEKLY."), 0) FROM mapOfTheDay INNER JOIN (SELECT * FROM solutions) AS usersSolutions ON usersSolutions.mapID = mapOfTheDay.mapID WHERE usersSolutions.ID = solutions.ID AND mapOfTheDay.mapType = 5 + AND mapOfTheDay.mapDate >= '$fromDate' ); "; diff --git a/pages/leaderboard.php b/pages/leaderboard.php index 292de60..a256f1c 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -109,7 +109,8 @@ function getStat ($type, $daysAgo = 1) { userData.wallColor, userData.wallEmblem, userData.displayColor, - users.ID as userID + users.ID as userID, + solutions.championPointsWorth FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID @@ -198,7 +199,8 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { userData.wallColor, userData.wallEmblem, userData.displayColor, - users.ID as userID + users.ID as userID, + solutions.championPointsWorth FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID @@ -269,6 +271,7 @@ function displaystats($result, $caption = NULL) { //$r .= ""; $i = 1; + $championPoints = null; while ($row = mysql_fetch_assoc($result)) { $rowcontent = ''; $mapid = $row['mapID']; @@ -293,6 +296,7 @@ function displaystats($result, $caption = NULL) { if ($userID == $_SESSION['userID']) { $promotedContent .= $x; + $championPoints = $row['championPointsWorth']; } else { $content .= $x; } @@ -300,7 +304,12 @@ function displaystats($result, $caption = NULL) { $i++; } - $r = "
IDDisplay name:Joined On:Last LogonEmailAdministrator
"; + $r = ''; + if($championPoints != null) + { + $r .= "
Points earned: $championPoints
"; + } + $r .= "
"; $r .= ""; $r .= $headers; $r .= $promotedContent; -- cgit v1.2.3 From 03c60352dfc39d1272bd1a7136025e5fac17f556 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 02:59:20 -0600 Subject: Minor change to make the challenge_incomplete color less intense --- css/challenge.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/css/challenge.css b/css/challenge.css index 1f51a9e..0380f4f 100644 --- a/css/challenge.css +++ b/css/challenge.css @@ -6,12 +6,12 @@ } #challenge_wrapper #challenges_listing { } .challenge_complete { - color:green; + color:#008000; font-weight: normal; } .challenge_incomplete { font-weight: bold; - color:red; + color:#DD1111; } .challenge_complete a { -- cgit v1.2.3 From 062d17b2721757801bee90764d36384d18f1e4b1 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 03:36:18 -0600 Subject: Moved the social-buttons next to the copyright to make the footer a bit more compact --- css/page.css | 30 +++++++++++++++++++++--------- includes/header.php | 24 +++++++++++------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/css/page.css b/css/page.css index 40027ca..13884dd 100644 --- a/css/page.css +++ b/css/page.css @@ -51,10 +51,9 @@ form { float:left; display:inline; } + .divide { - font-weight:bold; - padding: 15px 15px; - margin: 12px auto; + padding: 15px 0px; text-align: center; position: relative; min-width: 900px; @@ -70,6 +69,25 @@ form { } +.copyAndButtons +{ + margin: 0 auto; + width: 900px; +} + +.copyAndButtons #copy +{ + clear: both; + float: left; + margin-left: 240px; +} + +.copyAndButtons #socialButtons +{ + float: left; + margin: 0 auto; +} + #countdown { text-align: center; margin-top: 5px; @@ -107,12 +125,6 @@ a:hover { -moz-transition:color 0s ease-out; } -.socialButtons { - text-align:right; - margin: 0px auto; - width:890px; -} - .buttons a { margin: 1px; opacity: 0.7; diff --git a/includes/header.php b/includes/header.php index 2a6e940..d0a54bd 100644 --- a/includes/header.php +++ b/includes/header.php @@ -62,16 +62,7 @@ function htmlFooter() { global $footerLinks; - echo "
- - - -
"; + echo "
"; echo "
    "; foreach ($footerLinks as $key => $value) { echo "
  • $value
  • "; @@ -79,9 +70,16 @@ function htmlFooter() { echo "
"; ?> - -
- Copyright © 2011-2012 pathery.com +
+
+ Copyright © 2011-2012 pathery.com +
+
+ Facebook + Reddit + Twitter + Google Plus +

-- cgit v1.2.3 From dd06f9f378dcae2bd12109f644c614721bf60bd4 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 03:36:44 -0600 Subject: Added a fix for IE to remove the border around the social-buttons. --- css/page.css | 1 + 1 file changed, 1 insertion(+) diff --git a/css/page.css b/css/page.css index 13884dd..db32892 100644 --- a/css/page.css +++ b/css/page.css @@ -124,6 +124,7 @@ a:hover { -o-transition:color 0s ease-out; -moz-transition:color 0s ease-out; } +a img {border: none;} /* IE specific: remove outline around image links */ .buttons a { margin: 1px; -- cgit v1.2.3 From 5ea763da739357ff24f5f62ed73a3ccc8d596741 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 03:42:01 -0600 Subject: Updated the copyright! --- includes/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/header.php b/includes/header.php index d0a54bd..52a86f8 100644 --- a/includes/header.php +++ b/includes/header.php @@ -72,7 +72,7 @@ function htmlFooter() { ?>
- Copyright © 2011-2012 pathery.com + Copyright © 2011-2013 pathery.com
Facebook -- cgit v1.2.3 From 56fa59a0efdcd74eb7c2c77436bfa7f598089d36 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 13:09:49 -0600 Subject: Added champion points to the FAQ --- pages/faq.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pages/faq.php b/pages/faq.php index 3df08eb..2cf2709 100644 --- a/pages/faq.php +++ b/pages/faq.php @@ -7,7 +7,8 @@ htmlHeader(array(), 'FAQ', 'How does the pathing work?'); echo soundManager2(); topbar($Links); -include('./includes/maps.php'); +include_once('./includes/maps.php'); +include_once('./includes/championPoints.php'); // Demo maps: @@ -72,6 +73,7 @@ Your question not here? Ask me via the Feedback Page.
  • How does the pathing work? / How does it choose which way to go?
  • How does Multi-path work? (Two paths at once)
  • More than one of the same checkpoint?
  • +
  • What are 'Champion Points?'
  •   @@ -131,6 +133,26 @@ When there's more than one checkpoint, you can completely wall one off.
    +
    + +  +

    What are 'Champion Points?'

    + +

    Champion Points are a way for us to give you recognition for your skills and dedication. They work like this: +

    • Just for attempting a map, you get points. That's points a day just for clicking go!
    • +
    • If you tie the high score, you get anywhere between and points, + depending on how many people tied or didn't tie the high score.
    • +
    • The winner of each map receives an additional small bonus.
    • + On the weekly maps, everyone gets points! The more people you beat, the more points you'll get! ?> + You also receive points for completing additional tasks, like completing challenges, + //getting achievements!, or even liking us on facebook ?> +
    + Make sure to play every day to receive as many points as possible! +

    + +
    +
    +
    -- cgit v1.2.3 From ba103a4ab377808083b60140a523e2f078d0782a Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 14:03:43 -0600 Subject: Made some calculations significantly simpler by adding a 'isHighScore' column to the solutions table. --- includes/championPoints.php | 55 ++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/includes/championPoints.php b/includes/championPoints.php index b99fde3..28b2b78 100644 --- a/includes/championPoints.php +++ b/includes/championPoints.php @@ -9,7 +9,37 @@ define('CP_MAX_WORTH_WEEKLY', 350); define('CP_MIN_WORTH_WEEKLY', 50); define('CP_POINTS_FOR_ATTEMPTING', 5); define('CP_EXTRA_PERCENT_FOR_FIRST', 0.05); + +/** + * Sets a flag on all solutions which are the high score (first to tie the best length) + */ +function setIsHighScoreFlag($fromDate) +{ + $fromDate = mysql_escape_string($fromDate); + + $sql = " + UPDATE solutions + SET solutions.isHighScore = 1 + WHERE solutions.ID IN + ( + SELECT s2.ID + FROM (SELECT * FROM solutions) AS s2 + INNER JOIN mapOfTheDay ON s2.mapID = mapOfTheDay.mapID + WHERE s2.ID = + ( + SELECT s3.ID + FROM (SELECT * FROM solutions) AS s3 + WHERE s3.mapID = s2.mapID + ORDER BY moves DESC, dateModified ASC + LIMIT 1 + ) + AND mapOfTheDay.mapDate >= '$fromDate' + ) + "; + mysql_query($sql); +} + /** * Calculates the worth of all maps' champion points from after the given date * @param $fromDate The earliest date to count from. Use SQL date-string format. @@ -74,9 +104,9 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate) UPDATE solutions INNER JOIN ( - SELECT mapID, MAX(moves) AS moves + SELECT mapID, moves FROM solutions AS s2 - GROUP BY mapID + WHERE isHighScore = 1 ) AS maxMoves ON maxMoves.mapID = solutions.mapID INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth @@ -89,21 +119,11 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate) -- Add the extra for being the first to tie the map UPDATE solutions SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.") - WHERE solutions.ID IN - ( - SELECT s2.ID - FROM (SELECT * FROM solutions) AS s2 - INNER JOIN mapOfTheDay ON s2.mapID = mapOfTheDay.mapID - WHERE s2.moves = - ( - SELECT MAX(moves) - FROM (SELECT * FROM solutions) AS s3 - WHERE s3.mapID = mapOfTheDay.mapID - ) - AND mapOfTheDay.mapDate >= '$fromDate' - ) + WHERE solutions.isHighScore = 1 + AND solutions.dateModified >= $fromDate "; + //TODO: This doesn't work right, weekly maps last more than a day... $sql3 = " -- Add the points for doing the weekly maps UPDATE solutions @@ -125,7 +145,8 @@ function addPlayerChampionPointsForMapsOfTheDay($fromDate) WHERE usersSolutions.ID = solutions.ID AND mapOfTheDay.mapType = 5 AND mapOfTheDay.mapDate >= '$fromDate' - ); + ) + WHERE solutions.dateModified >= $fromDate; "; $sql4 = " @@ -164,6 +185,7 @@ function addChampionPointsForYesterdaysMaps() { $yesterday = strtotime('-1 day', time()); $yesterdayStr = date('Y-m-d', $yesterday); + setIsHighScoreFlag($yesterday); calculateMapsChampionPointWorth($yesterdayStr); addPlayerChampionPointsForMapsOfTheDay($yesterdayStr); } @@ -174,6 +196,7 @@ function addChampionPointsForYesterdaysMaps() */ function recalculateAllPlayersChampionPoints() { + setIsHighScoreFlag(CP_EARLIEST_DATE); calculateMapsChampionPointWorth(CP_EARLIEST_DATE); addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE); //TODO: Champion points for challenges! -- cgit v1.2.3 From 5e0a7d186ceced61f0c3b4c919332aa7b5cd33aa Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 14:35:35 -0600 Subject: Added a championpoints image to all the pages. You're definitely going to want to change it before releasing, though :) --- images/championpoints.png | Bin 0 -> 1484 bytes pages/faq.php | 4 ++-- pages/leaderboard.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 images/championpoints.png diff --git a/images/championpoints.png b/images/championpoints.png new file mode 100644 index 0000000..f6625fe Binary files /dev/null and b/images/championpoints.png differ diff --git a/pages/faq.php b/pages/faq.php index 2cf2709..e9d8e5f 100644 --- a/pages/faq.php +++ b/pages/faq.php @@ -137,8 +137,8 @@ When there's more than one checkpoint, you can completely wall one off.  

    What are 'Champion Points?'

    - -

    Champion Points are a way for us to give you recognition for your skills and dedication. They work like this: + +

    Champion Points are a way to give you recognition for your skills and dedication. They work like this:

    • Just for attempting a map, you get points. That's points a day just for clicking go!
    • If you tie the high score, you get anywhere between and points, depending on how many people tied or didn't tie the high score.
    • diff --git a/pages/leaderboard.php b/pages/leaderboard.php index a256f1c..62cc54d 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -307,7 +307,7 @@ function displaystats($result, $caption = NULL) { $r = ''; if($championPoints != null) { - $r .= "
      Points earned: $championPoints
      "; + $r .= "
      Points earned: $championPoints
      "; } $r .= "
    $caption
    "; $r .= ""; -- cgit v1.2.3 From 3917765f10b0a3024634bef1ff0c49d700abdfa1 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 14:41:12 -0600 Subject: Fixed minor CSS issue with leaderboard page --- css/stats.css | 4 ++-- pages/leaderboard.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/css/stats.css b/css/stats.css index 23a6003..d262a75 100644 --- a/css/stats.css +++ b/css/stats.css @@ -112,13 +112,13 @@ td, th { white-space:nowrap; } -.wrapper .col1 #myPoints +.wrapper .col1 .myPoints { text-align: center; color: #00DDFF; } -.wrapper .col1 #myPoints #myPointsValue +.wrapper .col1 .myPoints .myPointsValue { font-weight: bold; } \ No newline at end of file diff --git a/pages/leaderboard.php b/pages/leaderboard.php index 62cc54d..4636429 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -307,7 +307,7 @@ function displaystats($result, $caption = NULL) { $r = ''; if($championPoints != null) { - $r .= "
    Points earned: $championPoints
    "; + $r .= "
    Points earned: $championPoints
    "; } $r .= "
    $caption
    "; $r .= ""; -- cgit v1.2.3 From 28dab5d36ab1b593ef395e64973d40d24f574dcd Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 15:06:04 -0600 Subject: Replaced wins with champion points on the achievements page & achievement unlocks --- includes/datas.php | 36 +++++++++++++++++------------------- pages/achievements.php | 4 ++-- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/includes/datas.php b/includes/datas.php index 690b83a..6d73230 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -114,7 +114,7 @@ function getNotified($userID) { $aTypeCurrency[1] = "total moves mazed"; $aTypeCurrency[2] = "mazes played"; $aTypeCurrency[3] = "mazes with (tied) top score"; - $aTypeCurrency[4] = "maze wins"; + $aTypeCurrency[4] = "challenge points"; $aName = $aTypeNames[$aType]; $currency = $aTypeCurrency[$aType]; @@ -555,7 +555,7 @@ function getAchievementCurrency($userID, $aType) { // 1, Total Moves "Path Career" //Backdated // 2, Total Solutions (Total maps played) "Mazes Career" //Backdated // 3, Tie Top-Score on a map "Maze Mastery" //Tracked (no backdate) -// 4, Rank#1 Win Top-Score on a map "Wins" //Tracked +// 4, Champion Points! $r = 0; $sql = ''; switch ($aType) { @@ -579,11 +579,9 @@ function getAchievementCurrency($userID, $aType) { AND `type` IN (1, 2, 3, 4)"; break; case 4: - $sql = "SELECT - SUM(`value`) as t - FROM `statistics` - WHERE `userID` = '$userID' - AND `type` IN (32, 33, 34, 35)"; + $sql = "SELECT championPoints + FROM `users` + WHERE `ID` = '$userID'"; break; } if ($sql == '') @@ -618,7 +616,7 @@ function getAchievementsArray($type) { if ($type == 3) return getMazeMasteryArray(); if ($type == 4) - return getWinsArray(); + return getChampionPointsArray(); //Tutorial if ($type == 32) { $r[1] = array(1, 1, '#4444ff', 'Blue'); @@ -697,17 +695,17 @@ function getMazeMasteryArray() { } //TYPE 4 -function getWinsArray() { - //$cp[0] = array(requiredmazewins, type, 'value', 'name'); - $r[1] = array(1, 2, 'DiagonalCover_B.png', 'Light Diagnol Cover', 0); - $r[2] = array(5, 1, '#22aaaa', 'Teal'); - $r[3] = array(15, 2, 'OffsetStripesDiagonal_B.png', 'Dark Diagonal Stripes', 0); - $r[4] = array(30, 2, 'DiamondLargeDonut_W_I.png', 'Inverted Light Annulated Diamond', 0); - $r[5] = array(50, 2, 'StarsR_B.png', 'Dark Stars', 0); - $r[6] = array(75, 2, 'OffsetStripesHorizontal_B_I.png', 'Inverted Dark Horizontal Stripes', 0); - $r[7] = array(100, 2, 'CrossXLDonut_B_I.png', 'Inverted Dark Large Intersection', 0); - $r[8] = array(150, 2, 'DiamondLarge_B.png', 'Dark Large Diamond', 0); - $r[9] = array(225, 1, '#22ff22', 'Neon Lime', 1); +function getChampionPointsArray() { + //$cp[0] = array(requiredpoints, type, 'value', 'name'); + $r[1] = array(100, 2, 'DiagonalCover_B.png', 'Light Diagnol Cover', 0); + $r[2] = array(250, 1, '#22aaaa', 'Teal'); + $r[3] = array(500, 2, 'OffsetStripesDiagonal_B.png', 'Dark Diagonal Stripes', 0); + $r[4] = array(1000, 2, 'DiamondLargeDonut_W_I.png', 'Inverted Light Annulated Diamond', 0); + $r[5] = array(2000, 2, 'StarsR_B.png', 'Dark Stars', 0); + $r[6] = array(4000, 2, 'OffsetStripesHorizontal_B_I.png', 'Inverted Dark Horizontal Stripes', 0); + $r[7] = array(8000, 2, 'CrossXLDonut_B_I.png', 'Inverted Dark Large Intersection', 0); + $r[8] = array(16000, 2, 'DiamondLarge_B.png', 'Dark Large Diamond', 0); + $r[9] = array(32000, 1, '#22ff22', 'Neon Lime', 1); //$r[7] = array(75, 2, 'CircleSmall_W_I.png', 'Inverted Bright Small Circle', 0); return $r; diff --git a/pages/achievements.php b/pages/achievements.php index 1bb2195..6dbabe7 100644 --- a/pages/achievements.php +++ b/pages/achievements.php @@ -499,13 +499,13 @@ foreach($achievements as $aType => $a) { $aTypeNames[1] = "Path Career Level $aLevel!"; $aTypeNames[2] = "Mazes Career Level $aLevel!"; $aTypeNames[3] = "Maze Mastery Level $aLevel!"; - $aTypeNames[4] = "Champion Level $aLevel!"; + $aTypeNames[4] = "Champion Level $aLevel!"; $aTypeNames[32] = 'Tutorial Complete!'; $aTypeCurrency[1] = "total moves mazed"; $aTypeCurrency[2] = "mazes played"; $aTypeCurrency[3] = "mazes with (tied) top score"; - $aTypeCurrency[4] = "maze wins"; + $aTypeCurrency[4] = "champion points"; $name = $aTypeNames[$aType]; $currency = $aTypeCurrency[$aType]; -- cgit v1.2.3 From 994998fcca96e69bfbd7eed09e3c0023aadc2ce1 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 15:57:36 -0600 Subject: Updated CSS of leaderboard page to not get ridiculously large with long names, and not make the points-string off-center --- css/stats.css | 26 +++++++++++++++++++++++--- pages/leaderboard.php | 12 ++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/css/stats.css b/css/stats.css index d262a75..28d6842 100644 --- a/css/stats.css +++ b/css/stats.css @@ -9,7 +9,7 @@ margin-right: 0px; margin-left: 12px; float: left; - width: 300px; + max-width: 340px; height: auto; } .col { @@ -37,6 +37,26 @@ table { td, th { padding: 3px; } + +.leaderboardHeaders .leaderboardHeadersRank, +.leaderboardHeaders .leaderboardHeadersName, +.leaderboardHeaders .leaderboardHeadersMoves, +.leaderboardHeaders .leaderboardHeadersTime +{ + border:1px solid #ccc; +} + +.leaderboardHeaders .leaderboardHeadersRank { width: 40px; } +.leaderboardHeaders .leaderboardHeadersName, +.leaderboardName +{ + max-width: 140px; + text-overflow: ellipsis; + overflow: hidden; +} +.leaderboardHeaders .leaderboardHeadersMoves { width: 45px; } +.leaderboardHeaders .leaderboardHeadersTime { width: 85px; } + .lbrow { /* Temporary adjust for font changes */ font-size:105%; @@ -112,13 +132,13 @@ td, th { white-space:nowrap; } -.wrapper .col1 .myPoints +.myPoints { text-align: center; color: #00DDFF; } -.wrapper .col1 .myPoints .myPointsValue +.myPoints .myPointsValue { font-weight: bold; } \ No newline at end of file diff --git a/pages/leaderboard.php b/pages/leaderboard.php index 4636429..1c6ef89 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -256,11 +256,11 @@ function displayPastMaze($mapType, $name, $daysAgo = 1) { function displaystats($result, $caption = NULL) { //Get names. - $headers = ""; - $headers .= ""; - $headers .= ""; - $headers .= ""; - $headers .= ""; + $headers = ""; + $headers .= ""; + $headers .= ""; + $headers .= ""; + $headers .= ""; $headers .= ""; //Start table //$r .= "
    $caption
    RankNameMovesTime taken
    RankNameMovesTime taken
    "; @@ -288,7 +288,7 @@ function displaystats($result, $caption = NULL) { $x = "\n"; $x .= ""; - $x .= ""; + $x .= ""; //$x .= "'; $x .= ''; $x .= ''; -- cgit v1.2.3 From 35307251560e459615f2a3e5ab6572b3f80cfdd9 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 16:14:51 -0600 Subject: Fixed champion points not showing up correctly in leaderboards weekly/monthly view --- pages/leaderboard.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pages/leaderboard.php b/pages/leaderboard.php index 1c6ef89..b5e3a76 100644 --- a/pages/leaderboard.php +++ b/pages/leaderboard.php @@ -110,7 +110,9 @@ function getStat ($type, $daysAgo = 1) { userData.wallEmblem, userData.displayColor, users.ID as userID, - solutions.championPointsWorth + SUM(CASE WHEN solutions.dateModified < CURDATE() + THEN solutions.championPointsWorth + ELSE 0 END) AS championPointsWorth FROM `maps` JOIN `solutions` ON maps.ID = solutions.mapID @@ -305,7 +307,7 @@ function displaystats($result, $caption = NULL) { } $r = ''; - if($championPoints != null) + if($championPoints != null && $championPoints > 0) { $r .= "
    Points earned: $championPoints
    "; } -- cgit v1.2.3 From 099e2d5ab8effe07b0e5d8c59e18c81f519fd833 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 19:27:39 -0600 Subject: Added totalWins and totalTies columns to the users table. Also, removed all references to the 'statistics' table - it's not needed anymore. --- includes/championPoints.php | 204 --------------------------------- includes/datas.php | 82 +------------- includes/mapoftheday.php | 2 +- includes/playerStats.php | 271 ++++++++++++++++++++++++++++++++++++++++++++ pages/admin.php | 10 +- pages/faq.php | 2 +- pages/memberlist.php | 5 +- 7 files changed, 285 insertions(+), 291 deletions(-) delete mode 100644 includes/championPoints.php create mode 100644 includes/playerStats.php diff --git a/includes/championPoints.php b/includes/championPoints.php deleted file mode 100644 index 28b2b78..0000000 --- a/includes/championPoints.php +++ /dev/null @@ -1,204 +0,0 @@ -= '$fromDate' - ) - "; - - mysql_query($sql); -} - -/** - * Calculates the worth of all maps' champion points from after the given date - * @param $fromDate The earliest date to count from. Use SQL date-string format. - * Pass in yesterday's date, for example, to add champion points from yesterday's maps - */ -function calculateMapsChampionPointWorth($fromDate) -{ - $fromDate = mysql_escape_string($fromDate); - - //We take the worth of the map, multiply by the number of people who tied the high score, then divide by the - //total number of people who attempted the map (minus 1) - $sql = " - UPDATE mapOfTheDay - SET championPointsWorth = GREATEST(".CP_MIN_WORTH.", - ( - CASE mapType - WHEN 1 THEN ".CP_MAX_WORTH_SIMPLE." - WHEN 2 THEN ".CP_MAX_WORTH_NORMAL." - WHEN 3 THEN ".CP_MAX_WORTH_COMPLEX." - WHEN 4 THEN ".CP_MAX_WORTH_SPECIAL." - WHEN 5 THEN ".CP_MAX_WORTH_WEEKLY." - ELSE 0 - END - ) * ( - SELECT COUNT(*) - FROM solutions - WHERE solutions.mapID = mapOfTheDay.mapID - AND solutions.moves < - ( - SELECT MAX(moves) - FROM solutions AS s2 - WHERE s2.mapId = mapOfTheDay.mapID - ) - ) / ( - SELECT GREATEST(COUNT(*)-1, 1) - FROM solutions - WHERE solutions.mapID = mapOfTheDay.mapID - )) - WHERE mapDate >= '$fromDate' - "; - - mysql_query($sql); -} - -/** - * Adds the champion points for each player for every day after the given date, but before today. - * Thus, if you're using this to add points from yesterday's maps, this should be done - * after the date has changed. - * @param $fromDate The earliest date to count from. SQL date-string format. - * Pass in yesterday's date, for example, to add champion points from yesterday's maps - */ -function addPlayerChampionPointsForMapsOfTheDay($fromDate) -{ - $fromDate = mysql_escape_string($fromDate); - - //TODO: How do you know when an ultra-complex map has completed? - - //Weird syntax of these queries is necessary due to a bug in MySQL with updating a table and selecting a table - //in the same query. See http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/ - $sql1 = " - -- Add the points for tying the map - UPDATE solutions - INNER JOIN - ( - SELECT mapID, moves - FROM solutions AS s2 - WHERE isHighScore = 1 - ) AS maxMoves ON maxMoves.mapID = solutions.mapID - INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID - SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth - WHERE mapOfTheDay.mapDate >= '$fromDate' - AND mapOfTheDay.mapType <> 5 - AND solutions.moves = maxMoves.moves - "; - - $sql2 = " - -- Add the extra for being the first to tie the map - UPDATE solutions - SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.") - WHERE solutions.isHighScore = 1 - AND solutions.dateModified >= $fromDate - "; - - //TODO: This doesn't work right, weekly maps last more than a day... - $sql3 = " - -- Add the points for doing the weekly maps - UPDATE solutions - SET championPointsWorth = championPointsWorth + - ( - SELECT IFNULL(SUM(".CP_MAX_WORTH_WEEKLY." * - ( - SELECT COUNT(*) - FROM (SELECT * FROM solutions) AS s2 - WHERE s2.mapID = mapOfTheDay.mapID - AND s2.moves < usersSolutions.moves - ) / ( - SELECT GREATEST(COUNT(*)-1, 1) - FROM (SELECT * FROM solutions) AS s2 - WHERE s2.mapID = mapOfTheDay.mapID - ) + ".CP_MIN_WORTH_WEEKLY."), 0) - FROM mapOfTheDay - INNER JOIN (SELECT * FROM solutions) AS usersSolutions ON usersSolutions.mapID = mapOfTheDay.mapID - WHERE usersSolutions.ID = solutions.ID - AND mapOfTheDay.mapType = 5 - AND mapOfTheDay.mapDate >= '$fromDate' - ) - WHERE solutions.dateModified >= $fromDate; - "; - - $sql4 = " - -- Add the points for attempting the map - UPDATE solutions - SET championPointsWorth = ".CP_POINTS_FOR_ATTEMPTING." - WHERE championPointsWorth = 0 - AND dateModified >= $fromDate - AND dateModified < CURDATE() - "; - - //TODO: Points for doing challenges too - //TODO: Is summing the entire table every time slow? If so, we should just add the points instead - $sql5 = " - -- Simply re-sum all the points - UPDATE users - SET championPoints = - ( - SELECT SUM(championPointsWorth) - FROM solutions - WHERE solutions.userID = users.ID - ) - "; - - mysql_query($sql1); - mysql_query($sql2); - mysql_query($sql3); - mysql_query($sql4); - mysql_query($sql5); -} - -/** - * Calculates the worth of the maps for yesterday, and distributes points for them - */ -function addChampionPointsForYesterdaysMaps() -{ - $yesterday = strtotime('-1 day', time()); - $yesterdayStr = date('Y-m-d', $yesterday); - setIsHighScoreFlag($yesterday); - calculateMapsChampionPointWorth($yesterdayStr); - addPlayerChampionPointsForMapsOfTheDay($yesterdayStr); -} - -/** - * Recalculates all player's total champion points. - * Will probably be extremely slow, so should not be called often! - */ -function recalculateAllPlayersChampionPoints() -{ - setIsHighScoreFlag(CP_EARLIEST_DATE); - calculateMapsChampionPointWorth(CP_EARLIEST_DATE); - addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE); - //TODO: Champion points for challenges! -} -?> diff --git a/includes/datas.php b/includes/datas.php index 6d73230..b29f1c9 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -572,11 +572,9 @@ function getAchievementCurrency($userID, $aType) { WHERE userID = '$userID'"; break; case 3: - $sql = "SELECT - SUM(`value`) as t - FROM `statistics` - WHERE `userID` = '$userID' - AND `type` IN (1, 2, 3, 4)"; + $sql = "SELECT totalTies + FROM `users` + WHERE `userID` = '$userID'"; break; case 4: $sql = "SELECT championPoints @@ -711,74 +709,6 @@ function getChampionPointsArray() { return $r; } -//Used to track statistics on who wins or ties maps at the end of a day. -function trackMOTDstats($mapType) { - // Our rather massive query to get the data we need. - $sql = "SELECT - users.ID as userID, - SUM(solutions.moves) as Moves, - timediff(MAX(dateModified), maps.dateCreated) as Timetaken - FROM `maps` - JOIN `solutions` - ON maps.ID = solutions.mapID - JOIN `users` - ON solutions.userID = users.ID - JOIN `mapOfTheDay` - ON maps.ID = mapOfTheDay.mapID - WHERE - DATE_ADD(CURDATE(), INTERVAL -1 DAY) = - DATE_FORMAT(solutions.dateModified,'%Y-%m-%d') - AND DATE_ADD(CURDATE(), INTERVAL -1 DAY) = - DATE_FORMAT(maps.dateCreated,'%Y-%m-%d') - AND `mapType` = '$mapType' - GROUP BY solutions.userID - ORDER BY Moves DESC, MAX(dateModified) ASC, solutions.ID DESC - "; - - $mainResult = mysql_query($sql); - if ($mainResult) { - $first = true; - while (list($userID, $uMoves, $uTimeTaken) = mysql_fetch_row($mainResult)) { - //echo "$first : userID: $userID uMoves: $uMoves uTimeTaken: $uTimeTaken mapType: $mapType
    "; - do { - //If it's the rank #1 user, we need to repeat to also award him the tie stat. - $repeatThis = false; - $sType = $mapType; - if ($first) { - $bestMoves = $uMoves; - $sType = 31 + $mapType; - $repeatThis = true; - } - if ($uMoves == $bestMoves) { - $sql = "SELECT `ID` FROM `statistics` - WHERE `userID` = '$userID' AND `type` = '$sType'"; - $result = mysql_query($sql); - - if (mysql_num_rows($result) == 0) { - $sql = "INSERT INTO `statistics` (`userID`, `type`, `value`) - VALUES ('$userID', '$sType', 1)"; - $result = mysql_query($sql); - if (!$result) - return false; - } else { - $sql = "UPDATE `statistics` - SET `value` = `value` + 1 - WHERE `userID` = '$userID' AND `type` = '$sType'"; - $result = mysql_query($sql); - if (!$result) - return false; - } - - } else { - break 2; - } - $first = false; - } while ($repeatThis); - } - } - return true; -} - //Select Members function getMembers($order, $pageNumber = 1, $pageDivide = 50) { @@ -826,8 +756,8 @@ function getMembers($order, $pageNumber = 1, $pageDivide = 50) { WHERE solutions.userID = users.ID AND solutions.dateModified < CURRENT_DATE) , 0) AS totalMazes, - SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins, - SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies, + users.totalWins, + users.totalTies, IfNull(userData.wallColor, '#666666') as wallColor, IfNull(userData.displayColor, '#cccccc'), userData.wallEmblem as wallEmblem, @@ -835,8 +765,6 @@ function getMembers($order, $pageNumber = 1, $pageDivide = 50) { users.dateLogin as dateLogin FROM `users` LEFT JOIN `userData` ON users.ID = userData.userID - LEFT JOIN `statistics` ON users.ID = statistics.userID - GROUP BY users.ID $order LIMIT $limitTop, $pageDivide "; diff --git a/includes/mapoftheday.php b/includes/mapoftheday.php index 3a472ba..178dc64 100644 --- a/includes/mapoftheday.php +++ b/includes/mapoftheday.php @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/includes/playerStats.php b/includes/playerStats.php new file mode 100644 index 0000000..b302812 --- /dev/null +++ b/includes/playerStats.php @@ -0,0 +1,271 @@ += '$fromDate' + ) + "; + + mysql_query($sql); +} + +/** + * Calculates the worth of all maps' champion points from after the given date + * @param $fromDate The earliest date to count from. Use SQL date-string format. + * Pass in yesterday's date, for example, to add champion points from yesterday's maps + */ +function calculateMapsChampionPointWorth($fromDate) +{ + $fromDate = mysql_escape_string($fromDate); + + //We take the worth of the map, multiply by the number of people who tied the high score, then divide by the + //total number of people who attempted the map (minus 1) + $sql = " + UPDATE mapOfTheDay + SET championPointsWorth = GREATEST(".CP_MIN_WORTH.", + ( + CASE mapType + WHEN 1 THEN ".CP_MAX_WORTH_SIMPLE." + WHEN 2 THEN ".CP_MAX_WORTH_NORMAL." + WHEN 3 THEN ".CP_MAX_WORTH_COMPLEX." + WHEN 4 THEN ".CP_MAX_WORTH_SPECIAL." + WHEN 5 THEN ".CP_MAX_WORTH_WEEKLY." + ELSE 0 + END + ) * ( + SELECT COUNT(*) + FROM solutions + WHERE solutions.mapID = mapOfTheDay.mapID + AND solutions.moves < + ( + SELECT MAX(moves) + FROM solutions AS s2 + WHERE s2.mapId = mapOfTheDay.mapID + ) + ) / ( + SELECT GREATEST(COUNT(*)-1, 1) + FROM solutions + WHERE solutions.mapID = mapOfTheDay.mapID + )) + WHERE mapDate >= '$fromDate' + "; + + mysql_query($sql); +} + +/** + * Adds the champion points for each player for every day after the given date, but before today. + * Thus, if you're using this to add points from yesterday's maps, this should be done + * after the date has changed. + * @param $fromDate The earliest date to count from. SQL date-string format. + * Pass in yesterday's date, for example, to add champion points from yesterday's maps + */ +function addPlayerChampionPointsForMapsOfTheDay($fromDate) +{ + $fromDate = mysql_escape_string($fromDate); + + //TODO: How do you know when an ultra-complex map has completed? + + //Weird syntax of these queries is necessary due to a bug in MySQL with updating a table and selecting a table + //in the same query. See http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/ + $sql1 = " + -- Add the points for tying the map + UPDATE solutions + INNER JOIN + ( + SELECT mapID, moves + FROM solutions AS s2 + WHERE isHighScore = 1 + ) AS maxMoves ON maxMoves.mapID = solutions.mapID + INNER JOIN mapOfTheDay ON mapOfTheDay.mapID = solutions.mapID + SET solutions.championPointsWorth = mapOfTheDay.championPointsWorth + WHERE mapOfTheDay.mapDate >= '$fromDate' + AND mapOfTheDay.mapDate < CURDATE() + AND mapOfTheDay.mapType <> 5 + AND solutions.moves = maxMoves.moves + "; + + $sql2 = " + -- Add the extra for being the first to tie the map + UPDATE solutions + SET solutions.championPointsWorth = solutions.championPointsWorth * (1 + ".CP_EXTRA_PERCENT_FOR_FIRST.") + WHERE solutions.isHighScore = 1 + AND solutions.dateModified >= $fromDate + AND solutions.dateModified < CURDATE() + "; + + //TODO: This doesn't work right, weekly maps last more than a day... + $sql3 = " + -- Add the points for doing the weekly maps + UPDATE solutions + SET championPointsWorth = championPointsWorth + + ( + SELECT IFNULL(SUM(".CP_MAX_WORTH_WEEKLY." * + ( + SELECT COUNT(*) + FROM (SELECT * FROM solutions) AS s2 + WHERE s2.mapID = mapOfTheDay.mapID + AND s2.moves < usersSolutions.moves + ) / ( + SELECT GREATEST(COUNT(*)-1, 1) + FROM (SELECT * FROM solutions) AS s2 + WHERE s2.mapID = mapOfTheDay.mapID + ) + ".CP_MIN_WORTH_WEEKLY."), 0) + FROM mapOfTheDay + INNER JOIN (SELECT * FROM solutions) AS usersSolutions ON usersSolutions.mapID = mapOfTheDay.mapID + WHERE usersSolutions.ID = solutions.ID + AND mapOfTheDay.mapType = 5 + AND mapOfTheDay.mapDate >= '$fromDate' + AND mapOfTheDay.mapDate < CURDATE() + ) + WHERE solutions.dateModified >= $fromDate; + AND mapOfTheDay.mapDate < CURDATE() + "; + + $sql4 = " + -- Add the points for attempting the map + UPDATE solutions + SET championPointsWorth = ".CP_POINTS_FOR_ATTEMPTING." + WHERE championPointsWorth = 0 + AND dateModified >= $fromDate + AND dateModified < CURDATE() + "; + + //TODO: Points for doing challenges too + //TODO: Is summing the entire table every time slow? If so, we should just add the points instead + $sql5 = " + -- Simply re-sum all the points + UPDATE users + SET championPoints = + ( + SELECT SUM(championPointsWorth) + FROM solutions + WHERE solutions.userID = users.ID + ) + "; + + mysql_query($sql1); + mysql_query($sql2); + mysql_query($sql3); + mysql_query($sql4); + mysql_query($sql5); +} + +/** + * Sets all players wins and draws to 0. Should be done before a total recalculation + */ +function clearWinsAndTies() +{ + $sql = " + UPDATE users + SET totalWins = 0, totalTies = 0; + "; + + mysql_query($sql); +} + +/** + * Calculates players' total wins and draws, adding from the given date + */ +function addWinsAndTies($fromDate) +{ + $sql1 = " + -- Add the players' latest wins + UPDATE users + SET totalWins = totalWins + + ( + SELECT COUNT(*) + FROM solutions + INNER JOIN mapOfTheDay ON solutions.mapID = mapOfTheDay.mapID + WHERE solutions.isHighScore = 1 + AND mapOfTheDay.mapDate >= '$fromDate' + AND mapOfTheDay.mapDate < CURDATE() + AND solutions.userID = users.ID + ); + "; + + $sql2 = " + -- Add the players' latest ties + UPDATE users + SET totalTies = totalTies + + ( + SELECT COUNT(*) + FROM solutions + INNER JOIN mapOfTheDay ON solutions.mapID = mapOfTheDay.mapID + WHERE mapOfTheDay.mapDate >= '$fromDate' + AND mapOfTheDay.mapDate < CURDATE() + AND solutions.userID = users.ID + AND solutions.moves = + ( + SELECT moves + FROM solutions AS s2 + WHERE s2.mapID = mapOfTheDay.mapID + AND s2.isHighScore = 1 + LIMIT 1 + ) + ); + "; + + mysql_query($sql1); + mysql_query($sql2); +} + +/** + * Calculates the worth of the maps for yesterday, and distributes points for them. Also adds wins and ties to + * the correct players + */ +function addStatsForYesterdaysMaps() +{ + $yesterday = strtotime('-1 day', time()); + $yesterdayStr = date('Y-m-d', $yesterday); + setIsHighScoreFlag($yesterday); + calculateMapsChampionPointWorth($yesterdayStr); + addPlayerChampionPointsForMapsOfTheDay($yesterdayStr); + addWinsAndTies($yesterdayStr); +} + +/** + * Recalculates all player's total champion points, wins, and ties. + * Will probably be extremely slow, so should not be called often! + */ +function recalculateStatsForAllPlayers() +{ + setIsHighScoreFlag(CP_EARLIEST_DATE); + calculateMapsChampionPointWorth(CP_EARLIEST_DATE); + addPlayerChampionPointsForMapsOfTheDay(CP_EARLIEST_DATE); + //TODO: Champion points for challenges! + clearWinsAndTies(); + addWinsAndTies(CP_EARLIEST_DATE); +} +?> diff --git a/pages/admin.php b/pages/admin.php index afc6418..0f54285 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -10,7 +10,7 @@ include_once('./includes/datas.php'); include_once('./includes/maps.php'); include_once('./includes/mapoftheday.php'); include_once('./includes/sqlEmbedded.php'); -include_once('./includes/championPoints.php'); +include_once('./includes/playerStats.php'); if ($_GET['applyall'] == 'true') { echo "Apply-All command heard. Executing..."; @@ -27,10 +27,10 @@ if ($_GET['applyall'] == 'true') { echo "Execution complete!"; } -else if ($_GET['recalcChamp'] == 'true') { - echo "Recalculating champion points..."; +else if ($_GET['recalcStats'] == 'true') { + echo "Recalculating all player stats..."; - recalculateAllPlayersChampionPoints(); + recalculateStatsForAllPlayers(); echo "Complete!"; } @@ -45,7 +45,7 @@ echo '

    News:

    Buttons:
    - +

    Hello admins, this is our current userlist.

    diff --git a/pages/faq.php b/pages/faq.php index e9d8e5f..95b0b87 100644 --- a/pages/faq.php +++ b/pages/faq.php @@ -8,7 +8,7 @@ echo soundManager2(); topbar($Links); include_once('./includes/maps.php'); -include_once('./includes/championPoints.php'); +include_once('./includes/playerStats.php'); // Demo maps: diff --git a/pages/memberlist.php b/pages/memberlist.php index 3baf456..2fa2cdc 100644 --- a/pages/memberlist.php +++ b/pages/memberlist.php @@ -115,8 +115,8 @@ $sql = "SELECT WHERE solutions.userID = users.ID AND solutions.dateModified BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND CURRENT_DATE) AS totalMovesThisWeek, (SELECT COUNT(*) FROM solutions WHERE solutions.userID = users.ID AND solutions.dateModified < CURRENT_DATE) AS totalMazes, - SUM(CASE WHEN statistics.type IN (32, 33, 34, 35) THEN statistics.value ELSE 0 END) as totalWins, - SUM(CASE WHEN statistics.type IN (1, 2, 3, 4) THEN statistics.value ELSE 0 END) as totalTies, + users.totalWins, + users.totalTies, IfNull(userData.wallColor, '#666666') as wallColor, IfNull(userData.displayColor, '#cccccc'), userData.wallEmblem, @@ -124,7 +124,6 @@ $sql = "SELECT users.dateLogin as dateLogin FROM `users` LEFT JOIN `userData` ON users.ID = userData.userID -LEFT JOIN `statistics` ON users.ID = statistics.userID GROUP BY users.ID $order "; -- cgit v1.2.3 From cfd201af6cde7e86707c6a5a475b1c9f1e989744 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 19:28:16 -0600 Subject: Adding update notes, since there's a lot that needs to be done to upgrade --- update notes.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 update notes.txt diff --git a/update notes.txt b/update notes.txt new file mode 100644 index 0000000..de93369 --- /dev/null +++ b/update notes.txt @@ -0,0 +1,11 @@ +For next update: +- Move the new columns from BlueRaja's database over to your other databases. Make sure to get not only the type, but nullable/default as well. + (We need to do this in a more sensible way in the future... sorry) +- Drop the 'statistics' table. It's not needed anymore. +- Delete the lines relating to '$mysqlid' from db.inc.php (which I can't do, since that file is not versioned). + Those lines have been moved to sqlEmbedded.php. The only thing that should be left are the four lines defining the servername/username/etc. +- Go to the admin page, and click on the button that says "recalculate player statistics. + + + +Previous updates: \ No newline at end of file -- cgit v1.2.3 From 0e2ff7a5e11fbcd5462a2be61628b5f2eed412ac Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 19:35:52 -0600 Subject: Added a bit more to update notes --- update notes.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/update notes.txt b/update notes.txt index de93369..c19214f 100644 --- a/update notes.txt +++ b/update notes.txt @@ -4,8 +4,9 @@ For next update: - Drop the 'statistics' table. It's not needed anymore. - Delete the lines relating to '$mysqlid' from db.inc.php (which I can't do, since that file is not versioned). Those lines have been moved to sqlEmbedded.php. The only thing that should be left are the four lines defining the servername/username/etc. -- Go to the admin page, and click on the button that says "recalculate player statistics. +- Open includes\playerStats.php, and set CP_EARLIEST_DATE to the date we want to start counting ties/wins/champion points from. + We could also pretty easily recalculate the other stats (mazes and total moves) from that date also, if you want; then that date would be like the 'start' of pathery. +- Go to the admin page in the browser, and click on the button that says "recalculate player statistics." All the above steps must be done before this. - -Previous updates: \ No newline at end of file +Notes from previous updates: \ No newline at end of file -- cgit v1.2.3 From db7f5c43e70cb6497b21109feec445f47bb8997d Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 19:37:25 -0600 Subject: grammar --- update notes.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update notes.txt b/update notes.txt index c19214f..7c57a30 100644 --- a/update notes.txt +++ b/update notes.txt @@ -5,7 +5,7 @@ For next update: - Delete the lines relating to '$mysqlid' from db.inc.php (which I can't do, since that file is not versioned). Those lines have been moved to sqlEmbedded.php. The only thing that should be left are the four lines defining the servername/username/etc. - Open includes\playerStats.php, and set CP_EARLIEST_DATE to the date we want to start counting ties/wins/champion points from. - We could also pretty easily recalculate the other stats (mazes and total moves) from that date also, if you want; then that date would be like the 'start' of pathery. + We could also pretty easily recalculate the other stats (mazes and total moves) from that date, if you want; then that date would be like the 'start' of pathery. - Go to the admin page in the browser, and click on the button that says "recalculate player statistics." All the above steps must be done before this. -- cgit v1.2.3 From d2a9bf56c2625b71016f1ce879aaf10ade57754a Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 20:02:50 -0600 Subject: Small bugfix for not loading disabled challenges --- includes/datas.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/includes/datas.php b/includes/datas.php index b29f1c9..66c816b 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -1058,22 +1058,13 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) function loadChallengeListing($userIdUnsanitized) { $userID = mysql_escape_string($userIdUnsanitized); - $sql = " - SELECT maps.ID AS mapID, maps.challengeTier, maps.name AS name, - challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID - FROM maps - INNER JOIN challenges ON maps.ID = challenges.mapID - LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID - WHERE maps.isChallenge = 1 AND challenges.enabled = 1 - AND (challengeSolutions.userID IS NULL OR challengeSolutions.userID = '$userID') - AND maps.challengeTier <= (SELECT challengeTier FROM users WHERE users.ID = '$userID') - ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering - "; + $sql = " SELECT maps.ID AS mapID, maps.challengeTier, maps.name AS name, challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID FROM challenges LEFT JOIN maps ON challenges.mapID = maps.ID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' + WHERE challenges.enabled = 1 ORDER BY maps.challengeTier, maps.challengeSuborder, challenges.ordering"; $result = mysql_query($sql); -- cgit v1.2.3 From 532faa4d5cc5b20fba8422c87b0aac846874af43 Mon Sep 17 00:00:00 2001 From: BlueRaja Date: Sun, 13 Jan 2013 20:36:11 -0600 Subject: Replaced bullet-points with challenge images on challenge page --- css/challenge.css | 48 +++++++++++++++++++++++++++++++++--------------- pages/challenge.php | 8 +++----- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/css/challenge.css b/css/challenge.css index 0380f4f..787679f 100644 --- a/css/challenge.css +++ b/css/challenge.css @@ -5,11 +5,30 @@ font-weight: bold; } #challenge_wrapper #challenges_listing { } -.challenge_complete { - color:#008000; +.challenge_ulist +{ + list-style-type:none; + padding-left:0px; + margin-left:0px; +} +.challenge_ulist li +{ + /* Replace the bullet-points with challenge complete/incomplete images */ + background-position: 0 5px; + background-repeat: no-repeat; + background-size: 28px 28px; + padding-left: 30px; + padding-top: 6px; +} +.challenge_ulist .challenge_complete +{ + background-image:url('../images/challenge_complete.png'); font-weight: normal; + color:#008000; } -.challenge_incomplete { +.challenge_ulist .challenge_incomplete +{ + background-image:url('../images/challenge_incomplete.png'); font-weight: bold; color:#DD1111; } @@ -21,18 +40,6 @@ display: none; } -.challengelist_map { - float:left; - padding: 15px; - background-color:#333; - margin: 20px; - border-radius:10px; - cursor:pointer; -} -.challengelist_map:hover { - background-color:#444; -} - /** Challenge listing page **/ #challengelist_wrapper #challengelist {} #challengelist_wrapper #challengelist .challengelist_tier { @@ -54,4 +61,15 @@ height: 32px; background-image: url("../images/challenge_incomplete.png"); float: right; +} +.challengelist_map { + float:left; + padding: 15px; + background-color:#333; + margin: 20px; + border-radius:10px; + cursor:pointer; +} +.challengelist_map:hover { + background-color:#444; } \ No newline at end of file diff --git a/pages/challenge.php b/pages/challenge.php index 35c9525..ceefebe 100644 --- a/pages/challenge.php +++ b/pages/challenge.php @@ -131,21 +131,19 @@ function displayChallenges($challengeResultset) { echo '
    '; echo '
    Challenges
    '; - echo '
      '; + echo '
        '; while($challenge = mysql_fetch_array($challengeResultset)) { $mapID = $_GET["mapID"]; $challengeId = $challenge["challengeID"]; - echo "
      • "; if($challenge["dateSolved"] !== NULL) $cssClass = "challenge_complete"; else $cssClass = "challenge_incomplete"; $loadSolutionString = " Load this solution"; - echo "" . getChallengeDisplayString($challenge) . " $loadSolutionString "; - echo "
      • "; + echo "
      • " . getChallengeDisplayString($challenge) . " $loadSolutionString
      • "; } - echo "
    "; + echo ""; } /** -- cgit v1.2.3
    $i$displayName$displayName" . $row['Name'] . '' . $row['Moves'] . '' . $row['Timetaken'] . '