updated cloud detection and mixed in celestial weather
This commit is contained in:
@@ -3,7 +3,7 @@ import {resolve, dirname} from 'path';
|
||||
import {fileURLToPath} from 'url';
|
||||
import {cfg} from './config.mjs';
|
||||
import {queryCurrent, queryHourly, queryDaily, getCoords} from './influx.mjs';
|
||||
import {getCelestialCurrent, getCelestialHourly, getCelestialDaily} from './celestial.mjs';
|
||||
import {getCelestialCurrent, getCelestialHourly, getCelestialDaily, getCelestialForecast} from './celestial.mjs';
|
||||
import {getSpaceWeather} from './space.mjs';
|
||||
import {getOpenMeteo} from './openmeteo.mjs';
|
||||
import {apiReference} from '@scalar/express-api-reference';
|
||||
@@ -38,8 +38,8 @@ function filterArr(arr, fields) {
|
||||
|
||||
app.get('/api/current', async (req, res) => {
|
||||
const {fields} = req.query;
|
||||
const data = await queryCurrent();
|
||||
res.json(filterFields(data, fields));
|
||||
const [sensors, space] = await Promise.all([queryCurrent(), getCelestialCurrent()]);
|
||||
res.json(filterFields({...sensors, ...space}, fields));
|
||||
});
|
||||
|
||||
// ── Position ──────────────────────────────────────────────────────────────────
|
||||
@@ -53,23 +53,8 @@ app.get('/api/position', async (req, res) => {
|
||||
// ── Space ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
app.get('/api/space', async (req, res) => {
|
||||
const {fields, mode} = req.query;
|
||||
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
|
||||
const end = req.query.end || new Date().toISOString();
|
||||
const coords = await getCoords();
|
||||
if(mode === 'hourly') {
|
||||
const space = await getSpaceWeather();
|
||||
Object.assign(space, getCelestialHourly(coords.latitude, coords.longitude, start, end));
|
||||
res.json(filterFields(space, fields));
|
||||
} else if(mode === 'daily') {
|
||||
const space = await getSpaceWeather();
|
||||
Object.assign(space, getCelestialDaily(coords.latitude, coords.longitude, start, end));
|
||||
res.json(filterFields(space, fields));
|
||||
} else {
|
||||
const space = await getSpaceWeather();
|
||||
Object.assign(space, getCelestialCurrent(coords.latitude, coords.longitude));
|
||||
res.json(filterFields(space, fields));
|
||||
}
|
||||
const {fields} = req.query;
|
||||
res.json(filterFields(await getSpaceWeather(), fields));
|
||||
});
|
||||
|
||||
// ── Daily History/Forecast ────────────────────────────────────────────────────
|
||||
@@ -77,7 +62,9 @@ app.get('/api/space', async (req, res) => {
|
||||
app.get('/api/hourly', async (req, res) => {
|
||||
const {fields} = req.query;
|
||||
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
|
||||
const now = new Date().toISOString();
|
||||
let now = new Date();
|
||||
now.setHours(new Date().getHours() - 1, 0, 0);
|
||||
now = now.toISOString();
|
||||
const end = req.query.end || new Date().toISOString();
|
||||
const coords = await getCoords();
|
||||
const [sensor, meteo] = await Promise.allSettled([
|
||||
@@ -86,7 +73,8 @@ app.get('/api/hourly', async (req, res) => {
|
||||
]);
|
||||
const history = sensor.status === 'fulfilled' ? sensor.value : [];
|
||||
const forecast = meteo.status === 'fulfilled' ? meteo.value.hourly : [];
|
||||
res.json(filterArr([...history, ...forecast], fields));
|
||||
const hourly = getCelestialForecast(coords.latitude, coords.longitude, [...history, ...forecast]);
|
||||
res.json(filterArr(hourly, fields));
|
||||
});
|
||||
|
||||
// ── Hourly History/Forecast ───────────────────────────────────────────────────
|
||||
@@ -94,7 +82,10 @@ app.get('/api/hourly', async (req, res) => {
|
||||
app.get('/api/daily', async (req, res) => {
|
||||
const {fields} = req.query;
|
||||
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
|
||||
const now = new Date().toISOString();
|
||||
let now = new Date();
|
||||
now.setDate(now.getDate() - 1);
|
||||
now.setHours(0, 0, 0, 0);
|
||||
now = now.toISOString();
|
||||
const end = req.query.end || new Date().toISOString();
|
||||
const coords = await getCoords();
|
||||
const [sensor, meteo] = await Promise.allSettled([
|
||||
@@ -103,7 +94,8 @@ app.get('/api/daily', async (req, res) => {
|
||||
]);
|
||||
const history = sensor.status === 'fulfilled' ? sensor.value : [];
|
||||
const forecast = meteo.status === 'fulfilled' ? meteo.value.daily : [];
|
||||
res.json(filterArr([...history, ...forecast], fields));
|
||||
const daily = getCelestialForecast(coords.latitude, coords.longitude, [...history, ...forecast]);
|
||||
res.json(filterArr(daily, fields));
|
||||
});
|
||||
|
||||
// ── ADSB Proxy ────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user