TCrB Bot hübscher gemacht

This commit is contained in:
2026-04-06 09:24:31 +02:00
parent 23df0ed163
commit a70e46b307
6 changed files with 104 additions and 21 deletions
+34 -6
View File
@@ -30,12 +30,36 @@ $headerIntroPre = 'Variabler Stern';
$headerIntroTitle = 'T CrB Lichtkurve';
$headerIntroSub = 'AAVSO-WebObs-Daten mit waehlbaren Filtern in einem gemeinsamen Plotly-Diagramm.';
$errors = [];
$eruptionIntervalDays = 227.5687;
$lastEruptionUtc = new DateTimeImmutable('1946-02-09 00:00:00', new DateTimeZone('UTC'));
$todayUtc = new DateTimeImmutable('now', new DateTimeZone('UTC'));
$secondsPerDay = 86400;
$eruptionIntervalSeconds = (int) round($eruptionIntervalDays * $secondsPerDay);
$elapsedSecondsSinceLastEruption = max(0, $todayUtc->getTimestamp() - $lastEruptionUtc->getTimestamp());
$elapsedIntervals = (int) floor($elapsedSecondsSinceLastEruption / $eruptionIntervalSeconds);
$nextPossibleEruptionUtc = $lastEruptionUtc->modify('+' . (($elapsedIntervals + 1) * $eruptionIntervalSeconds) . ' seconds');
$daysUntilNextEruption = ($nextPossibleEruptionUtc->getTimestamp() - $todayUtc->getTimestamp()) / $secondsPerDay;
function h(?string $value): string
{
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
}
function formatGermanDate(?string $value, bool $includeTime = true): string
{
if ($value === null || trim($value) === '') {
return '—';
}
try {
$date = new DateTimeImmutable($value, new DateTimeZone('UTC'));
} catch (Exception) {
return $value;
}
return $date->format($includeTime ? 'd.m.Y H:i:s' : 'd.m.Y');
}
$filterRows = $pdo->query("
SELECT `filter_code`, COUNT(*) AS `entry_count`
FROM `aavso_tcrb_observations`
@@ -182,8 +206,8 @@ foreach ($chartDatasets as $dataset) {
$customData[] = [
$point['jd'],
$point['observer_code'] !== '' ? $point['observer_code'] : '—',
$point['magnitude_error'] !== null ? number_format((float) $point['magnitude_error'], 3, '.', '') : '—',
$point['observer_code'] !== '' ? $point['observer_code'] : '—',
$point['magnitude_error'] !== null ? number_format((float) $point['magnitude_error'], 3, '.', '') : '—',
];
}
@@ -472,17 +496,21 @@ $plotlyPayload = [
<span>Messpunkte</span>
</div>
<div class="tcrb-summary-box">
<strong><?= h((string) $summary['min_utc']) ?></strong>
<span>Erster UTC-Zeitpunkt</span>
<strong><?= h(formatGermanDate($summary['min_utc'])) ?></strong>
<span>Erster Beobachtungszeitpunkt</span>
</div>
<div class="tcrb-summary-box">
<strong><?= h((string) $summary['max_utc']) ?></strong>
<span>Letzter UTC-Zeitpunkt</span>
<strong><?= h(formatGermanDate($summary['max_utc'])) ?></strong>
<span>Letzter Beobachtungszeitpunkt</span>
</div>
<div class="tcrb-summary-box">
<strong><?= number_format((float) $summary['min_mag'], 3, '.', '') ?> bis <?= number_format((float) $summary['max_mag'], 3, '.', '') ?></strong>
<span>Magnitudenbereich</span>
</div>
<div class="tcrb-summary-box">
<strong><?= h($nextPossibleEruptionUtc->format('d.m.Y')) ?></strong>
<span>Naechster moeglicher Ausbruch<br>(in <?= number_format($daysUntilNextEruption, 1, ',', '.') ?> Tagen)</span>
</div>
</div>
<div class="tcrb-chart-wrap">