diff options
author | Minteck <contact@minteck.org> | 2022-09-21 22:42:33 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-09-21 22:42:33 +0200 |
commit | e95b208af90cc386a7d8d1bcab426727cf4f0121 (patch) | |
tree | b293e0c644513fbeb6e9ad29be97fa6347a55e9f /autoschedule/main.php | |
parent | b5f589c323f415bb42ea7069cb4d1a8a2233dd69 (diff) | |
download | pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.gz pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.tar.bz2 pluralconnect-e95b208af90cc386a7d8d1bcab426727cf4f0121.zip |
Update time
Diffstat (limited to 'autoschedule/main.php')
-rw-r--r-- | autoschedule/main.php | 280 |
1 files changed, 280 insertions, 0 deletions
diff --git a/autoschedule/main.php b/autoschedule/main.php new file mode 100644 index 0000000..892ea02 --- /dev/null +++ b/autoschedule/main.php @@ -0,0 +1,280 @@ +<?php + +$_SERVER['DOCUMENT_ROOT'] = ".."; + +require_once "../includes/score.php"; +require_once "../includes/bitset.php"; +require_once "../includes/functions.php"; + +$days = []; +$today_date = date('Y-m-d', time() + 86400); +$today_weekday = (int)date('N', time() + 86400); +$today = []; +$weekend = $today_weekday > 5; + +require_once "./ponies.php"; global $ponies_raindrops; global $ponies_cloudburst; + +$candidates_cloudburst = []; +$candidates_cloudburst_sorted = [ + "night" => [[], [], [], []], + "morning" => [[], [], [], []], + "afternoon" => [[], [], [], []], + "evening" => [[], [], [], []] +]; +$candidates_cloudburst_best = []; + +foreach ($ponies_cloudburst as $pony) { + $dates = $pony["_dates"]; + echo($pony["name"] . ": " . $dates[0] . ", " . $dates[1] . "\n"); + + $candidates_cloudburst[] = $pony["id"]; + if (isset($dates[0])) $candidates_cloudburst_sorted[$dates[1]][1][] = $pony["id"]; + if (isset($dates[1])) $candidates_cloudburst_sorted[$dates[0]][0][] = $pony["id"]; + if (isset($dates[2])) $candidates_cloudburst_sorted[$dates[2]][2][] = $pony["id"]; + if (isset($dates[3])) $candidates_cloudburst_sorted[$dates[3]][3][] = $pony["id"]; +} + +unset($candidates_cloudburst_sorted[""]); + +$candidates_cloudburst_sorted["night"] = [ + ...$candidates_cloudburst_sorted["night"][0], + ...$candidates_cloudburst_sorted["night"][1], + ...$candidates_cloudburst_sorted["night"][2], + ...$candidates_cloudburst_sorted["night"][3] +]; +$candidates_cloudburst_sorted["morning"] = [ + ...$candidates_cloudburst_sorted["morning"][0], + ...$candidates_cloudburst_sorted["morning"][1], + ...$candidates_cloudburst_sorted["morning"][2], + ...$candidates_cloudburst_sorted["morning"][3] +]; +$candidates_cloudburst_sorted["afternoon"] = [ + ...$candidates_cloudburst_sorted["afternoon"][0], + ...$candidates_cloudburst_sorted["afternoon"][1], + ...$candidates_cloudburst_sorted["afternoon"][2], + ...$candidates_cloudburst_sorted["afternoon"][3] +]; +$candidates_cloudburst_sorted["evening"] = [ + ...$candidates_cloudburst_sorted["evening"][0], + ...$candidates_cloudburst_sorted["evening"][1], + ...$candidates_cloudburst_sorted["evening"][2], + ...$candidates_cloudburst_sorted["evening"][3] +]; + +$candidates_cloudburst_id = []; +$candidates_cloudburst_id["night"] = 0; +$candidates_cloudburst_id["morning"] = 0; +$candidates_cloudburst_id["afternoon"] = 0; +$candidates_cloudburst_id["evening"] = 0; + +$candidates_cloudburst_best["night"] = $candidates_cloudburst_sorted["night"][$candidates_cloudburst_id["night"]]; +$candidates_cloudburst_best["morning"] = $candidates_cloudburst_sorted["morning"][$candidates_cloudburst_id["morning"]]; +$candidates_cloudburst_best["afternoon"] = $candidates_cloudburst_sorted["afternoon"][$candidates_cloudburst_id["afternoon"]]; +$candidates_cloudburst_best["evening"] = $candidates_cloudburst_sorted["evening"][$candidates_cloudburst_id["evening"]]; + +$candidates_raindrops = []; +$candidates_raindrops_sorted = [ + "night" => [[], [], [], []], + "morning" => [[], [], [], []], + "afternoon" => [[], [], [], []], + "evening" => [[], [], [], []] +]; +$candidates_raindrops_best = []; + +foreach ($ponies_raindrops as $pony) { + $dates = $pony["_dates"]; + echo($pony["name"] . ": " . implode(", ", $dates) . "\n"); + + $add = false; + + if ($weekend && $pony["_metadata"]["shared_memory"] < 2) { + $add = true; + } else if ($weekend && $pony["_metadata"]["little"] === 2) { + $add = true; + } else if ($pony["_metadata"]["little"] !== 2 && !$pony["_metadata"]["shared_memory"] < 2) { + $add = true; + } + + if ($add) { + $candidates_raindrops[] = $pony["id"]; + if (isset($dates[0])) $candidates_raindrops_sorted[$dates[0]][0][] = $pony["id"]; + if (isset($dates[1])) $candidates_raindrops_sorted[$dates[1]][1][] = $pony["id"]; + if (isset($dates[2])) $candidates_raindrops_sorted[$dates[2]][2][] = $pony["id"]; + if (isset($dates[3])) $candidates_raindrops_sorted[$dates[3]][3][] = $pony["id"]; + } +} + +unset($candidates_raindrops_sorted[""]); + +$candidates_raindrops_sorted["night"] = [ + ...$candidates_raindrops_sorted["night"][0], + ...$candidates_raindrops_sorted["night"][1], + ...$candidates_raindrops_sorted["night"][2], + ...$candidates_raindrops_sorted["night"][3] +]; +$candidates_raindrops_sorted["morning"] = [ + ...$candidates_raindrops_sorted["morning"][0], + ...$candidates_raindrops_sorted["morning"][1], + ...$candidates_raindrops_sorted["morning"][2], + ...$candidates_raindrops_sorted["morning"][3] +]; +$candidates_raindrops_sorted["afternoon"] = [ + ...$candidates_raindrops_sorted["afternoon"][0], + ...$candidates_raindrops_sorted["afternoon"][1], + ...$candidates_raindrops_sorted["afternoon"][2], + ...$candidates_raindrops_sorted["afternoon"][3] +]; +$candidates_raindrops_sorted["evening"] = [ + ...$candidates_raindrops_sorted["evening"][0], + ...$candidates_raindrops_sorted["evening"][1], + ...$candidates_raindrops_sorted["evening"][2], + ...$candidates_raindrops_sorted["evening"][3] +]; + +$candidates_raindrops_id = []; +$candidates_raindrops_id["night"] = 0; +$candidates_raindrops_id["morning"] = 0; +$candidates_raindrops_id["afternoon"] = 0; +$candidates_raindrops_id["evening"] = 0; + +$candidates_raindrops_best["night"] = $candidates_raindrops_sorted["night"][$candidates_raindrops_id["night"]]; +$candidates_raindrops_best["morning"] = $candidates_raindrops_sorted["morning"][$candidates_raindrops_id["morning"]]; +$candidates_raindrops_best["afternoon"] = $candidates_raindrops_sorted["afternoon"][$candidates_raindrops_id["afternoon"]]; +$candidates_raindrops_best["evening"] = $candidates_raindrops_sorted["evening"][$candidates_raindrops_id["evening"]]; + +echo("--------------\n"); + +var_dump($candidates_cloudburst_best); +var_dump($candidates_raindrops_best); + +echo("--------------\n"); + +$correct = false; +$relationships = []; + +foreach (scoreOrderGlobal() as $pony) { + $relationships[$pony["id"]] = [ + ...array_map(function ($i) { + return explode("/", $i)[1]; + }, array_values(array_filter($pony["_metadata"]["marefriends"], function ($i) use ($pony) { + return explode("/", $i)[0] !== $pony["_system"]; + }))), + ...array_map(function ($i) { + return explode("/", $i)[1]; + }, array_values(array_filter($pony["_metadata"]["sisters"], function ($i) use ($pony) { + return explode("/", $i)[0] !== $pony["_system"]; + }))), + ...array_map(function ($i) { + return explode("/", $i)[1]; + }, array_values(array_filter($pony["_metadata"]["caretakers"], function ($i) use ($pony) { + return explode("/", $i)[0] !== $pony["_system"]; + }))) + ]; +} + +while (!$correct) { + $ponies = []; + $fixed = false; + + foreach (["morning", "afternoon", "evening", "night"] as $period) { + if (in_array($candidates_raindrops_best[$period], $ponies)) { + echo("Saw " . $candidates_raindrops_best[$period] . " (raindrops) more than once\n"); + + if (count($candidates_raindrops_sorted[$period]) > $candidates_raindrops_id[$period]) { + $candidates_raindrops_id[$period]++; + + if (isset($candidates_raindrops_sorted[$period][$candidates_raindrops_id[$period]])) { + $candidates_raindrops_best[$period] = $candidates_raindrops_sorted[$period][$candidates_raindrops_id[$period]]; + echo(" Conflict resolved\n"); + $fixed = true; + } else { + echo(" Unable to resolve conflict\n"); + } + } else { + echo(" Unable to resolve conflict\n"); + } + } else { + $ponies[] = $candidates_raindrops_best[$period]; + } + + if (in_array($candidates_cloudburst_best[$period], $ponies)) { + echo("Saw " . $candidates_cloudburst_best[$period] . " (cloudburst) more than once\n"); + + if (count($candidates_cloudburst_sorted[$period]) > $candidates_cloudburst_id[$period]) { + $candidates_cloudburst_id[$period]++; + + if (isset($candidates_cloudburst_sorted[$period][$candidates_cloudburst_id[$period]])) { + $candidates_cloudburst_best[$period] = $candidates_cloudburst_sorted[$period][$candidates_cloudburst_id[$period]]; + echo(" Conflict resolved\n"); + $fixed = true; + } else { + echo(" Unable to resolve conflict\n"); + } + } else { + echo(" Unable to resolve conflict\n"); + } + } else { + $ponies[] = $candidates_cloudburst_best[$period]; + } + + $relations_cloudburst = $relationships[$candidates_cloudburst_best[$period]]; + $relations_raindrops = $relationships[$candidates_raindrops_best[$period]]; + + if (!in_array($candidates_cloudburst_best[$period], $relations_raindrops)) { + echo($candidates_cloudburst_best[$period] . " (cloudburst) is not in a relationship with " . $candidates_raindrops_best[$period] . " (raindrops)\n"); + + $fixable = false; + $fixRelation = null; + + foreach ($relationships[$candidates_cloudburst_best[$period]] as $relationship) { + if (in_array($relationship, $candidates_raindrops_sorted[$period])) { + $fixable = true; + $fixRelation = $relationship; + break; + } + } + + if (!$fixable) { + echo(" Unable to resolve conflict\n"); + } else { + $fixed = true; + $candidates_raindrops_id[$period] = array_search($fixRelation, $candidates_raindrops_sorted[$period]); + $candidates_raindrops_best[$period] = $fixRelation; + echo(" Conflict resolved\n"); + } + } + + if (!in_array($candidates_raindrops_best[$period], $relations_cloudburst)) { + echo($candidates_raindrops_best[$period] . " (raindrops) is not in a relationship with " . $candidates_cloudburst_best[$period] . " (cloudburst)\n"); + + $fixable = false; + $fixRelation = null; + + foreach ($relationships[$candidates_raindrops_best[$period]] as $relationship) { + if (in_array($relationship, $candidates_cloudburst_sorted[$period])) { + $fixable = true; + $fixRelation = $relationship; + break; + } + } + + if (!$fixable) { + echo(" Unable to resolve conflict\n"); + } else { + $fixed = true; + $candidates_cloudburst_id[$period] = array_search($fixRelation, $candidates_cloudburst_sorted[$period]); + $candidates_cloudburst_best[$period] = $fixRelation; + echo(" Conflict resolved\n"); + } + } + } + + if (!$fixed) $correct = true; +} + +echo("--------------\n"); + +echo("Morning: " . getSystemMember("ynmuc", $candidates_cloudburst_best["morning"])["display_name"] . " with " . getSystemMember("gdapd", $candidates_raindrops_best["morning"])["display_name"] . "\n"); +echo("Afternoon: " . getSystemMember("ynmuc", $candidates_cloudburst_best["afternoon"])["display_name"] . " with " . getSystemMember("gdapd", $candidates_raindrops_best["afternoon"])["display_name"] . "\n"); +echo("Evening: " . getSystemMember("ynmuc", $candidates_cloudburst_best["evening"])["display_name"] . " with " . getSystemMember("gdapd", $candidates_raindrops_best["evening"])["display_name"] . "\n"); +echo("Night: " . getSystemMember("ynmuc", $candidates_cloudburst_best["night"])["display_name"] . " with " . getSystemMember("gdapd", $candidates_raindrops_best["night"])["display_name"] . "\n");
\ No newline at end of file |