summaryrefslogtreecommitdiff
path: root/autoschedule/ponies.php
diff options
context:
space:
mode:
Diffstat (limited to 'autoschedule/ponies.php')
-rw-r--r--autoschedule/ponies.php99
1 files changed, 99 insertions, 0 deletions
diff --git a/autoschedule/ponies.php b/autoschedule/ponies.php
new file mode 100644
index 0000000..3346452
--- /dev/null
+++ b/autoschedule/ponies.php
@@ -0,0 +1,99 @@
+<?php
+
+global $ponies_raindrops;
+global $ponies_cloudburst;
+global $weekend;
+
+$travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling.json"), true);
+
+function ponies(string $system): array {
+ global $travelling;
+ global $weekend;
+
+ return array_map(function ($i) use ($system, $weekend) {
+ $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-switches.json"), true);
+ $memberData = $i;
+
+ $i["_lastFronted"] = -1;
+ $i["_datesRaw"] = array_values(array_map(function ($i) {
+ return strtotime("1970-01-01T" . date("H:i:s", strtotime($i["timestamp"])) . ".000Z");
+ }, array_filter($switches, function ($item) use ($memberData) {
+ return in_array($memberData["id"], $item["members"]);
+ })));
+
+ $i["_datesValues"] = [
+ "night" => 0,
+ "morning" => 0,
+ "afternoon" => 0,
+ "evening" => 0
+ ];
+
+ foreach ($i["_datesRaw"] as $date) {
+ if ($date < 16200 || $date >= 75600) $i["_datesValues"]["night"]++;
+ if ($date >= 61200 && $date < 75600) $i["_datesValues"]["evening"]++;
+ if ($date >= 39600 && $date < 61200) $i["_datesValues"]["afternoon"]++;
+ if ($date >= 16200 && $date < 39600) $i["_datesValues"]["morning"]++;
+ }
+
+ if (($i["_metadata"]["little"] === 2 || $i["_metadata"]["shared_memory"] < 2) && !$weekend) {
+ $i["_datesValues"]["morning"] = 0;
+ $i["_datesValues"]["afternoon"] = 0;
+ }
+
+ $i["_dates"] = array_values(array_filter(array_keys($i["_datesValues"]), function ($j) use ($i) {
+ return $i["_datesValues"][$j] > 0;
+ }));
+
+ uasort($i["_dates"], function ($a, $b) use ($i) {
+ return $i["_datesValues"][$b] - $i["_datesValues"][$a];
+ });
+ $i["_dates"] = array_values($i["_dates"]);
+
+ $id = $i["id"];
+
+ $fronters = array_map(function ($item) {
+ return $item["id"];
+ }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-fronters.json"), true)["members"]);
+
+ if (in_array($id, $fronters)) {
+ $i["_lastFronted"] = time();
+ } else {
+ $thisMember = array_filter($switches, function ($item) use ($memberData) {
+ return in_array($memberData["id"], $item["members"]);
+ });
+
+ $thisMember = array_values($thisMember);
+ $frontingEnd = null;
+
+ if (count($thisMember) > 0) {
+ $thisIndex = array_search($thisMember[0], $switches);
+
+ $frontingStart = $thisMember[0];
+ $frontingEnd = $switches[$thisIndex - 1];
+ }
+
+ if ($frontingEnd !== null && isset($frontingStart)) {
+ $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
+ }
+ }
+
+ return $i;
+ }, array_values(array_filter(scoreOrderGlobal(), function ($i) use ($system, $travelling) {
+ return $i["_system"] === $system && (!in_array($i["id"], array_keys($travelling)) || !$travelling[$i["id"]]["travelling"]) && !isset($i["_metadata"]["median"]) && $i["name"] !== "unknown" && $i["name"] !== "fusion";
+ })));
+}
+
+$ponies_cloudburst = ponies("ynmuc");
+uasort($ponies_cloudburst, function ($a, $b) {
+ return $b["_lastFronted"] - $a["_lastFronted"];
+});
+$ponies_cloudburst = array_filter($ponies_cloudburst, function ($i) { return $i["_lastFronted"] > 0; });
+
+$ponies_raindrops = ponies("gdapd");
+uasort($ponies_raindrops, function ($a, $b) {
+ return $b["_lastFronted"] - $a["_lastFronted"];
+});
+$ponies_raindrops = array_filter($ponies_raindrops, function ($i) { return $i["_lastFronted"] > 0; });
+
+$ponies_cloudburst = array_reverse($ponies_cloudburst);
+$ponies_raindrops = array_reverse($ponies_raindrops); \ No newline at end of file