From 84f87d3dfe1e47402be24b5ea9d4ef8cd7d162c8 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Mon, 6 Oct 2025 14:54:01 +0200 Subject: [PATCH] debug et modif prevision --- pws2mqtt.cpp | 84 ++++++++++++++++++++++++++++++---------------------- pws2mqtt.h | 4 +-- version.h | 2 +- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/pws2mqtt.cpp b/pws2mqtt.cpp index 20a54b0..161ad88 100644 --- a/pws2mqtt.cpp +++ b/pws2mqtt.cpp @@ -21,6 +21,7 @@ QStringList previsionList { "Temps variable (incertain).", \ "Beau temps stable (anticyclone).", \ + "Beau temps en baisse (anticyclone).", \ "Amélioration progressive (éclaircies).", \ "Risque de pluie légère ou nuages.", \ "Dégradation marquée (pluie/vent/orage).", \ @@ -320,6 +321,8 @@ void Pws2mqtt::parseData(QList> queryList) } }else if (name == "baromin") { + //static QDateTime timePrevision = QDateTime::currentDateTime().addSecs(-1000); + propertyValue = tohPa(pair.second.toFloat()); debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG); if (compare (propertyList[name].toFloat(), propertyValue, 0.5)) @@ -329,23 +332,23 @@ void Pws2mqtt::parseData(QList> queryList) propertyList[name] = propertyValue; changed = true; } - static double prevision; - QString ret = pressureVariation(propertyValue); + + static QString prevision; + QString ret = pressureVariation(propertyValue, priority); if (!ret.isEmpty()) { debug (DEBUGMACRO, "baromin ret not empty : " + ret, DEBUG); - QStringList liste = ret.split(","); - double newPrevision = liste[0].toUInt(); - priority = setPriority(priority, liste[1].toUInt()); + QString newPrevision = ret; + priority = setPriority(priority, priority); if (prevision != newPrevision) { prevision = newPrevision; propertyList["prevision"] = prevision; - notif += previsionList[prevision] + " \n"; //debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG); changed = true; } } + notif += prevision + " \n"; }else if (name == "UV") { static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600); @@ -427,38 +430,56 @@ void Pws2mqtt::parseData(QList> queryList) debug(DEBUGMACRO, "parseData: Returning", DEBUG); } -quint8 previsionMeteo(double currentPressure, double variation3h) +QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority) { + QString variation = ""; + + priority = 3; debug (DEBUGMACRO, "begin", DEBUG); - if (currentPressure > 1020.0 && variation3h >= 0.0) + + if (variation3h == 0.0) { - return 0; - } else if (currentPressure > 1010.0 && currentPressure <= 1020.0 && variation3h > 0.0) + variation = " - temps stable"; + }else if (variation3h > 0.2) { - return 1; - } else if (currentPressure > 1000.0 && currentPressure <= 1010.0 && variation3h < 0.0) + variation = " en amélioration rapide"; + }else if (variation3h < -2.0) { - return 2; - } else if (currentPressure <= 1000.0 && variation3h < -2.0) + variation = "en dégradation rapide"; + }else if (variation3h > 0) { - return 3; + variation = " en amélioration"; + }else if (variation3h <0) + { + variation = " en dégradation"; + } + + if (currentPressure > 1020.0) + { + return "Beau temps (anticyclone)" + variation; + } else if (currentPressure > 1010.0 && currentPressure <= 1020.0) + { + return "Éclaircies" + variation; + } else if (currentPressure > 1000.0 && currentPressure <= 1010.0) + { + priority = 4; + return "Temps variable, risque de pluie légère" + variation; + } else if (currentPressure >=990 && currentPressure <= 1000.0) + { + priority = 5; + return "Pluie/vent/orage" + variation; } else if (currentPressure < 990.0) { - return 4; - } else if (variation3h == 0) - { - return 6; - }else - { - return 5; + priority = 5; + return "Tempête ou dépression forte (vigilance)" + variation; } + return variation; } -QString pressureVariation(double currentPressure) +QString pressureVariation(double currentPressure, quint8 &priority) { const int NB_MESURES_3H = 360; // 3h × 120 mesures/heure (1 mesure toutes les 30s) static QVector historiquePressions; - debug(DEBUGMACRO, "PressureVariation : current pressure = " + QByteArray::number(currentPressure), DEBUG); historiquePressions.append(currentPressure); @@ -473,7 +494,6 @@ QString pressureVariation(double currentPressure) // Calcul de la variation sur 3h si on a assez de mesures if (historiquePressions.size() == NB_MESURES_3H) { - QString priority = "default"; double pressionInitiale = historiquePressions.front(); double pressionFinale = historiquePressions.back(); double variation = pressionFinale - pressionInitiale; @@ -482,19 +502,13 @@ QString pressureVariation(double currentPressure) debug(DEBUGMACRO, "Variation sur 3h : " + QString::number(variation) + " hPa", DEBUG); // Prévision météo - quint8 prevision = previsionMeteo(pressionFinale, variation); - debug(DEBUGMACRO, "Prévision : " + previsionList[prevision], DEBUG); + QString prevision = previsionMeteo(pressionFinale, variation, priority); + debug(DEBUGMACRO, "Prévision : " + prevision, DEBUG); // Exemple : Envoi d'une alerte si nécessaire - if (prevision == 4) - { - priority = "high"; - }else if (prevision == 5) - { - priority = "urgent"; - } + debug(DEBUGMACRO, "ending pressureVariation with result", DEBUG); - return QByteArray::number(prevision) + "," + priority; + return prevision; } debug(DEBUGMACRO, "ending pressureVariation no result", DEBUG); return ""; diff --git a/pws2mqtt.h b/pws2mqtt.h index ffe9944..09db3e0 100644 --- a/pws2mqtt.h +++ b/pws2mqtt.h @@ -58,8 +58,8 @@ QString formatNotifString (QString name, QString unit, QByteArray value=""); double mphTokmh (double value); void notify (QString notif, QString priority = "low", QString inputPath = ""); quint8 setPriority (quint8 currentPriority, quint8 newPriority); -quint8 previsionMeteo(double currentPressure, double variation3h); -QString pressureVariation(double currentPressure); +QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority); +QString pressureVariation(double currentPressure, quint8 &priority); void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0); #endif // PWS2MQTT_H diff --git a/version.h b/version.h index 121dfe0..955f428 100644 --- a/version.h +++ b/version.h @@ -3,6 +3,6 @@ #include -std::string version = "1.0.16"; +std::string version = "1.0.17"; #endif // VERSION_H