mirror of
https://github.com/sigmasternchen/mobmash.click
synced 2025-03-15 08:09:02 +00:00
feat: Basic results page
This commit is contained in:
parent
daa84d14c7
commit
a4c2c3876b
8 changed files with 160 additions and 2 deletions
|
@ -15,7 +15,7 @@ function renderChoice(): void {
|
|||
if ($ajax) {
|
||||
include __DIR__ . "/../view/fragments/mobSelection.php";
|
||||
} else {
|
||||
$title = "Test";
|
||||
$title = "MobMash";
|
||||
$content = function() use ($left, $right, $csrfToken) {
|
||||
include __DIR__ . "/../view/pages/mobSelection.php";
|
||||
};
|
||||
|
|
13
html/results/index.php
Normal file
13
html/results/index.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../core.php';
|
||||
require_once __DIR__ . '/../../lib/rating.php';
|
||||
|
||||
$mobs = getMobsWithMetaData();
|
||||
|
||||
$title = "MobMash - Results";
|
||||
$content = function () use ($mobs) {
|
||||
require __DIR__ . '/../../view/pages/results.php';
|
||||
};
|
||||
|
||||
require_once __DIR__ . '/../../view/layout.php';
|
|
@ -102,4 +102,8 @@ h1 {
|
|||
height: 35vw;
|
||||
margin-top: 5.5vw;
|
||||
margin-left: 2.5vw;
|
||||
}
|
||||
|
||||
.results-list img {
|
||||
max-height: 25px;
|
||||
}
|
|
@ -14,4 +14,42 @@ function addMatch(int $mob1, int $mob2, int $winner, string $session): void {
|
|||
global $pdo;
|
||||
$query = $pdo->prepare("INSERT INTO mm_matches (mob1fk, mob2fk, winner, session) VALUES (?, ?, ?, ?)");
|
||||
$query->execute([$mob1, $mob2, $winner, $session]);
|
||||
}
|
||||
|
||||
function getMobsWithMetaData($orderBy = "rating", $direction = "DESC"): array {
|
||||
global $pdo;
|
||||
$query = $pdo->prepare(<<<EOF
|
||||
SELECT
|
||||
row_number() OVER () AS position,
|
||||
*
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
name,
|
||||
image,
|
||||
created,
|
||||
matches,
|
||||
wins,
|
||||
matches - wins AS losses,
|
||||
rating
|
||||
FROM mm_mobs
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
mob,
|
||||
count(*) AS matches,
|
||||
sum(CASE WHEN won THEN 1 ELSE 0 END) AS wins
|
||||
FROM mm_matches_of_mob
|
||||
GROUP BY mob
|
||||
) AS match_metadata
|
||||
ON match_metadata.mob = mm_mobs.id
|
||||
INNER JOIN mm_current_rating AS rating
|
||||
ON rating.mob = mm_mobs.id
|
||||
WHERE enabled
|
||||
ORDER BY rating DESC
|
||||
) AS with_rating
|
||||
EOF
|
||||
. " ORDER BY " . $orderBy . " " . $direction
|
||||
);
|
||||
$query->execute();
|
||||
return $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
|
@ -170,4 +170,34 @@ FROM jsonb_each(
|
|||
FROM mm_rating_history
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
CREATE VIEW mm_rating_trends (mob, rating, "date", id) AS
|
||||
SELECT
|
||||
key AS mob,
|
||||
value AS rating,
|
||||
"date",
|
||||
id
|
||||
FROM (
|
||||
SELECT
|
||||
id,
|
||||
ratings,
|
||||
"date"
|
||||
FROM (
|
||||
SELECT
|
||||
max(id) AS id,
|
||||
"date"
|
||||
FROM (
|
||||
SELECT
|
||||
last_update AS id,
|
||||
date(matches.created) AS "date"
|
||||
FROM mm_history_cache AS history
|
||||
INNER JOIN mm_matches AS matches
|
||||
ON history.last_update = matches.id
|
||||
) AS dates
|
||||
GROUP BY "date"
|
||||
) AS key_dates
|
||||
INNER JOIN mm_history_cache AS history
|
||||
ON key_dates.id = history.last_update
|
||||
) AS ratings_at_key_date,
|
||||
jsonb_each(ratings_at_key_date.ratings) AS ratings(key, value);
|
||||
|
|
40
view/fragments/mobList.php
Normal file
40
view/fragments/mobList.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
$mobs ??= [];
|
||||
?>
|
||||
<table class="results-list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Position
|
||||
</th>
|
||||
<th>
|
||||
<!-- image -->
|
||||
</th>
|
||||
<th>
|
||||
Name
|
||||
</th>
|
||||
<th>
|
||||
Rating
|
||||
</th>
|
||||
<th>
|
||||
Matches
|
||||
</th>
|
||||
<th>
|
||||
Wins
|
||||
</th>
|
||||
<th>
|
||||
Losses
|
||||
</th>
|
||||
<th>
|
||||
Trend
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($mobs as $mob) {
|
||||
require __DIR__ . '/mobListItem.php';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
26
view/fragments/mobListItem.php
Normal file
26
view/fragments/mobListItem.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
$mob ??= [];
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= $mob["position"] ?>
|
||||
</td>
|
||||
<td>
|
||||
<img src="/images/mobs/<?= $mob["image"] ?>" />
|
||||
</td>
|
||||
<td>
|
||||
<?= $mob["name"] ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= number_format($mob["rating"]) ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $mob["matches"] ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $mob["wins"] ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $mob["losses"] ?>
|
||||
</td>
|
||||
</tr>
|
7
view/pages/results.php
Normal file
7
view/pages/results.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
$mobs ??= [];
|
||||
?>
|
||||
<h1>Results</h1>
|
||||
<?php
|
||||
require_once __DIR__ . '/../fragments/mobList.php';
|
||||
?>
|
Loading…
Reference in a new issue