add: ajoute la bibliothèque SimuGaz qui génère des données
This commit is contained in:
parent
5553c6d13e
commit
4fd89ecfad
2 changed files with 77 additions and 0 deletions
70
lib/SimuGaz/SimuGaz.cpp
Normal file
70
lib/SimuGaz/SimuGaz.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#include <SimuGaz.h>
|
||||
#include <Preferences.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue