diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2012-02-04 22:38:54 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2012-02-04 22:38:54 -0800 |
commit | b62253264a94a4ea2d4f92442f882c6adb771578 (patch) | |
tree | 4bc42083ae8b6a838050d6777294845160e3004b /includes | |
parent | 809c2e251ca9adfedf8d8fc43faafae4dad816c8 (diff) | |
download | pathery-b62253264a94a4ea2d4f92442f882c6adb771578.tar.xz |
Stat tracking.
Added support for tracking when a user ranks #1, and when a user ties #1.
Added "Next level at X" to achievement notifications.
Modified some achievement values, but nothing set in stone.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/datas.php | 102 |
1 files changed, 91 insertions, 11 deletions
diff --git a/includes/datas.php b/includes/datas.php index c6f7666..f29f60e 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -118,7 +118,6 @@ function getNotified($userID) { } } } - // ---------- Prepare response $r = "<strong>$aName</strong>"; @@ -128,7 +127,12 @@ function getNotified($userID) { $r .= "Go select this now</a>"; $r .= "</center>"; } - // "Next level at $nextLevelN"; // unavailable data? + $aAry = getAchievementsArray($aType); + $nextLevelRequired = $aAry[($aLevel + 1)][0]; + if ($nextLevelRequired >= 1) { + $nextLevelRequired = number_format($nextLevelRequired); + $r .= "Next level at $nextLevelRequired <br />"; // unavailable data? + } // ---------- Mark that we have notified the user $sql = "UPDATE `achievements` @@ -303,12 +307,13 @@ function getCareerPathArray() { //$cp[0] = array(requiredmoves, type, 'value', 'name'); $cp[1] = array(100, 1, '#229922', 'Green'); $cp[2] = array(400, 1, '#9922ff', 'Purple'); - $cp[3] = array(11, 2,'CircleSmall.png','Small White Circle'); - $cp[4] = array(11, 2,'StarsR_W.png','Starry White'); - $cp[5] = array(11, 2,'StarsR_B.png','Starry Black'); - $cp[6] = array(11, 1, '#a9b1f6', 'Steel Blue'); - $cp[7] = array(5000, 3, '#aafcbb', 'Green'); - $cp[8] = array(7500, 3, '#ffffaa', 'Yellow'); + $cp[3] = array(900, 2,'CircleSmall.png','Small White Circle'); + $cp[4] = array(2000, 2,'StarsR_W.png','Starry White'); + $cp[5] = array(3500, 2,'StarsR_B.png','Starry Black'); + $cp[6] = array(5000, 1, '#a9b1f6', 'Steel Blue'); + $cp[7] = array(7500, 3, '#aafcbb', 'Green'); + $cp[8] = array(10000, 3, '#ffffaa', 'Yellow'); + $cp[8] = array(13000, 3, '#ffbb77', 'Orange'); return $cp; } @@ -318,18 +323,93 @@ function getCareerMazesArray() { //$cp[0] = array(requiredmazes, type, 'value', 'name'); $cm[1] = array(1, 1, '#eeeeee', 'Silver'); $cm[2] = array(5, 1, '#22aaaa', 'Teal'); - $cm[3] = array(20, 1, '#ff3344', 'Red'); + $cm[3] = array(25, 1, '#ff3344', 'Red'); $cm[4] = array(50, 1, '#aaaa22', 'Chartreuse'); - $cm[5] = array(75, 1, '#cc22aa', 'Orange'); - $cm[6] = array(100, 1, '#ff9922', 'Magenta'); + $cm[5] = array(75, 1, '#ff9922', 'Orange'); + $cm[6] = array(100, 1, '#cc22aa', 'Magenta'); return $cm; } + + function apply() { } + +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 + "; + + $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<br >"; + 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; +} + + + + + + ?> |