From 4fd89ecfadca404149117ef237be47821e82e752 Mon Sep 17 00:00:00 2001 From: Alexis Fourmaux Date: Sat, 30 May 2026 17:00:44 +0200 Subject: [PATCH] =?UTF-8?q?add:=20ajoute=20la=20biblioth=C3=A8que=20SimuGa?= =?UTF-8?q?z=20qui=20g=C3=A9n=C3=A8re=20des=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/SimuGaz/SimuGaz.cpp | 70 +++++++++++++++++++++++++++++++++++++++++ lib/SimuGaz/SimuGaz.h | 7 +++++ 2 files changed, 77 insertions(+) create mode 100644 lib/SimuGaz/SimuGaz.cpp create mode 100644 lib/SimuGaz/SimuGaz.h diff --git a/lib/SimuGaz/SimuGaz.cpp b/lib/SimuGaz/SimuGaz.cpp new file mode 100644 index 0000000..36e698f --- /dev/null +++ b/lib/SimuGaz/SimuGaz.cpp @@ -0,0 +1,70 @@ +#include +#include + +#define INITIAL_CONSUMPTION 1594.87f +#define INITIAL_SECONDS 11462400 // date initiale = 13/05/2026 16:00 +#define AVERAGE_DAILY_CONSUMPTION 2.66f + +// Source : opendata.grdf.fr/explore/dataset/correction_climatique_grdf/ +// Profil résidentiel chauffage (P011), moyenne 2019-2023, normalisée sur 12 mois +static const float GRDF_MONTHLY_COEFF[12] = { + 2.21f, // Janvier + 2.05f, // Février + 1.62f, // Mars + 0.97f, // Avril + 0.55f, // Mai + 0.22f, // Juin + 0.15f, // Juillet + 0.17f, // Août + 0.38f, // Septembre + 0.85f, // Octobre + 1.52f, // Novembre + 2.11f, // Décembre +}; + +Preferences prefs; + +// Base annuelle : 972 m³/an pour 100m² (CRE) +// - base mensuelle moyenne = 81 m³/mois +// - base journalière moyenne = 2.66 m³/j + +float consumptionM3; +uint32_t totalSeconds; + +void get_stored_values(){ + prefs.begin("simugaz"); + consumptionM3 = prefs.getFloat("consumption_m3", INITIAL_CONSUMPTION); + totalSeconds = prefs.getUInt("seconds", INITIAL_SECONDS); + prefs.end(); +} + +void store_values(){ + prefs.begin("simugaz"); + prefs.putFloat("consumption_m3", consumptionM3); + prefs.putUInt("seconds", totalSeconds); + prefs.end(); +} + +uint32_t simulateGasPulses(uint32_t intervalSeconds) +{ + get_stored_values(); + totalSeconds += intervalSeconds; + + uint32_t month = (totalSeconds / (86400UL * 30UL)) % 12; + + float dailyBase = AVERAGE_DAILY_CONSUMPTION * GRDF_MONTHLY_COEFF[month]; + + // Variabilité journalière ±15% + float dailyVariation = 1.0f + 0.30f * ((float)(esp_random() % 1000) / 1000.0f - 0.5f); + + // Résolution compteur Gazpar : 0.010 m³ par impulsion + float incrementM3 = dailyBase * intervalSeconds / 86400.0f * dailyVariation; + consumptionM3 += incrementM3; + uint32_t pulseCount = (uint32_t)(consumptionM3 / 0.010f); + uint32_t incrementPulses = (uint32_t)(incrementM3 / 0.010f); + + store_values(); + + Serial.printf("[GAZ] Incrément de %lu impulsions - Total : %lu impulsions (%.3f m³)\n", incrementPulses, pulseCount, pulseCount * 0.010f); + return pulseCount; +} \ No newline at end of file diff --git a/lib/SimuGaz/SimuGaz.h b/lib/SimuGaz/SimuGaz.h new file mode 100644 index 0000000..a7ca631 --- /dev/null +++ b/lib/SimuGaz/SimuGaz.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +uint32_t simulateGasPulses(uint32_t intervalSeconds = 86400); +void get_stored_values(); +void store_values(); \ No newline at end of file