Add more detailed ranking calculations
This commit is contained in:
		
							parent
							
								
									be5ef3af5d
								
							
						
					
					
						commit
						71b6ebf48c
					
				
					 1 changed files with 191 additions and 101 deletions
				
			
		| 
						 | 
					@ -9,6 +9,87 @@ $stmt->execute([
 | 
				
			||||||
$title = "Results: " . $stmt->fetch(PDO::FETCH_COLUMN);
 | 
					$title = "Results: " . $stmt->fetch(PDO::FETCH_COLUMN);
 | 
				
			||||||
$description = "View the results of particular issue's voting.";
 | 
					$description = "View the results of particular issue's voting.";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// use new weights for Winter 2024 and later
 | 
				
			||||||
 | 
					// i want to normalise the old and new ranking formulas, but for now
 | 
				
			||||||
 | 
					// this will have to do
 | 
				
			||||||
 | 
					if (intval($_GET['game']) >= 381):
 | 
				
			||||||
 | 
					/** === START new display query === */
 | 
				
			||||||
 | 
					$temp = "";
 | 
				
			||||||
 | 
					$view =
 | 
				
			||||||
 | 
					    'CREATE TEMPORARY VIEW round_%2$d AS SELECT
 | 
				
			||||||
 | 
					        submissions.id AS submission_id,
 | 
				
			||||||
 | 
					        SUM(score) AS total_score,
 | 
				
			||||||
 | 
					        COUNT(completed) AS num_scores,
 | 
				
			||||||
 | 
					        AVG(score) AS average_score
 | 
				
			||||||
 | 
					        FROM submissions
 | 
				
			||||||
 | 
					        LEFT JOIN assignments ON submissions.id = assignments.submission_id
 | 
				
			||||||
 | 
					        WHERE submissions.game_id = %1$d AND round_number = %2$d
 | 
				
			||||||
 | 
					        GROUP BY submission_id;' . PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$temp .= sprintf($view, $_GET["game"], 1);
 | 
				
			||||||
 | 
					$temp .= sprintf($view, $_GET["game"], 2);
 | 
				
			||||||
 | 
					$temp .= sprintf($view, $_GET["game"], 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$temp .= sprintf(
 | 
				
			||||||
 | 
					    'CREATE TEMPORARY VIEW participants AS SELECT
 | 
				
			||||||
 | 
					            member_id,
 | 
				
			||||||
 | 
					            COUNT(completed) != COUNT(id) AS disqualified
 | 
				
			||||||
 | 
					            FROM assignments
 | 
				
			||||||
 | 
					            WHERE game_id = %d
 | 
				
			||||||
 | 
					            GROUP BY member_id;',
 | 
				
			||||||
 | 
					    $_GET["game"]
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$db["data"]->exec($temp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$stmt = $db["data"]->query(
 | 
				
			||||||
 | 
					    'SELECT submissions.id AS id, submissions.hash, members.name, members.handle,
 | 
				
			||||||
 | 
					    CASE WHEN name_is_public = 1 AND name IS NOT NULL
 | 
				
			||||||
 | 
					        THEN name
 | 
				
			||||||
 | 
					        ELSE CONCAT("Member ", submissions.member_id)
 | 
				
			||||||
 | 
					    END AS author,
 | 
				
			||||||
 | 
					    CASE WHEN doc_is_public = 1
 | 
				
			||||||
 | 
					        THEN title
 | 
				
			||||||
 | 
					        ELSE CONCAT("Entry ", submissions.id)
 | 
				
			||||||
 | 
					    END AS title
 | 
				
			||||||
 | 
					    ,
 | 
				
			||||||
 | 
					    doc_is_public,
 | 
				
			||||||
 | 
					    name_is_public,
 | 
				
			||||||
 | 
					    participants.disqualified,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    row_number() OVER(ORDER BY
 | 
				
			||||||
 | 
					    round_1.average_score DESC, round_1.num_scores DESC) AS rank_round_1,
 | 
				
			||||||
 | 
					    iif(round_1.average_score, format("%.2f", round_1.average_score), NULL) AS score_round_1,
 | 
				
			||||||
 | 
					    round_1.num_scores AS round_1_num_scores,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    row_number() OVER(ORDER BY
 | 
				
			||||||
 | 
					    round_2.average_score DESC, round_2.num_scores DESC,
 | 
				
			||||||
 | 
					    round_1.average_score DESC, round_1.num_scores DESC) AS rank_round_2,
 | 
				
			||||||
 | 
					    iif(round_2.average_score, format("%.2f", round_2.average_score), NULL) AS score_round_2,
 | 
				
			||||||
 | 
					    round_2.num_scores AS round_2_num_scores,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    row_number() OVER(ORDER BY
 | 
				
			||||||
 | 
					    round_3.average_score DESC, round_3.num_scores DESC,
 | 
				
			||||||
 | 
					    round_2.average_score DESC, round_2.num_scores DESC,
 | 
				
			||||||
 | 
					    round_1.average_score DESC, round_1.num_scores DESC) AS rank_round_3,
 | 
				
			||||||
 | 
					    iif(round_3.average_score, format("%.2f", round_3.average_score), NULL) AS score_round_3,
 | 
				
			||||||
 | 
					    round_3.num_scores AS round_3_num_scores
 | 
				
			||||||
 | 
					    FROM submissions
 | 
				
			||||||
 | 
					    LEFT JOIN members ON submissions.member_id = members.id
 | 
				
			||||||
 | 
					    JOIN round_1 ON submissions.id = round_1.submission_id
 | 
				
			||||||
 | 
					    LEFT JOIN round_2 ON submissions.id = round_2.submission_id
 | 
				
			||||||
 | 
					    LEFT JOIN round_3 ON submissions.id = round_3.submission_id
 | 
				
			||||||
 | 
					    LEFT JOIN participants ON participants.member_id = submissions.member_id
 | 
				
			||||||
 | 
					    GROUP BY submissions.id, submissions.member_id
 | 
				
			||||||
 | 
					    ORDER BY rank_round_3;',
 | 
				
			||||||
 | 
					    PDO::FETCH_OBJ
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** === END new display query === */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** === START old display query === */
 | 
				
			||||||
$stmt = $db["data"]
 | 
					$stmt = $db["data"]
 | 
				
			||||||
    ->prepare('SELECT submissions.id AS id, submissions.hash, members.name, members.handle,
 | 
					    ->prepare('SELECT submissions.id AS id, submissions.hash, members.name, members.handle,
 | 
				
			||||||
    CASE WHEN name_is_public = 1 AND name IS NOT NULL
 | 
					    CASE WHEN name_is_public = 1 AND name IS NOT NULL
 | 
				
			||||||
| 
						 | 
					@ -18,15 +99,32 @@ $stmt = $db["data"]
 | 
				
			||||||
    CASE WHEN doc_is_public = 1
 | 
					    CASE WHEN doc_is_public = 1
 | 
				
			||||||
        THEN title
 | 
					        THEN title
 | 
				
			||||||
        ELSE CONCAT("Entry ", submissions.id)
 | 
					        ELSE CONCAT("Entry ", submissions.id)
 | 
				
			||||||
    END AS title
 | 
					    END AS title,
 | 
				
			||||||
    , doc_is_public, name_is_public, score_round_1, rank_round_1, score_round_2, rank_round_2, score_round_3, rank_round_3, rank_final, votes_round_1, votes_round_2, votes_round_3, num_assignments_round_1, num_assignments_round_2, num_assignments_round_3
 | 
					    doc_is_public,
 | 
				
			||||||
 | 
					    name_is_public,
 | 
				
			||||||
 | 
					    score_round_1,
 | 
				
			||||||
 | 
					    rank_round_1,
 | 
				
			||||||
 | 
					    score_round_2,
 | 
				
			||||||
 | 
					    rank_round_2,
 | 
				
			||||||
 | 
					    score_round_3,
 | 
				
			||||||
 | 
					    rank_round_3,
 | 
				
			||||||
 | 
					    rank_final,
 | 
				
			||||||
 | 
					    votes_round_1,
 | 
				
			||||||
 | 
					    votes_round_2,
 | 
				
			||||||
 | 
					    votes_round_3,
 | 
				
			||||||
 | 
					    num_assignments_round_1,
 | 
				
			||||||
 | 
					    num_assignments_round_2,
 | 
				
			||||||
 | 
					    num_assignments_round_3
 | 
				
			||||||
    FROM submissions
 | 
					    FROM submissions
 | 
				
			||||||
    JOIN members ON submissions.member_id = members.id
 | 
					    JOIN members ON submissions.member_id = members.id
 | 
				
			||||||
    WHERE submissions.game_id = :id AND rank_final IS NOT NULL AND submissions.transaction_id IS NOT NULL ORDER BY rank_final ASC');
 | 
					    WHERE submissions.game_id = :id AND rank_final IS NOT NULL AND submissions.transaction_id IS NOT NULL ORDER BY rank_final ASC');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$results = $stmt->execute([
 | 
					$stmt->execute([
 | 
				
			||||||
    "id" => $_GET["game"],
 | 
					    "id" => $_GET["game"],
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					/** === END old display query === */
 | 
				
			||||||
 | 
					endif;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$row = $stmt->fetch();
 | 
					$row = $stmt->fetch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (!$row) {
 | 
					if (!$row) {
 | 
				
			||||||
| 
						 | 
					@ -38,103 +136,95 @@ include "partials/head.php";
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
    <body>
 | 
					    <body>
 | 
				
			||||||
        <?php include "partials/header.php"; ?>
 | 
					        <?php include "partials/header.php"; ?>
 | 
				
			||||||
    <main id="main" class="flow">
 | 
					        <main id="main" class="flow">
 | 
				
			||||||
    <header>
 | 
					        <header>
 | 
				
			||||||
        <h1><?= $title ?></h1>
 | 
					            <h1><?= $title ?></h1>
 | 
				
			||||||
    </header>
 | 
					        </header>
 | 
				
			||||||
    <?php if ($row): ?>
 | 
					        <?php if ($row): ?>
 | 
				
			||||||
    <!-- <p><a href="/resulthowto.html">How to Read the Results</a></p> -->
 | 
					        <!-- <p><a href="/resulthowto.html">How to Read the Results</a></p> -->
 | 
				
			||||||
            <div role="region" aria-labelledby="results-caption" tabindex="0">
 | 
					                <div role="region" aria-labelledby="results-caption" tabindex="0">
 | 
				
			||||||
                <table>
 | 
					                    <table>
 | 
				
			||||||
                    <caption id="results-caption">Results for Game <?= $_GET[
 | 
					                        <caption id="results-caption">Results for Game <?= $_GET[
 | 
				
			||||||
                        "game"
 | 
					                            "game"
 | 
				
			||||||
                    ] ?></caption>
 | 
					                        ] ?></caption>
 | 
				
			||||||
                <thead>
 | 
					                    <thead>
 | 
				
			||||||
                    <tr>
 | 
					                        <tr>
 | 
				
			||||||
                        <th scope="col" rowspan="3">Title</th>
 | 
					                            <th scope="col" rowspan="3">Title</th>
 | 
				
			||||||
                        <th scope="col" rowspan="3">Author</th>
 | 
					                            <th scope="col" rowspan="3">Author</th>
 | 
				
			||||||
                        <th scope="col" colspan="3">Score</th>
 | 
					                            <th scope="col" colspan="3">Score</th>
 | 
				
			||||||
                        <th scope="col" colspan="3">Rank</th>
 | 
					                            <th scope="col" colspan="3">Rank</th>
 | 
				
			||||||
                    </tr>
 | 
					 | 
				
			||||||
                    <tr>
 | 
					 | 
				
			||||||
                        <th scope="col">Round One</th>
 | 
					 | 
				
			||||||
                        <th scope="col">Round Two</th>
 | 
					 | 
				
			||||||
                        <th scope="col">Round Three</th>
 | 
					 | 
				
			||||||
                        <th scope="col">Round One</th>
 | 
					 | 
				
			||||||
                        <th scope="col">Round Two</th>
 | 
					 | 
				
			||||||
                        <th scope="col">Round Three</th>
 | 
					 | 
				
			||||||
                    </tr>
 | 
					 | 
				
			||||||
                </thead>
 | 
					 | 
				
			||||||
                <tbody>
 | 
					 | 
				
			||||||
                    <?php do {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        $is_booted =
 | 
					 | 
				
			||||||
                            ($row["rank_round_1"] &&
 | 
					 | 
				
			||||||
                                $row["num_assignments_round_1"] &&
 | 
					 | 
				
			||||||
                                !$row["votes_round_1"]) ||
 | 
					 | 
				
			||||||
                            ($row["rank_round_2"] &&
 | 
					 | 
				
			||||||
                                $row["num_assignments_round_2"] &&
 | 
					 | 
				
			||||||
                                !$row["votes_round_2"]) ||
 | 
					 | 
				
			||||||
                            ($row["rank_round_3"] &&
 | 
					 | 
				
			||||||
                                $row["num_assignments_round_3"] &&
 | 
					 | 
				
			||||||
                                !$row["votes_round_3"])
 | 
					 | 
				
			||||||
                                ? true
 | 
					 | 
				
			||||||
                                : false;
 | 
					 | 
				
			||||||
                        $is_autoadvance =
 | 
					 | 
				
			||||||
                            ($row["votes_round_1"] &&
 | 
					 | 
				
			||||||
                                $row["votes_round_1"] < 4) ||
 | 
					 | 
				
			||||||
                            ($row["votes_round_2"] && $row["votes_round_2"] < 4)
 | 
					 | 
				
			||||||
                                ? true
 | 
					 | 
				
			||||||
                                : false;
 | 
					 | 
				
			||||||
                        $has_visible_doc = $row["doc_is_public"] || IS_ADMIN;
 | 
					 | 
				
			||||||
                        $doc_title = htmlspecialchars(
 | 
					 | 
				
			||||||
                            $row["title"],
 | 
					 | 
				
			||||||
                            ENT_QUOTES
 | 
					 | 
				
			||||||
                        );
 | 
					 | 
				
			||||||
                        $doc_url = sprintf("/docs/%s", $row["hash"]);
 | 
					 | 
				
			||||||
                        $author = htmlspecialchars($row["author"], ENT_QUOTES);
 | 
					 | 
				
			||||||
                        $profile_url = "/members/" . $row["handle"];
 | 
					 | 
				
			||||||
                        ?>
 | 
					 | 
				
			||||||
                        <tr <?= $is_booted ? 'class="booted"' : "" ?>>
 | 
					 | 
				
			||||||
                            <th scope="row">
 | 
					 | 
				
			||||||
                                <?= $has_visible_doc
 | 
					 | 
				
			||||||
                                    ? "<a href='$doc_url'>$doc_title</a>"
 | 
					 | 
				
			||||||
                                    : $doc_title ?>
 | 
					 | 
				
			||||||
                                <?php if (
 | 
					 | 
				
			||||||
                                    $is_booted
 | 
					 | 
				
			||||||
                                ) { ?><small>(disqualified)</small><?php } ?>
 | 
					 | 
				
			||||||
                            </th>
 | 
					 | 
				
			||||||
                            <td><?= $row["name_is_public"]
 | 
					 | 
				
			||||||
                                ? "<a href='$profile_url'>$author</a>"
 | 
					 | 
				
			||||||
                                : $author ?></td>
 | 
					 | 
				
			||||||
                            <td <?= is_null($row["score_round_1"])
 | 
					 | 
				
			||||||
                                ? 'class="empty"'
 | 
					 | 
				
			||||||
                                : "" ?>><?= is_null($row["score_round_1"])
 | 
					 | 
				
			||||||
    ? 0
 | 
					 | 
				
			||||||
    : $row["score_round_1"] ?></td>
 | 
					 | 
				
			||||||
                            <td <?= is_null($row["score_round_2"])
 | 
					 | 
				
			||||||
                                ? 'class="empty"'
 | 
					 | 
				
			||||||
                                : "" ?>><?= is_null($row["score_round_2"])
 | 
					 | 
				
			||||||
    ? 0
 | 
					 | 
				
			||||||
    : $row["score_round_2"] ?></td>
 | 
					 | 
				
			||||||
                            <td <?= is_null($row["score_round_3"])
 | 
					 | 
				
			||||||
                                ? 'class="empty"'
 | 
					 | 
				
			||||||
                                : "" ?>><?= is_null($row["score_round_3"])
 | 
					 | 
				
			||||||
    ? 0
 | 
					 | 
				
			||||||
    : $row["score_round_3"] ?></td>
 | 
					 | 
				
			||||||
                            <td><?= $row["rank_round_1"] ?></td>
 | 
					 | 
				
			||||||
                            <td><?= $row["rank_round_2"] ?></td>
 | 
					 | 
				
			||||||
                            <td><?= $row["rank_round_3"] ?></td>
 | 
					 | 
				
			||||||
                        </tr>
 | 
					                        </tr>
 | 
				
			||||||
                    <?php
 | 
					                        <tr>
 | 
				
			||||||
                    } while ($row = $stmt->fetch()); ?>
 | 
					                            <th scope="col">Round One</th>
 | 
				
			||||||
                </tbody>
 | 
					                            <th scope="col">Round Two</th>
 | 
				
			||||||
                <tfoot>
 | 
					                            <th scope="col">Round Three</th>
 | 
				
			||||||
                </tfoot>
 | 
					                            <th scope="col">Round One</th>
 | 
				
			||||||
            </table>
 | 
					                            <th scope="col">Round Two</th>
 | 
				
			||||||
        </div>
 | 
					                            <th scope="col">Round Three</th>
 | 
				
			||||||
        <?php else: ?>
 | 
					                        </tr>
 | 
				
			||||||
        <p><?= $description ?></p>
 | 
					                    </thead>
 | 
				
			||||||
        <?php endif; ?>
 | 
					                    <tbody>
 | 
				
			||||||
        </main>
 | 
					                        <?php do {
 | 
				
			||||||
 | 
					                            $has_visible_doc = $row->doc_is_public || IS_ADMIN;
 | 
				
			||||||
 | 
					                            $doc_title = htmlspecialchars(
 | 
				
			||||||
 | 
					                                $row->title,
 | 
				
			||||||
 | 
					                                ENT_QUOTES
 | 
				
			||||||
 | 
					                            );
 | 
				
			||||||
 | 
					                            $doc_url = sprintf("/docs/%s", $row->hash);
 | 
				
			||||||
 | 
					                            $author = htmlspecialchars($row->author, ENT_QUOTES);
 | 
				
			||||||
 | 
					                            $profile_url = "/members/" . $row->handle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            $is_disqualified = $row->disqualified ??
 | 
				
			||||||
 | 
					                                ($row->rank_round_1 &&
 | 
				
			||||||
 | 
					                                    $row->num_assignments_round_1 &&
 | 
				
			||||||
 | 
					                                    !$row->votes_round_1) ||
 | 
				
			||||||
 | 
					                                    ($row->rank_round_2 &&
 | 
				
			||||||
 | 
					                                    $row->num_assignments_round_2 &&
 | 
				
			||||||
 | 
					                                    !$row->votes_round_2) ||
 | 
				
			||||||
 | 
					                                    ($row->rank_round_3 &&
 | 
				
			||||||
 | 
					                                    $row->num_assignments_round_3 &&
 | 
				
			||||||
 | 
					                                    !$row->votes_round_3)
 | 
				
			||||||
 | 
					                                    ? true
 | 
				
			||||||
 | 
					                                    : false;
 | 
				
			||||||
 | 
					                            ?>
 | 
				
			||||||
 | 
					                            <tr <?= $is_disqualified ? 'class="booted"' : "" ?>>
 | 
				
			||||||
 | 
					                                <th scope="row">
 | 
				
			||||||
 | 
					                                    <?= $has_visible_doc
 | 
				
			||||||
 | 
					                                        ? "<a href='$doc_url'>$doc_title</a>"
 | 
				
			||||||
 | 
					                                        : $doc_title ?>
 | 
				
			||||||
 | 
					                                    <?php if ($is_disqualified) { ?><small>(disqualified)</small><?php } ?>
 | 
				
			||||||
 | 
					                                </th>
 | 
				
			||||||
 | 
					                                <td><?= $row->name_is_public
 | 
				
			||||||
 | 
					                                    ? "<a href='$profile_url'>$author</a>"
 | 
				
			||||||
 | 
					                                    : $author ?></td>
 | 
				
			||||||
 | 
					                                <td <?= is_null($row->score_round_1)
 | 
				
			||||||
 | 
					                                    ? 'class="empty"'
 | 
				
			||||||
 | 
					                                    : "" ?>><?= is_null($row->score_round_1)
 | 
				
			||||||
 | 
					        ? 0
 | 
				
			||||||
 | 
					        : $row->score_round_1 ?></td>
 | 
				
			||||||
 | 
					                                <td <?= is_null($row->score_round_2)
 | 
				
			||||||
 | 
					                                    ? 'class="empty"'
 | 
				
			||||||
 | 
					                                    : "" ?>><?= is_null($row->score_round_2)
 | 
				
			||||||
 | 
					        ? 0
 | 
				
			||||||
 | 
					        : $row->score_round_2 ?></td>
 | 
				
			||||||
 | 
					                                <td <?= is_null($row->score_round_3)
 | 
				
			||||||
 | 
					                                    ? 'class="empty"'
 | 
				
			||||||
 | 
					                                    : "" ?>><?= is_null($row->score_round_3)
 | 
				
			||||||
 | 
					        ? 0
 | 
				
			||||||
 | 
					        : $row->score_round_3 ?></td>
 | 
				
			||||||
 | 
					                                <td><?= $row->rank_round_1 ?></td>
 | 
				
			||||||
 | 
					                                <td><?= $row->rank_round_2 ?></td>
 | 
				
			||||||
 | 
					                                <td><?= $row->rank_round_3 ?></td>
 | 
				
			||||||
 | 
					                            </tr>
 | 
				
			||||||
 | 
					                        <?php
 | 
				
			||||||
 | 
					                        } while ($row = $stmt->fetch(PDO::FETCH_OBJ)); ?>
 | 
				
			||||||
 | 
					                    </tbody>
 | 
				
			||||||
 | 
					                    <tfoot>
 | 
				
			||||||
 | 
					                    </tfoot>
 | 
				
			||||||
 | 
					                </table>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <?php else: ?>
 | 
				
			||||||
 | 
					            <p><?= $description ?></p>
 | 
				
			||||||
 | 
					            <?php endif; ?>
 | 
				
			||||||
 | 
					            </main>
 | 
				
			||||||
    <?php include "partials/footer.php"; ?>
 | 
					    <?php include "partials/footer.php"; ?>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue