Import jetzt ohne csv von Raumfahrzeugspuren möglich

This commit is contained in:
2026-04-12 09:28:18 +02:00
parent 457d1a9ade
commit a95c35481e
6 changed files with 229 additions and 2251 deletions
-61
View File
@@ -110,57 +110,6 @@ function buildCometPerihelionIso(array $comet): ?string
return $date->modify(sprintf('+%d seconds', $seconds))->format('c');
}
function loadSpacecraftTrackCsv(string $csvPath): array
{
if (!is_file($csvPath)) {
return [];
}
$lines = file($csvPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($lines === false || count($lines) < 2) {
return [];
}
$header = str_getcsv((string) array_shift($lines), ',', '"', '\\');
if ($header === false || empty($header)) {
return [];
}
$rows = [];
foreach ($lines as $line) {
$values = str_getcsv((string) $line, ',', '"', '\\');
if (!is_array($values) || count($values) !== count($header)) {
continue;
}
$row = array_combine($header, $values);
if (!is_array($row)) {
continue;
}
$timestamp = strtotime((string) ($row['date_tdb'] ?? ''));
$xKm = isset($row['x_km']) ? (float) str_replace(',', '.', (string) $row['x_km']) : null;
$yKm = isset($row['y_km']) ? (float) str_replace(',', '.', (string) $row['y_km']) : null;
$zKm = isset($row['z_km']) ? (float) str_replace(',', '.', (string) $row['z_km']) : null;
$distanceAu = isset($row['distance_au']) ? (float) str_replace(',', '.', (string) $row['distance_au']) : null;
if ($timestamp === false || !is_finite((float) $xKm) || !is_finite((float) $yKm) || !is_finite((float) $zKm) || !is_finite((float) $distanceAu)) {
continue;
}
$rows[] = [
'timestampMs' => $timestamp * 1000,
'dateTdb' => (string) $row['date_tdb'],
'xAu' => $xKm / 149597870.7,
'yAu' => $yKm / 149597870.7,
'zAu' => $zKm / 149597870.7,
'distanceAu' => $distanceAu,
];
}
return $rows;
}
function loadSpacecraftTrackFromDatabase(PDO $pdo, string $missionKey): array
{
$stmt = $pdo->prepare("
@@ -337,16 +286,6 @@ if ($pdo instanceof PDO) {
}
}
if ($voyager1TrackForJs === []) {
$voyager1TrackForJs = loadSpacecraftTrackCsv(__DIR__ . '/../docs/voyager1_horizons_1977_2046_monthly_sun_centered.csv');
}
if ($voyager2TrackForJs === []) {
$voyager2TrackForJs = loadSpacecraftTrackCsv(__DIR__ . '/../docs/voyager2_horizons_1977_2046_monthly_sun_centered.csv');
}
if ($newHorizonsTrackForJs === []) {
$newHorizonsTrackForJs = loadSpacecraftTrackCsv(__DIR__ . '/../docs/new_horizons_2006_2046_monthly_sun_centered.csv');
}
if ($voyager1TrackForJs !== []) {
$spacecraftOptionsForJs[] = ['key' => 'voyager1', 'label' => 'Voyager 1'];
}