24h forecasting
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import {queryHourly, getCoords, queryCurrent} from './influx.mjs';
|
||||
import { getCelestialForecast } from './celestial.mjs';
|
||||
|
||||
let cache = { ts: 0, slots: [], summary: null }
|
||||
export let lastForecast = { ts: 0, slots: [], summary: null }
|
||||
const TTL = 10 * 60 * 1000
|
||||
|
||||
// ── Physics Helpers ───────────────────────────────────────────────────────────
|
||||
@@ -224,14 +224,14 @@ function summarise(slots) {
|
||||
|
||||
export async function refreshForecast() {
|
||||
const sensors = await queryCurrent().catch(() => null)
|
||||
if (!sensors) return cache
|
||||
if (!sensors) return lastForecast
|
||||
const slots = await get24HourForecast(sensors).catch(() => null)
|
||||
if (!slots) return cache
|
||||
cache = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||
return cache
|
||||
if (!slots) return lastForecast
|
||||
lastForecast = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||
return lastForecast
|
||||
}
|
||||
|
||||
export async function ensureForecast() {
|
||||
if (Date.now() - cache.ts > TTL) await refreshForecast()
|
||||
return cache
|
||||
if (Date.now() - lastForecast.ts > TTL) await refreshForecast()
|
||||
return lastForecast
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user