first commit

This commit is contained in:
2026-03-31 09:44:27 +02:00
commit 8dd4253ee3
123 changed files with 369814 additions and 0 deletions
+118
View File
@@ -0,0 +1,118 @@
<?php
declare(strict_types=1);
/**
* Import RCS (Radar Cross Section) aus dem CelesTrak Satcat.
*
* Quelle: https://celestrak.org/pub/satcat.csv
*
* Relevante Spalten:
* NORAD_CAT_ID – NORAD-Katalognummer
* RCS – Radar Cross Section in m² (kann leer sein)
*
* Die RCS wird in sat_satellites.rcs gespeichert und ermöglicht eine
* bessere Helligkeitsschätzung als die grobe LARGE/MEDIUM/SMALL-Kategorie.
*
* Formel: m1000 ≈ 7.5 − 2.5·log10(RCS)
* (diffuse Kugel, 1000 km Entfernung, Phase 90°, kein Atm.)
*
* Voraussetzung:
* ALTER TABLE sat_satellites ADD COLUMN rcs FLOAT DEFAULT NULL;
*
* Aufruf:
* php import_celestrak_satcat.php
*/
$config = require __DIR__ . '/../../config/database.php';
$dsn = sprintf(
'mysql:host=%s;dbname=%s;charset=%s',
$config['host'],
$config['dbname'],
$config['charset'] ?? 'utf8mb4'
);
$pdo = new PDO($dsn, $config['user'], $config['pass'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
// --- Download ---
$url = 'https://celestrak.org/pub/satcat.csv';
echo "Lade satcat.csv von CelesTrak...\n";
$content = @file_get_contents($url);
if ($content === false) {
exit("Download fehlgeschlagen. Netzwerkverbindung prüfen.\n");
}
echo 'Download OK (' . number_format(strlen($content)) . " Bytes).\n";
// --- CSV einlesen ---
$lines = explode("\n", str_replace("\r\n", "\n", $content));
if (count($lines) < 2) {
exit("CSV leer oder ungültig.\n");
}
// Header-Zeile parsen
$header = str_getcsv(array_shift($lines));
$header = array_map('trim', $header);
$idxNorad = array_search('NORAD_CAT_ID', $header, true);
$idxRcs = array_search('RCS', $header, true);
if ($idxNorad === false || $idxRcs === false) {
exit("Erwartete Spalten NORAD_CAT_ID / RCS nicht gefunden. Header: " . implode(', ', $header) . "\n");
}
// --- Update vorbereiten ---
$stmt = $pdo->prepare("
UPDATE `sat_satellites`
SET `rcs` = :rcs
WHERE `norad_cat_id` = :norad
");
$updated = 0;
$skipped = 0; // nicht in DB
$noRcs = 0; // RCS leer in satcat
$total = 0;
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
$cols = str_getcsv($line);
$norad = isset($cols[$idxNorad]) ? (int)trim($cols[$idxNorad]) : 0;
if ($norad === 0) {
continue;
}
$total++;
$rcsRaw = isset($cols[$idxRcs]) ? trim($cols[$idxRcs]) : '';
if ($rcsRaw === '' || $rcsRaw === '0' || $rcsRaw === '0.0000') {
$noRcs++;
continue; // kein brauchbarer RCS-Wert
}
$rcs = (float)$rcsRaw;
if ($rcs <= 0) {
$noRcs++;
continue;
}
$stmt->execute([':rcs' => $rcs, ':norad' => $norad]);
if ($stmt->rowCount() > 0) {
$updated++;
} else {
$skipped++;
}
}
echo "Fertig.\n";
echo " Einträge gesamt: {$total}\n";
echo " rcs aktualisiert: {$updated}\n";
echo " Nicht in DB: {$skipped}\n";
echo " Ohne RCS-Wert: {$noRcs}\n";