diff --git a/php/profile.php b/php/profile.php index bc8b8ed..3cbd1dc 100644 --- a/php/profile.php +++ b/php/profile.php @@ -1,9 +1,8 @@ - "|", "["=>"{", "]"=>"}", "~"=>"^"); $usernameCanonical = strtr($username, $ircLowerSymbols); @@ -12,7 +11,53 @@ if(array_key_exists('username', $_GET)) { $username = ''; $usernameCanonical = ''; } + +if ($db && $username != '') { + $q = $db->prepare('select + tl.username as usrname, + sum(tl2.t * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as count, + sum(tl2.p * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as score, + (select sum(points_made) from triviauserlog t3 where username_canonical=:username) as points, + (select sum(num_answered) from triviauserlog t4 where username_canonical=:username) as q_asked, + (select num_editted from triviausers where username_canonical=:username) as num_e, + (select num_editted_accepted from triviausers where username_canonical=:username) as num_e_accepted, + (select num_questions_added from triviausers where username_canonical=:username) as num_q, + (select num_questions_accepted from triviausers where username_canonical=:username) as num_q_accepted, + (select num_reported from triviausers where username_canonical=:username) as num_r + from (select tl3.id as id2, tl3.average_time * 1.0 as t, tl3.average_score * 1.0 as p, tl3.num_answered * 1.0 as n from triviauserlog tl3) tl2 + inner join triviauserlog tl + on tl.username_canonical=:username + and tl.id=tl2.id2'); + $q->execute(array(':username'=>$usernameCanonical)); + if ($q === false) { + die("Error: database error: table does not exist\n"); + } else { + $result = $q->fetchAll(); + if(sizeOf($result) > 0) { + $result = $result[0]; + } + + if(is_null($result['usrname'])) { + $result['usrname'] = "Not found"; + $result['count'] = 0; + $result['score'] = 0; + $result['points'] = 0; + $result['q_asked'] = 0; + $result['num_e'] = 0; + $result['num_e_accepted'] = 0; + $result['num_q'] = 0; + $result['num_q_accepted'] = 0; + $result['num_r'] = 0; + + } + } +} else { + if(isset($err)) { + die($err); + } +} ?> + Players · TriviaTime @@ -48,168 +93,104 @@ if(array_key_exists('username', $_GET)) { - prepare('select - tl.username as usrname, - sum(tl2.t * (tl2.n / - (select sum(num_answered) - from triviauserlog - where username_canonical=:username)) -) as count, -sum(tl2.p * (tl2.n / - (select sum(num_answered) - from triviauserlog - where username_canonical=:username)) - ) as score, - (select sum(points_made) from triviauserlog t3 where username_canonical=:username) as points, - (select sum(num_answered) from triviauserlog t4 where username_canonical=:username) as q_asked, - (select num_editted from triviausers where username_canonical=:username) as num_e, - (select num_editted_accepted from triviausers where username_canonical=:username) as num_e_accepted, - (select num_questions_added from triviausers where username_canonical=:username) as num_q, - (select num_questions_accepted from triviausers where username_canonical=:username) as num_q_accepted, - (select num_reported from triviausers where username_canonical=:username) as num_r - from (select - tl3.id as id2, - tl3.average_time * 1.0 as t, - tl3.average_score * 1.0 as p, - tl3.num_answered * 1.0 as n - from triviauserlog tl3 - ) tl2 -inner join triviauserlog tl -on tl.username_canonical=:username -and tl.id=tl2.id2 -'); -$q->execute(array(':username'=>$usernameCanonical)); -if ($q === false) { - die("Error: database error: table does not exist\n"); -} else { - $result = $q->fetchAll(); - if(sizeOf($result) > 0) { - $result = $result[0]; - } - - if(is_null($result['usrname'])) { - $result['usrname'] = "Not found"; - $result['count'] = 0; - $result['score'] = 0; - $result['points'] = 0; - $result['q_asked'] = 0; - $result['num_e'] = 0; - $result['num_e_accepted'] = 0; - $result['num_q'] = 0; - $result['num_q_accepted'] = 0; - $result['num_r'] = 0; - - } -} -} else { - if(isset($err)) { - die($err); - } -} -?> -
-

-

Profile and user summary.

-

-

-
+
+

+

Profile and user summary.

+

+

+
-
-
-

Averages

- - - - - - - - - +
+

Averages

+
Average Time/Question*Average Points/Question*
+ + + + + + + + '; + echo ''; + echo ''; + echo ''; + } + } + ?> + +
Average Time/Question*Average Points/Question*
' . number_format($result['count'],2) . '' . number_format($result['score'],2) . '
+
+
+

Totals

+ + + + + + + + + '; + echo ''; + echo ''; + echo ''; + } + } + ?> + +
Total PointsNumber Answered*
' . number_format($result['points'],0) . '' . number_format($result['q_asked'],0) . '
+
+
+
+
+

Contributions

+ + + + + + + + + + + + '; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + ?> + +
Number EditedEdits AcceptedQuestions AddedQuestions AcceptedReports Made
' . number_format($result['num_e'],0) . '' . number_format($result['num_e_accepted'],0) . '' . number_format($result['num_q'],0) . '' . number_format($result['num_q_accepted'],0) . '' . number_format($result['num_r'],0) . '
+
+
- if(isset($result)) { - if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') { - echo ''; - echo '' . number_format($result['count'],2) . ''; - echo '' . number_format($result['score'],2) . ''; - echo ''; - } - } - ?> - - - -
-

Totals

- - - - - - - - - +
+

* These stats do not include KAOS

+
+ + - if(isset($result)) { - if(!is_null($result['usrname']) && $result['usrname'] != 'Not found') { - echo ''; - echo ''; - echo ''; - echo ''; - } - } - ?> - -
Total PointsNumber Answered*
' . number_format($result['points'],0) . '' . number_format($result['q_asked'],0) . '
-
- -
-
-

Contributions

- - - - - - - - - - - - '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - } - ?> - -
Number EditedEdits AcceptedQuestions AddedQuestions AcceptedReports Made
' . number_format($result['num_e'],0) . '' . number_format($result['num_e_accepted'],0) . '' . number_format($result['num_q'],0) . '' . number_format($result['num_q_accepted'],0) . '' . number_format($result['num_r'],0) . '
-
-
- -
-
-

* These stats do not include KAOS

-
-
- - - + diff --git a/php/stats.php b/php/stats.php index cdf140a..bea8057 100644 --- a/php/stats.php +++ b/php/stats.php @@ -101,129 +101,129 @@ include('config.php'); ' and month=' . $week->format('n') . ' and year=' . $week->format('Y') . ')'; -$week->add($interval); -} -?> -
-

Week Top Scores

- - - - - - - - - - query("SELECT username, sum(points_made) as points FROM triviauserlog WHERE $sqlClause GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); - if ($q === false) { - die("Error: database error: table does not exist\n"); - } else { - $result = $q->fetchAll(); - foreach($result as $key=>$res) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - } - } else { - die($err); + $week->add($interval); } ?> - - -
#UsernamePoints
' . ($key+1) . '' . $res['username'] . '' . number_format($res['points'],0) . '
-
- -
-
-

Month Top Scores

- - - - - - - - - - prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year AND month=:month GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); - $q->execute(array(':year'=>$year, ':month'=>$month)); - if ($q === false) { - die("Error: database error: table does not exist\n"); - } else { - $result = $q->fetchAll(); - foreach($result as $key=>$res) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; +
+

Week Top Scores

+
#UsernamePoints
' . ($key+1) . '' . $res['username'] . '' . number_format($res['points'],0) . '
+ + + + + + + + + query("SELECT username, sum(points_made) as points FROM triviauserlog WHERE $sqlClause GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); + if ($q === false) { + die("Error: database error: table does not exist\n"); + } else { + $result = $q->fetchAll(); + foreach($result as $key=>$res) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + } else { + die($err); } - } - } else { - die($err); - } - ?> - -
#UsernamePoints
' . ($key+1) . '' . $res['username'] . '' . number_format($res['points'],0) . '
-
-
-

Year Top Scores

- - - - - - - - - - - if ($db) { - $q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); - $q->execute(array(':year'=>$year)); - if ($q === false) { - die("Error: database error: table does not exist\n"); - } else { - $result = $q->fetchAll(); - foreach($result as $key=>$res) { - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + +
#UsernamePoints
' . ($key+1) . '' . $res['username'] . '' . number_format($res['points'],0) . '
+
+
+
+
+

Month Top Scores

+ + + + + + + + + + prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year AND month=:month GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); + $q->execute(array(':year'=>$year, ':month'=>$month)); + if ($q === false) { + die("Error: database error: table does not exist\n"); + } else { + $result = $q->fetchAll(); + foreach($result as $key=>$res) { + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + } + } else { + die($err); } - } - } else { - die($err); - } - ?> + ?> + +
#UsernamePoints
' . ($key+1) . '' . $res['username'] . '' . number_format($res['points'],0) . '
+
+
+

Year Top Scores

+ + + + + + + + + + -
#UsernamePoints
-
-
+ if ($db) { + $q = $db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year GROUP BY username_canonical ORDER BY points DESC LIMIT 10"); + $q->execute(array(':year'=>$year)); + if ($q === false) { + die("Error: database error: table does not exist\n"); + } else { + $result = $q->fetchAll(); + foreach($result as $key=>$res) { + echo ''; + echo '' . ($key+1) . ''; + echo '' . $res['username'] . ''; + echo '' . number_format($res['points'],0) . ''; + echo ''; + } + } + } else { + die($err); + } + ?> - + + + + - + + +