From 4fe068cd57e18f2600bbc46c9a6e8c7863ee1051 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Tue, 6 Aug 2024 23:03:22 +0200 Subject: [PATCH] feat: Add statistics to about page --- html/about/index.php | 8 ++++- lib/stats.php | 86 ++++++++++++++++++++++++++++++++++++++++++++ view/pages/about.php | 51 ++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 lib/stats.php diff --git a/html/about/index.php b/html/about/index.php index 69fef24..8f44837 100644 --- a/html/about/index.php +++ b/html/about/index.php @@ -2,8 +2,14 @@ require_once __DIR__ . '/../../core.php'; +require_once __DIR__ . '/../../lib/stats.php'; + +$stats = getStatistics(); +$mobStats = getMobStats(); + + $title = "MobMash - About"; -$content = function () { +$content = function () use ($stats, $mobStats) { require __DIR__ . '/../../view/pages/about.php'; }; diff --git a/lib/stats.php b/lib/stats.php new file mode 100644 index 0000000..c5366ef --- /dev/null +++ b/lib/stats.php @@ -0,0 +1,86 @@ +query(<<setFetchMode(PDO::FETCH_ASSOC); + + $result = $query->fetch(); + + $query = $pdo->query("SELECT count(*) AS votes FROM mm_matches"); + $query->setFetchMode(PDO::FETCH_ASSOC); + + $result = array_merge($result, $query->fetch()); + + $query = $pdo->query("SELECT count(*) AS mobs FROM mm_mobs"); + $query->setFetchMode(PDO::FETCH_ASSOC); + + $result = array_merge($result, $query->fetch()); + + $query = $pdo->query(<<= power((SELECT count(*) FROM mm_mobs), 2); + EOF + ); + $query->setFetchMode(PDO::FETCH_ASSOC); + + $result = array_merge($result, $query->fetch()); + + return $result; +} + +function getMobStats(): array { + $mobs = getMobsWithMetaData(); + + return [ + "highest_rating" => array_reduce($mobs, + fn($current, $mob) => $mob["rating"] > $current["rating"] ? $mob : $current, + $mobs[0] + ), + "lowest_rating" => array_reduce($mobs, + fn($current, $mob) => $mob["rating"] < $current["rating"] ? $mob : $current, + $mobs[0] + ), + "most_matches" => array_reduce($mobs, + fn($current, $mob) => $mob["matches"] > $current["matches"] ? $mob : $current, + $mobs[0] + ), + "least_matches" => array_reduce($mobs, + fn($current, $mob) => $mob["matches"] < $current["matches"] ? $mob : $current, + $mobs[0] + ), + "most_wins" => array_reduce($mobs, + fn($current, $mob) => $mob["wins"] > $current["wins"] ? $mob : $current, + $mobs[0] + ), + "least_wins" => array_reduce($mobs, + fn($current, $mob) => $mob["losses"] > $current["losses"] ? $mob : $current, + $mobs[0] + ), + ]; +} \ No newline at end of file diff --git a/view/pages/about.php b/view/pages/about.php index 5c8e082..7a4736d 100644 --- a/view/pages/about.php +++ b/view/pages/about.php @@ -1,3 +1,8 @@ + +

About

@@ -63,6 +68,52 @@ Github. Pull Requests are welcome!

+

Statistics

+ +

+ There are currently mobs in the system. + The top ranked mob is "" with a rating of + . Last place is + "" with a rating of + . +

+

+ "" has fought the most matches: + , out of which it won . + + Which also makes it the mob with the most wins. + + Speaking of wins: The mob with the most wins is "" with + wins out of matches. + +

+

+ Until now, there have been votes. +

+

+ Over the past 6 months, there have been unique voters. On average, each one voted + times with 80 ? "(You people are mad!)" : "" ?> + as the maximum. +

+

+ + So far, none have voted for all pairings yet. : ( + + Coincidentally, that maximum is the highest possible number - this one person voted for every single paring. ^^ + + Coincidentally, that maximum is the highest possible number - visitors voted for every + single paring. D: + +

+

Contact