mirror of
https://github.com/Lukas0025/YAGS.git
synced 2025-04-10 17:32:17 +01:00
53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
namespace API\cron;
|
|
|
|
function all($params) {
|
|
tle($params);
|
|
autoFail($params);
|
|
}
|
|
|
|
function tle($params) {
|
|
// get all targets
|
|
$targets = new \wsos\database\core\table(\DAL\target::class);
|
|
|
|
$updated = [];
|
|
foreach ($targets->getAll()->values as $target) {
|
|
|
|
$locator = $target->locator->get();
|
|
if (array_key_exists("tle", $locator)) {
|
|
//get NORAD of objects
|
|
$norad = explode(" ", $locator["tle"]["line2"])[1];
|
|
|
|
//have norad now get data from celestrak
|
|
//https://celestrak.org/NORAD/elements/gp.php?CATNR={norad}&FORMAT=tle
|
|
|
|
$newTle = file_get_contents("https://celestrak.org/NORAD/elements/gp.php?CATNR={$norad}&FORMAT=tle");
|
|
$newTle = explode("\n", $newTle);
|
|
|
|
if (count($newTle) >= 3) { //tle loaded
|
|
$locator["tle"]["line1"] = str_replace("\r", "", $newTle[1]);
|
|
$locator["tle"]["line2"] = str_replace("\r", "", $newTle[2]);
|
|
|
|
$updated[] = ["name" => $target->name->get(), "norad" => $norad];
|
|
|
|
$target->locator->set($locator);
|
|
$target->commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
return $updated;
|
|
}
|
|
|
|
function autoFail($params) {
|
|
$observations = new \wsos\database\core\table(\DAL\observation::class);
|
|
$ob = new \DAL\observation();
|
|
|
|
$faild = $observations->query("(status == ?) && (start < ?)", [$ob->status->getVal("assigned"), time() - 300]);
|
|
|
|
foreach ($faild->values as $fob) {
|
|
$fob->status->set("fail");
|
|
$fob->commit();
|
|
}
|
|
|
|
} |