Added daytime property
This commit is contained in:
@@ -10,7 +10,7 @@ import {spec} from './spec.mjs';
|
||||
import {existsSync} from 'fs';
|
||||
import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs';
|
||||
import {getWeatherCondition} from './openweather.mjs';
|
||||
import {ensureForecast, lastForecast, refreshForecast} from './forecast.mjs';
|
||||
import {lastForecast, refreshForecast} from './forecast.mjs';
|
||||
import {dailyWeather, hourlyWeather} from './openmeteo.mjs';
|
||||
|
||||
const app = express();
|
||||
@@ -73,7 +73,6 @@ app.get('/api/hourly', async (req, res) => {
|
||||
const end = req.query.end ? new Date(req.query.end) : plus24
|
||||
|
||||
const coords = await getCoords()
|
||||
const { slots } = await ensureForecast()
|
||||
|
||||
// Past → now: InfluxDB
|
||||
const historyEnd = new Date(Math.min(now, end))
|
||||
@@ -86,7 +85,7 @@ app.get('/api/hourly', async (req, res) => {
|
||||
|
||||
// Now → +24h: cached physics forecast
|
||||
const physics = end > now
|
||||
? slots.filter(s => { const t = new Date(s.time); return t >= now && t <= new Date(Math.min(end, plus24)) })
|
||||
? lastForecast.slots.filter(s => { const t = new Date(s.time); return t >= now && t <= new Date(Math.min(end, plus24)) })
|
||||
: []
|
||||
|
||||
// +24h → beyond: Open-Meteo
|
||||
@@ -114,8 +113,7 @@ app.get('/api/daily', async (req, res) => {
|
||||
|
||||
// Does the requested window overlap with today (the 24h forecast window)?
|
||||
const todayStr = now
|
||||
const { summary } = await ensureForecast()
|
||||
const usePhysics = summary && start <= next && end >= now
|
||||
const usePhysics = lastForecast.summary && start <= next && end >= now
|
||||
|
||||
// Past influx history (days before today)
|
||||
const [sensorResult] = await Promise.allSettled([
|
||||
@@ -131,7 +129,7 @@ app.get('/api/daily', async (req, res) => {
|
||||
const meteo = meteoResult.status === 'fulfilled' ? meteoResult.value : []
|
||||
|
||||
// Splice in physics summary for today, skip any meteo row that duplicates it
|
||||
const todaySlot = usePhysics ? [summary] : []
|
||||
const todaySlot = usePhysics ? [lastForecast.summary] : []
|
||||
const meteoClean = meteo.filter(r => r.time !== todayStr)
|
||||
|
||||
const daily = getCelestialForecast(
|
||||
|
||||
Reference in New Issue
Block a user