Added daytime property
This commit is contained in:
@@ -57,11 +57,10 @@ export async function queryCurrent() {
|
||||
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||
`;
|
||||
const rows = await query(flux);
|
||||
const result = {};
|
||||
const result = {time: new Date()};
|
||||
for(const row of rows) {
|
||||
Object.assign(result, extractRow(row));
|
||||
}
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ export function getWeatherCondition(data) {
|
||||
}
|
||||
|
||||
// Cloud-based conditions
|
||||
if(data.daytime == null)
|
||||
data.daytime = data.time >= new Date(data.sunrise) && data.time <= new Date(data.sunset);
|
||||
const isDay = data.daytime;
|
||||
const dayNight = isDay ? "d" : "n";
|
||||
|
||||
|
||||
@@ -41,13 +41,12 @@ function filterArr(arr, fields) {
|
||||
app.get('/api/current', async (req, res) => {
|
||||
const { fields } = req.query
|
||||
const [sensors, coords] = await Promise.all([queryCurrent(), getCoords()])
|
||||
const condition = getWeatherCondition(sensors)
|
||||
const space = getCelestialCurrent(coords.latitude, coords.longitude)
|
||||
const condition = getWeatherCondition(Object.assign(sensors, space))
|
||||
const { summary } = await ensureForecast()
|
||||
|
||||
// Merge forecast summary fields — sensor readings take priority
|
||||
const merged = {
|
||||
time: new Date(),
|
||||
...(summary ? {
|
||||
precipitation_chance: summary.precipitation_chance,
|
||||
temperature_max: summary.temperature_max,
|
||||
|
||||
Reference in New Issue
Block a user