From 108525534c28013cfe1897c30e4565f9893f3766 Mon Sep 17 00:00:00 2001 From: Minteck Date: Mon, 10 Oct 2022 20:51:39 +0200 Subject: Update --- includes/score.inc | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 includes/score.inc (limited to 'includes/score.inc') diff --git a/includes/score.inc b/includes/score.inc new file mode 100644 index 0000000..c35e9bc --- /dev/null +++ b/includes/score.inc @@ -0,0 +1,86 @@ + $scoreHost, + "fictive" => $scoreFictive, + "little" => $scoreLittle, + "median" => $scoreMedian, + "not_talking" => $scoreNotTalking, + "name" => $scoreName, + "protector" => $scoreProtector, + "shared_memory" => $scoreSharedMemory, + "relations" => $scoreRelations, + "species" => $scoreSpecies, + "additional" => $scoreAdd, + "total" => $score + ]; +} + +function scoreOrder($members, $system) { + $ordered = []; + foreach ($members as $member) { + if ($member["name"] !== "unknown" && $member["name"] !== "fusion" && $member["name"] !== "new" && !str_ends_with($member["name"], "-travelling") && file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json")) { + $systemID = $member["system"] ?? $system; + + $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_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_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); +} \ No newline at end of file -- cgit