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");