Add sun constellation changes page
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
session_start();
|
||||
require_once __DIR__ . '/python_api.php';
|
||||
|
||||
$pageTitle = 'Sonne in Sternbildern - AstroTools';
|
||||
$bodyClass = 'sun-constellations-page';
|
||||
|
||||
function h(string $value): string
|
||||
{
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
$timezoneName = 'Europe/Berlin';
|
||||
$currentYear = (int) (new DateTimeImmutable('now', new DateTimeZone($timezoneName)))->format('Y');
|
||||
$selectedYear = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
|
||||
if ($selectedYear === false || $selectedYear === null || $selectedYear < 1600 || $selectedYear > 2200) {
|
||||
$selectedYear = $currentYear;
|
||||
}
|
||||
|
||||
?>
|
||||
<?php require __DIR__ . '/header.php'; ?>
|
||||
|
||||
<?php
|
||||
$pythonResult = runPythonApi('sun_constellation_changes_for_year', [(string) $selectedYear, $timezoneName]);
|
||||
$result = $pythonResult['ok'] ? $pythonResult['data'] : null;
|
||||
$intervals = is_array($result['intervals'] ?? null) ? $result['intervals'] : [];
|
||||
$events = is_array($result['events'] ?? null) ? $result['events'] : [];
|
||||
$displayTimezone = new DateTimeZone($timezoneName);
|
||||
$intervalsByStart = [];
|
||||
foreach ($intervals as $interval) {
|
||||
$startIso = (string) ($interval['start_local_iso'] ?? '');
|
||||
if ($startIso !== '') {
|
||||
$intervalsByStart[$startIso] = $interval;
|
||||
}
|
||||
}
|
||||
$astrologicalStarts = [
|
||||
'Steinbock' => [$selectedYear - 1, 12, 22],
|
||||
'Wassermann' => [$selectedYear, 1, 20],
|
||||
'Fische' => [$selectedYear, 2, 19],
|
||||
'Widder' => [$selectedYear, 3, 21],
|
||||
'Stier' => [$selectedYear, 4, 20],
|
||||
'Zwillinge' => [$selectedYear, 5, 21],
|
||||
'Krebs' => [$selectedYear, 6, 21],
|
||||
'Löwe' => [$selectedYear, 7, 23],
|
||||
'Jungfrau' => [$selectedYear, 8, 23],
|
||||
'Waage' => [$selectedYear, 9, 23],
|
||||
'Skorpion' => [$selectedYear, 10, 23],
|
||||
'Schütze' => [$selectedYear, 11, 22],
|
||||
];
|
||||
?>
|
||||
|
||||
<main class="sun-constellations-tool">
|
||||
<section class="card sun-constellations-card">
|
||||
<form class="sun-constellations-form" method="get">
|
||||
<label for="year">Jahr</label>
|
||||
<input id="year" name="year" type="number" min="1600" max="2200" value="<?= h((string) $selectedYear) ?>">
|
||||
<button class="btn btn-primary" type="submit">Berechnen</button>
|
||||
</form>
|
||||
<p class="hint">
|
||||
Berechnet werden die offiziellen IAU-Sternbildgrenzen aus geozentrischer Sicht.
|
||||
Der Jahreszeitraum beginnt am 01.01.<?= h((string) $selectedYear) ?> um 00:00 Uhr in Europe/Berlin.
|
||||
Deshalb erscheint auch der Schlangenträger; der klassische Tierkreis mit zwölf Zeichen ist nicht identisch mit den Sternbildern.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<?php if ($result === null): ?>
|
||||
<section class="card msg-error">
|
||||
<h2>Berechnung nicht möglich</h2>
|
||||
<p><?= h((string) ($pythonResult['error'] ?? 'Unbekannter Python-Fehler.')) ?></p>
|
||||
</section>
|
||||
<?php else: ?>
|
||||
<section class="card sun-constellations-card">
|
||||
<h2>Astronomisch und astrologisch</h2>
|
||||
<div class="sun-constellations-table-wrap">
|
||||
<table class="data-table sun-constellations-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sternbild</th>
|
||||
<th>Wechsel</th>
|
||||
<th>Astrologisch</th>
|
||||
<th>Differenz</th>
|
||||
<th>Von</th>
|
||||
<th>Bis</th>
|
||||
<th>Dauer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($events as $event): ?>
|
||||
<?php
|
||||
$constellationName = (string) ($event['to_constellation_name'] ?? '');
|
||||
$interval = $intervalsByStart[(string) ($event['local_iso'] ?? '')] ?? [];
|
||||
$astrologicalStart = null;
|
||||
if (isset($astrologicalStarts[$constellationName])) {
|
||||
[$astrologicalYear, $astrologicalMonth, $astrologicalDay] = $astrologicalStarts[$constellationName];
|
||||
$astrologicalStart = new DateTimeImmutable(
|
||||
sprintf('%04d-%02d-%02d 00:00:00', $astrologicalYear, $astrologicalMonth, $astrologicalDay),
|
||||
$displayTimezone
|
||||
);
|
||||
}
|
||||
$astronomicalChange = new DateTimeImmutable((string) ($event['local_iso'] ?? ''), $displayTimezone);
|
||||
$differenceText = '-';
|
||||
if ($astrologicalStart !== null) {
|
||||
$differenceDays = ($astronomicalChange->getTimestamp() - $astrologicalStart->getTimestamp()) / 86400;
|
||||
$differenceText = sprintf('%+.1f Tage', $differenceDays);
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td><strong><?= h($constellationName) ?></strong></td>
|
||||
<td><?= h((string) ($event['local_date'] ?? '')) ?></td>
|
||||
<td><?= $astrologicalStart === null ? '-' : h($astrologicalStart->format('d.m.Y')) ?></td>
|
||||
<td><?= h($differenceText) ?></td>
|
||||
<td><?= h((string) ($interval['start_local_date'] ?? '')) ?>, <?= h((string) ($interval['start_local_time'] ?? '')) ?> Uhr</td>
|
||||
<td><?= h((string) ($interval['end_local_date'] ?? '')) ?>, <?= h((string) ($interval['end_local_time'] ?? '')) ?> Uhr</td>
|
||||
<td><?= h(number_format((float) ($interval['duration_days'] ?? 0), 1, ',', '.')) ?> Tage</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<?php require __DIR__ . '/footer.php'; ?>
|
||||
Reference in New Issue
Block a user