summaryrefslogtreecommitdiff
path: root/includes/score.inc
blob: 703b9cce41d61cfd4d53dee16e2bb233f13ebeab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php

function calculateScore($metadata, $name) {
    $scoreFictive = $metadata["fictive"] ? 200 : 0;
    $scoreLittle = $metadata["little"] === 2 ? 100 : ($metadata["little"] === 1 ? 50 : ($metadata["little"] === 3 ? 75 : 0));
    $scoreNotTalking = $metadata["not_talking"] ? -200 : 0;
    $scoreMedian = $metadata["median"] !== false ? -50 : 0;
    $scoreProtector = $metadata["protector"] ? 1000 : 0;
    $scoreSharedMemory = $metadata["shared_memory"] === 0 ? 200 : ($metadata["shared_memory"] === 1 ? 50 : 0);
    $scoreSpecies = (in_array("pegasus", $metadata["species"]) ? 100 : 0) + (in_array("unicorn", $metadata["species"]) ? 75 : 0) + (in_array("earth", $metadata["species"]) ? 50 : 0) + (in_array("alicorn", $metadata["species"]) ? 150 : 0) + (in_array("batpony", $metadata["species"]) ? 125 : 0) + (in_array("crystal", $metadata["species"]) ? 125 : 0);
    $scoreName = strlen($name) * 5;
    $relations = (count($metadata["marefriends"]) * ($metadata["little"] ? 1 : 2)) + count($metadata["sisters"]);
    $scoreRelations = $relations * 50;

    $scoreLeader = $metadata["leader"] ? 10000 : 0;
    $scorePersecutor = $metadata["persecutor"] ? -10000 : 0;

    $scoreAdd = 0;
    if ($name === "Cloudy Dreams") $scoreAdd += 250;
    if ($name === "Scootaloo") $scoreAdd -= 235;

    $score = $scoreLeader + $scorePersecutor + $scoreFictive + $scoreLittle + $scoreNotTalking + $scoreProtector + $scoreSharedMemory + $scoreRelations + $scoreSpecies + $scoreName + $scoreMedian + $scoreAdd;

    return [
        "leader" => $scoreLeader,
        "fictive" => $scoreFictive,
        "little" => $scoreLittle,
        "median" => $scoreMedian,
        "not_talking" => $scoreNotTalking,
        "name" => $scoreName,
        "protector" => $scoreProtector,
        "shared_memory" => $scoreSharedMemory,
        "relations" => $scoreRelations,
        "species" => $scoreSpecies,
        "persecutor" => $scorePersecutor,
        "additional" => $scoreAdd,
        "total" => $score
    ];
}

function scoreOrder($members, $system) {
    $ordered = [];
    foreach ($members as $member) {
        if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling") && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) {
            $systemID = $member["system"] ?? $system;

            $member["_system"] = $member["system"] = $systemID;
            $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
            $member["_score"] = calculateScore(parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true)), $member["display_name"] ?? $member["name"]);
            $ordered[] = $member;
        }
    }

    uasort($ordered, function($a, $b) {
        return $b["_score"]["total"] - $a["_score"]["total"];
    });

    return $ordered;
}

function scoreOrderGlobal() {
    $ordered = [];
    foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true) as $member) {
        if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling") && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) {
            $member["_system"] = "gdapd";
            $member["system"] = "gdapd";
            $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
            $member["_score"] = calculateScore(parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true)), $member["display_name"] ?? $member["name"]);
            $ordered[] = $member;
        }
    }

    foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true) as $member) {
        if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_starts_with($member["name"], "smol") && !str_ends_with($member["name"], "-travelling") && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) {
            $member["_system"] = "ynmuc";
            $member["system"] = "ynmuc";
            $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
            $member["_score"] = calculateScore(parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true)), $member["display_name"] ?? $member["name"]);
            $ordered[] = $member;
        }
    }

    uasort($ordered, function($a, $b) {
        return $b["_score"]["total"] - $a["_score"]["total"];
    });

    return array_values($ordered);
}