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