backfill all data points
This commit is contained in:
@@ -311,7 +311,7 @@ def read_ltr(c, sensor, temp=None, dew_point=None, rh=None, aqi=None, lat=0.0, l
|
||||
|
||||
if temp is not None and dew_point is not None:
|
||||
cloud, sun_elev = estimate_cloud_cover(c, lux, temp, dew_point, lat, lon)
|
||||
fields['cloud_cover'] = cloud
|
||||
fields['clouds'] = cloud
|
||||
fields['sun_elevation'] = sun_elev
|
||||
|
||||
if rh is not None:
|
||||
|
||||
@@ -5,6 +5,14 @@ import {localDateStr} from './config.mjs';
|
||||
export let lastForecast = { ts: 0, slots: [], summary: null }
|
||||
export const forecastTTL = 5 * 60 * 60_000
|
||||
|
||||
function estimatePrecipitation(precipChance, clouds) {
|
||||
if (precipChance < 30) return 0;
|
||||
const intensity = (precipChance / 100) * clouds;
|
||||
if (intensity > 0.7) return Math.round(intensity * 15 * 10) / 10;
|
||||
if (intensity > 0.4) return Math.round(intensity * 6 * 10) / 10;
|
||||
return Math.round(intensity * 2 * 10) / 10;
|
||||
}
|
||||
|
||||
function estimateUV(sunElevation, cloudFraction) {
|
||||
if (sunElevation <= 0) return 0;
|
||||
const clearSkyUV = Math.sin((sunElevation * Math.PI) / 180) * 12;
|
||||
@@ -123,6 +131,9 @@ export async function get24HourForecast(currentSensors) {
|
||||
const temperature = Math.round(bgTemp * 10) / 10;
|
||||
const humidity = forecastHumidity(seedAbsHum, temperature);
|
||||
const wind_speed = forecastWind(seedWind, pressureTrend);
|
||||
const precipitation_chance = Math.round(weather.precipitation_chance * (1 - i * 0.02) * 100);
|
||||
const raining = precipitation_chance > 60 ? 'True' : 'False';
|
||||
const precipitation = estimatePrecipitation(precipitation_chance, clouds);
|
||||
|
||||
const celestial = getCelestialCurrent(coords.latitude, coords.longitude, time);
|
||||
const uv_index = estimateUV(celestial.sun_elevation ?? 0, clouds);
|
||||
@@ -143,7 +154,9 @@ export async function get24HourForecast(currentSensors) {
|
||||
wind_gusts: Math.round(wind_speed * 1.4 * 10) / 10,
|
||||
wind_direction: currentSensors.wind_direction ?? 0,
|
||||
clouds,
|
||||
precipitation_chance: Math.round(weather.precipitation_chance * (1 - i * 0.02) * 100),
|
||||
raining,
|
||||
precipitation,
|
||||
precipitation_chance,
|
||||
accumulation: 0,
|
||||
uv_index,
|
||||
uv_dose: 0,
|
||||
@@ -216,6 +229,7 @@ function summarise(slots) {
|
||||
return {
|
||||
time: slots[0].time,
|
||||
label: dominant.label,
|
||||
code: dominant.code ?? null,
|
||||
icon: dominant.icon,
|
||||
temperature: peak(fin('temperature')),
|
||||
temperature_max: peak(finAll('temperature')),
|
||||
@@ -233,6 +247,8 @@ function summarise(slots) {
|
||||
wind_gusts: peak(fin('wind_gusts')),
|
||||
wind_direction: avg(fin('wind_direction')),
|
||||
clouds: avg(fin('clouds')),
|
||||
raining: peak(fin('precipitation_chance')) > 60 ? 'True' : 'False',
|
||||
precipitation: avg(fin('precipitation')),
|
||||
precipitation_chance: Math.round(peak(fin('precipitation_chance'))),
|
||||
accumulation: 0,
|
||||
uv_index: peak(fin('uv_index')),
|
||||
@@ -271,21 +287,20 @@ export async function getForecast() {
|
||||
|
||||
export function getWeatherCondition(data) {
|
||||
if(data.lightning_rate > 0 && data.raining === 'True') {
|
||||
return {label: 'Thunderstorm', icon: '11d'};
|
||||
return {label: 'Thunderstorm', icon: '11d', code: 211};
|
||||
}
|
||||
|
||||
if(data.raining === 'True') {
|
||||
if(data.precipitation > 7.6) return {label: 'Heavy Rain', icon: '10d'};
|
||||
if(data.precipitation > 2.5) return {label: 'Moderate Rain', icon: '10d'};
|
||||
return {label: 'Light Rain', icon: '09d'};
|
||||
if(data.precipitation > 7.6) return {label: 'Heavy Rain', icon: '10d', code: 502};
|
||||
if(data.precipitation > 2.5) return {label: 'Moderate Rain', icon: '10d', code: 501};
|
||||
return {label: 'Light Rain', icon: '09d', code: 500};
|
||||
}
|
||||
|
||||
if(data.visibility < 10) return {label: 'Mist', icon: '50d'};
|
||||
if(data.visibility < 10) return {label: 'Mist', icon: '50d', code: 701};
|
||||
|
||||
const dayNight = data.daytime ? 'd' : 'n';
|
||||
if(data.clouds > 0.85) return {label: 'Overcast Clouds', icon: `04${dayNight}`};
|
||||
if(data.clouds > 0.50) return {label: 'Broken Clouds', icon: `04${dayNight}`};
|
||||
if(data.clouds > 0.25) return {label: 'Scattered Clouds', icon: `03${dayNight}`};
|
||||
if(data.clouds > 0.10) return {label: 'Few Clouds', icon: `02${dayNight}`};
|
||||
return {label: 'Clear Sky', icon: `01${dayNight}`};
|
||||
const c = data.clouds > 1 ? data.clouds / 100 : data.clouds;
|
||||
if(c > 0.85) return {label: 'Overcast Clouds', icon: `04${dayNight}`, code: 804};
|
||||
if(c > 0.50) return {label: 'Broken Clouds', icon: `04${dayNight}`, code: 803};
|
||||
if(c > 0.25) return {label: 'Scattered Clouds', icon: `03${dayNight}`, code: 802};
|
||||
if(c > 0.10) return {label: 'Few Clouds', icon: `02${dayNight}`, code: 801};
|
||||
return {label: 'Clear Sky', icon: `01${dayNight}`, code: 800};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user