1

Correction des données météo

This commit is contained in:
2025-11-27 21:35:05 +01:00
parent 7d8388252c
commit bcf7336315
369 changed files with 427 additions and 438 deletions

View File

@@ -42,6 +42,10 @@ async function fetchWeather(targetDateTime, config) {
if (!result) continue;
if (provider.name === "influxdb") {
return result;
}
mergeWeather(weather, result, provider.name);
const complete = WEATHER_FIELDS.every((field) => hasValue(weather[field]));

View File

@@ -90,14 +90,17 @@ function createInfluxProvider(config = {}, globalConfig = {}) {
return null;
}
const timezone = config.timezone || globalConfig.timezone || "UTC";
const queryApi = new InfluxDB({ url, token }).getQueryApi(org);
const windowMinutes = config.windowMinutes ?? globalConfig.windowMinutes ?? 60;
const precipitationThreshold = config.precipitationThreshold ?? globalConfig.precipitationThreshold ?? 0.1;
async function fetch({ target }) {
const window = buildTimeWindow(target, windowMinutes);
const targetInZone = DateTime.isDateTime(target) ? target.setZone(timezone) : DateTime.fromJSDate(target, { zone: timezone });
const window = buildTimeWindow(targetInZone, windowMinutes);
const weather = {};
const contributed = new Set();
let hasMeasurement = false;
for (const [key, sensor] of Object.entries(sensors)) {
const query = buildFluxQuery(bucket, sensor, window);
@@ -114,11 +117,28 @@ function createInfluxProvider(config = {}, globalConfig = {}) {
weather[key] = value;
contributed.add("influxdb");
hasMeasurement = true;
} catch (error) {
console.error(`InfluxDB error for ${key}: ${error.message}`);
}
}
if (!hasMeasurement) return null;
if (!hasValue(weather.illuminance) && sensors.illuminance) {
const hour = targetInZone.hour;
const isNight = hour < 6 || hour >= 18;
if (isNight) {
weather.illuminance = 0;
contributed.add("influxdb");
}
}
if (!hasValue(weather.precipitations) && sensors.precipitations) {
weather.precipitations = false;
contributed.add("influxdb");
}
if (Object.keys(weather).length === 0) return null;
weather.source = Array.from(contributed);

View File

@@ -54,6 +54,11 @@ function createOpenMeteoProvider(config = {}, globalConfig = {}) {
const windowMinutes = config.windowMinutes ?? globalConfig.windowMinutes ?? 60;
const precipitationThreshold = config.precipitationThreshold ?? globalConfig.precipitationThreshold ?? 0.1;
const pressureOffset = Number.isFinite(config.pressureOffset) ? config.pressureOffset : 0;
const illuminanceToLuxFactor = Number.isFinite(config.illuminanceToLuxFactor)
? config.illuminanceToLuxFactor
: Number.isFinite(globalConfig.providers?.openMeteo?.illuminanceToLuxFactor)
? globalConfig.providers.openMeteo.illuminanceToLuxFactor
: 126.7;
const timezone = config.timezone || globalConfig.timezone || "UTC";
async function fetchData({ target }) {
@@ -130,7 +135,10 @@ function createOpenMeteoProvider(config = {}, globalConfig = {}) {
if (hasValue(nearest.temperature_2m)) weather.temperature = nearest.temperature_2m;
if (hasValue(nearest.relative_humidity_2m)) weather.humidity = nearest.relative_humidity_2m;
if (hasValue(nearest.surface_pressure)) weather.pressure = nearest.surface_pressure + pressureOffset;
if (hasValue(nearest.shortwave_radiation)) weather.illuminance = nearest.shortwave_radiation;
if (hasValue(nearest.shortwave_radiation)) {
const factor = Number.isFinite(illuminanceToLuxFactor) ? illuminanceToLuxFactor : 126.7;
weather.illuminance = nearest.shortwave_radiation * factor;
}
if (hasValue(nearest.precipitation)) {
weather.precipitations = nearest.precipitation > precipitationThreshold;