TCRB per Telegram final
This commit is contained in:
@@ -93,7 +93,7 @@ $tasks = [
|
||||
}
|
||||
|
||||
$messageText = buildTcrbLatestVMessage($latestObservation, $nowBerlin);
|
||||
$chartObservations = fetchRecentTcrbObservationsByFilter($pdo, 'V', 80);
|
||||
$chartObservations = fetchRecentTcrbObservationsByFilterWindow($pdo, 'V', '-2 months');
|
||||
$chartSvg = buildTcrbVChartSvg($chartObservations, $latestObservation);
|
||||
$chartPackage = createTelegramChartPackage($chartSvg);
|
||||
$sentCount = 0;
|
||||
@@ -421,8 +421,12 @@ function fetchLatestTcrbObservationByFilter(PDO $pdo, string $filterCode): ?arra
|
||||
return is_array($row) ? $row : null;
|
||||
}
|
||||
|
||||
function fetchRecentTcrbObservationsByFilter(PDO $pdo, string $filterCode, int $limit = 80): array
|
||||
function fetchRecentTcrbObservationsByFilterWindow(PDO $pdo, string $filterCode, string $windowSpec = '-2 months'): array
|
||||
{
|
||||
$windowStartUtc = (new DateTimeImmutable('now', new DateTimeZone('UTC')))
|
||||
->modify($windowSpec)
|
||||
->format('Y-m-d H:i:s');
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT
|
||||
`id`,
|
||||
@@ -434,17 +438,38 @@ function fetchRecentTcrbObservationsByFilter(PDO $pdo, string $filterCode, int $
|
||||
`observer_code`
|
||||
FROM `aavso_tcrb_observations`
|
||||
WHERE `filter_code` = :filter_code
|
||||
ORDER BY `observed_at_utc` DESC, `id` DESC
|
||||
LIMIT :row_limit
|
||||
AND `observed_at_utc` >= :window_start_utc
|
||||
ORDER BY `observed_at_utc` ASC, `id` ASC
|
||||
");
|
||||
$stmt->bindValue(':filter_code', $filterCode, PDO::PARAM_STR);
|
||||
$stmt->bindValue(':row_limit', max(5, $limit), PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$stmt->execute([
|
||||
':filter_code' => $filterCode,
|
||||
':window_start_utc' => $windowStartUtc,
|
||||
]);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
usort($rows, static function (array $a, array $b): int {
|
||||
return strcmp((string) ($a['observed_at_utc'] ?? ''), (string) ($b['observed_at_utc'] ?? ''));
|
||||
});
|
||||
if ($rows === []) {
|
||||
$fallbackStmt = $pdo->prepare("
|
||||
SELECT
|
||||
`id`,
|
||||
`observed_at_utc`,
|
||||
`jd`,
|
||||
`magnitude`,
|
||||
`magnitude_error`,
|
||||
`filter_code`,
|
||||
`observer_code`
|
||||
FROM `aavso_tcrb_observations`
|
||||
WHERE `filter_code` = :filter_code
|
||||
ORDER BY `observed_at_utc` DESC, `id` DESC
|
||||
LIMIT 30
|
||||
");
|
||||
$fallbackStmt->execute([
|
||||
':filter_code' => $filterCode,
|
||||
]);
|
||||
$rows = $fallbackStmt->fetchAll();
|
||||
usort($rows, static function (array $a, array $b): int {
|
||||
return strcmp((string) ($a['observed_at_utc'] ?? ''), (string) ($b['observed_at_utc'] ?? ''));
|
||||
});
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
@@ -636,7 +661,7 @@ function buildTcrbVChartSvg(array $observations, array $latestObservation): stri
|
||||
<rect width="%d" height="%d" fill="url(#bg)"/>
|
||||
<rect x="%d" y="%d" width="%d" height="%d" rx="16" fill="#11263b" stroke="#2f4d68" stroke-width="1.5"/>
|
||||
<text x="%d" y="44" fill="#f8fafc" font-size="30" font-weight="700">T CrB Lichtkurve - Filter V</text>
|
||||
<text x="%d" y="70" fill="#cbd5e1" font-size="19">letzte 80 Messpunkte, kleinere Magnituden sind heller</text>
|
||||
<text x="%d" y="70" fill="#cbd5e1" font-size="19">letzte 2 Monate</text>
|
||||
<text x="%d" y="%d" fill="#cbd5e1" font-size="18">%s</text>
|
||||
<text x="%d" y="%d" fill="#cbd5e1" font-size="18" text-anchor="end">%s</text>
|
||||
<text x="%d" y="48" fill="#f4d35e" font-size="22" text-anchor="end">Aktuell: %s%s</text>
|
||||
|
||||
Reference in New Issue
Block a user