summaryrefslogtreecommitdiff
path: root/includes/util/score.inc
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
committerRaindropsSys <contact@minteck.org>2023-03-12 19:16:53 +0100
commiteb89b15c0f044673c1206a418a21d0baba1a675e (patch)
tree39ac31a576d8b8392cbd9baf8d67621bf2cefa86 /includes/util/score.inc
parent5385f0ed8fbb4325203a222a75e6700ffb519349 (diff)
downloadpluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.gz
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.tar.bz2
pluralconnect-eb89b15c0f044673c1206a418a21d0baba1a675e.zip
Updated 104 files, added 3 files, deleted 4 files and renamed 36 files (automated)
Diffstat (limited to 'includes/util/score.inc')
-rw-r--r--includes/util/score.inc136
1 files changed, 136 insertions, 0 deletions
diff --git a/includes/util/score.inc b/includes/util/score.inc
new file mode 100644
index 0000000..57c7a75
--- /dev/null
+++ b/includes/util/score.inc
@@ -0,0 +1,136 @@
+<?php
+
+function scoreOrder($members, $system, $useDominant = false) {
+ $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")) {
+ if (isset($member["color"])) {
+ if ($useDominant) {
+ $rgb = [
+ hexdec(substr($member["dominant_color"] ?? $member["color"], 0, 2)),
+ hexdec(substr($member["dominant_color"] ?? $member["color"], 2, 2)),
+ hexdec(substr($member["dominant_color"] ?? $member["color"], 4, 2))
+ ];
+ } else {
+ $rgb = [
+ hexdec(substr($member["color"], 0, 2)),
+ hexdec(substr($member["color"], 2, 2)),
+ hexdec(substr($member["color"], 4, 2))
+ ];
+ }
+
+ $hsl = rgbToHsl(
+ $rgb[0],
+ $rgb[1],
+ $rgb[2]
+ );
+ } else {
+ $rgb = [255, 255, 255];
+ $hsl = rgbToHsl(255, 255, 255);
+ }
+
+ $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"] = $hsl[0];
+ $ordered[] = $member;
+ }
+ }
+
+ uasort($ordered, function($a, $b) {
+ return $a["_score"] - $b["_score"];
+ });
+
+ return $ordered;
+}
+
+function scoreOrderGlobal() {
+ global $isLowerLoggedIn;
+ global $isLoggedIn;
+
+ $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")) {
+ if (isset($member["color"])) {
+ $rgb = [
+ hexdec(substr($member["color"], 0, 2)),
+ hexdec(substr($member["color"], 2, 2)),
+ hexdec(substr($member["color"], 4, 2))
+ ];
+ $hsl = rgbToHsl(
+ $rgb[0],
+ $rgb[1],
+ $rgb[2]
+ );
+ } else {
+ $rgb = [255, 255, 255];
+ $hsl = rgbToHsl(255, 255, 255);
+ }
+ $member["_score"] = $hsl[0];
+ $member["_system"] = "gdapd";
+ $member["system"] = "gdapd";
+ $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
+ $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")) {
+ if (isset($member["color"])) {
+ $rgb = [
+ hexdec(substr($member["color"], 0, 2)),
+ hexdec(substr($member["color"], 2, 2)),
+ hexdec(substr($member["color"], 4, 2))
+ ];
+ $hsl = rgbToHsl(
+ $rgb[0],
+ $rgb[1],
+ $rgb[2]
+ );
+ } else {
+ $rgb = [255, 255, 255];
+ $hsl = rgbToHsl(255, 255, 255);
+ }
+ $member["_score"] = $hsl[0];
+ $member["_system"] = "ynmuc";
+ $member["system"] = "ynmuc";
+ $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
+ $ordered[] = $member;
+ }
+ }
+
+ if ($isLowerLoggedIn || $isLoggedIn) {
+ $app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+ foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/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")) {
+ if (isset($member["color"])) {
+ $rgb = [
+ hexdec(substr($member["color"], 0, 2)),
+ hexdec(substr($member["color"], 2, 2)),
+ hexdec(substr($member["color"], 4, 2))
+ ];
+ $hsl = rgbToHsl(
+ $rgb[0],
+ $rgb[1],
+ $rgb[2]
+ );
+ } else {
+ $rgb = [255, 255, 255];
+ $hsl = rgbToHsl(255, 255, 255);
+ }
+ $member["_score"] = $hsl[0];
+ $member["_system"] = $app["other"]["id"];
+ $member["system"] = $app["other"]["id"];
+ $member["_metadata"] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$member[id].json"), true));
+ $ordered[] = $member;
+ }
+ }
+ }
+
+ uasort($ordered, function($a, $b) {
+ return $a["_score"] - $b["_score"];
+ });
+
+ return array_values($ordered);
+} \ No newline at end of file