added: prevision1h

This commit is contained in:
2025-10-18 14:49:24 +02:00
parent a8819971d7
commit 6f28fd5001
9 changed files with 132 additions and 60 deletions

1
ESM_3_coeffs.txt Normal file
View File

@@ -0,0 +1 @@
6.07562052E-01, -2.27712343E-02, 8.06470249E-04, -1.54271372E-04, -3.24651735E-06, 7.32602852E-08, 1.35959073E-09, -2.25836520E+00, 8.80326035E-02, 2.16844454E-03, -1.53347087E-05, -5.72983704E-07, -2.55090145E-09, -7.51269505E-01, -4.08350271E-03, -5.21670675E-05, 1.94544667E-06, 1.14099531E-08, 1.58137256E-01, -6.57263143E-05, 2.22697524E-07, -4.16117031E-08, -1.27762753E-02, 9.66891875E-06, 2.52785852E-09, 4.56306672E-04, -1.74202546E-07, -5.91491269E-06, 3.98374029E-01, 1.83945314E-04, -1.73754510E-04, -7.60781159E-07, 3.77830287E-08, 5.43079673E-10, -2.00518269E-02, 8.92859837E-04, 3.45433048E-06, -3.77925774E-07, -1.69699377E-09, 1.69992415E-04, -4.99204314E-05, 2.47417178E-07, 1.07596466E-08, 8.49242932E-05, 1.35191328E-06, -6.21531254E-09, -4.99410301E-06, -1.89489258E-08, 8.15300114E-08, 7.55043090E-04, -3.69476348E-02, 1.62325322E-03, -3.14279680E-05, 2.59835559E-06, -4.77136523E-08, 8.64203390E-03, -6.87405181E-04, -9.13863872E-06, 5.15916806E-07, -3.59217476E-05, 3.28696511E-05, -7.10542454E-07, -1.24382300E-05, -7.38584400E-09, 2.20609296E-07, -7.32469180E-04, -1.87381964E-05, 4.80925239E-06, -8.75492040E-08, 2.77862930E-05, -5.06004592E-06, 1.14325367E-07, 2.53016723E-06, -1.72857035E-08, -3.95079398E-08, -3.59413173E-07, 7.04388046E-07, -1.89309167E-08, -4.79768731E-07, 7.96079978E-09, 1.62897058E-09, 3.94367674E-08, -1.18566247E-09, 3.34678041E-10, -1.15606447E-10, -2.80626406E+00, 5.48712484E-01, -3.99428410E-03, -9.54009191E-04, 1.93090978E-05, -3.08806365E-01, 1.16952364E-02, 4.95271903E-04, -1.90710882E-05, 2.10787756E-03, -6.98445738E-04, 2.30109073E-05, 4.17856590E-04, -1.27043871E-05, -3.04620472E-06, -5.65095215E-05, -4.52166564E-07, 2.46688878E-08, 2.42674348E-10, 1.54547250E-04, 5.24110970E-06, -8.75874982E-08, -1.50743064E-09, -1.56236307E-05, -1.33895614E-07, 2.49709824E-09, 6.51711721E-07, 1.94960053E-09, -1.00361113E-08, -1.21206673E-05, -2.18203660E-07, 7.51269482E-09, 9.79063848E-11, 1.25006734E-06, -1.81584736E-09, -3.52197671E-10, -3.36514630E-08, 1.35908359E-10, 4.17032620E-10, -1.30369025E-09, 4.13908461E-10, 9.22652254E-12, -5.08220384E-09, -2.24730961E-11, 1.17139133E-10, 6.62154879E-10, 4.03863260E-13, 1.95087203E-12, -4.73602469E-12, 5.12733497E+00, -3.12788561E-01, -1.96701861E-02, 9.99690870E-04, 9.51738512E-06, -4.66426341E-07, 5.48050612E-01, -3.30552823E-03, -1.64119440E-03, -5.16670694E-06, 9.52692432E-07, -4.29223622E-02, 5.00845667E-03, 1.00601257E-06, -1.81748644E-06, -1.25813502E-03, -1.79330391E-04, 2.34994441E-06, 1.29735808E-04, 1.29064870E-06, -2.28558686E-06, coefficient, 5.14507424E-02, -4.32510997E-03, 8.99281156E-05, -7.14663943E-07, -2.66016305E-04, 2.63789586E-04, -7.01199003E-06, -1.06823306E-04, 3.61341136E-06, 2.29748967E-07, 3.04788893E-04, -6.42070836E-05, 1.16257971E-06, 7.68023384E-06, -5.47446896E-07, -3.59937910E-08, -4.36497725E-06, 1.68737969E-07, 2.67489271E-08, 3.23926897E-09, -3.53874123E-02, -2.21201190E-01, 1.55126038E-02, -2.63917279E-04, 4.53433455E-02, -4.32943862E-03, 1.45389826E-04, 2.17508610E-04, -6.66724702E-05, 3.33217140E-05, -2.26921615E-03, 3.80261982E-04, -5.45314314E-09, -7.96355448E-04, 2.53458034E-05, -6.31223658E-06, 3.02122035E-04, -4.77403547E-06, 1.73825715E-06, -4.09087898E-07, 6.14155345E-01, -6.16755931E-02, 1.33374846E-03, 3.55375387E-03, -5.13027851E-04, 1.02449757E-04, -1.48526421E-03, -4.11469183E-05, -6.80434415E-06, -9.77675906E-06, 8.82773108E-02, -3.01859306E-03, 1.04452989E-03, 2.47090539E-04, 1.48348065E-03,

View File

@@ -14,10 +14,10 @@ CONFIG -= app_bundle
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mqtt.cpp \
pws2mqtt.cpp \
utcicalculator.cpp
src/main.cpp \
src/mqtt.cpp \
src/pws2mqtt.cpp \
src/utcicalculator.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
@@ -25,10 +25,10 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
barometertrend.h \
httpserver.h \
mqtt.h \
pws2mqtt.h \
utcicalculator.h \
version.h
src/barometertrend.h \
src/httpserver.h \
src/mqtt.h \
src/pws2mqtt.h \
src/utcicalculator.h \
src/version.h

View File

@@ -1,4 +1,6 @@
#pragma once
#include "pws2mqtt.h"
#include <QObject>
#include <QVector>
#include <QDateTime>
@@ -7,12 +9,14 @@
struct ForecastResult
{
QString message;
int urgency; // 0-5
QString colorCode; // "vert", "jaune", ...
int urgency = 0; // 0-5
QString colorCode = ""; // "vert", "jaune", ...
bool snowRisk;
bool rainRisk;
bool stormRisk;
bool blackIce;
QString prevision1h;
quint8 confiance;
};
class BarometerTrend : public QObject
@@ -25,6 +29,7 @@ public:
void addPressure(double pressure_hPa)
{
debug(DEBUGMACRO, "adding pressure " + QByteArray::number(pressure_hPa), DEBUG);
// Enregistrement de la nouvelle mesure
m_values.append(pressure_hPa);
m_timestamps.append(QDateTime::currentDateTime());
@@ -54,7 +59,9 @@ public:
double sum = 0.0;
for (int i = m_values.size() - n; i < m_values.size(); ++i)
sum += m_values[i];
debug(DEBUGMACRO, "smoothed pressure : " + QByteArray::number(sum/n), DEBUG);
return sum / n;
}
// Variation de pression sur les dernières 3h
@@ -84,6 +91,7 @@ public:
}
double p_now = smoothedPressure();
double p_past = m_values[idx];
debug(DEBUGMACRO, "delta pressure : " + QByteArray::number(p_now - p_past), DEBUG);
return p_now - p_past;
}
@@ -99,131 +107,153 @@ public:
r.stormRisk = false;
r.blackIce = false;
debug(DEBUGMACRO, "current pressure : " + QByteArray::number(p) + " - delta pressure 3h" + QByteArray::number(d), DEBUG);
// Logique combinée pression / tendance
if (p >= 1020 && d >= +3)
{
r.message = "Très beau temps durable";
r.message = "- Très beau temps durable \n";
r.urgency = 0;
r.colorCode = "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1020 && d >= +1)
{
r.message = "Beau temps durable";
r.message = "- Beau temps durable \n";
r.urgency = 0;
r.colorCode = "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1020 && d < -3)
{
r.message = "Beau, mais rapide dégradation";
r.message = "- Beau, mais rapide dégradation \n";
r.urgency = 4;
r.colorCode = "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1020 && d < -1)
{
r.message = "Beau, mais possible dégradation";
r.message = "- Beau, mais possible dégradation \n";
r.urgency = 1;
r.colorCode = "sun_behind_small_cloud";
}else if (p >= 1020 && d < 0.5)
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
/*}else if (p >= 1020 && d < 0.5)
{
r.message = "Beau temps stable";
r.message = "- Beau temps \n";
r.urgency = 0;
r.colorCode = "sunny";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);*/
}else if (p >= 1010 && d >= +3)
{
r.message = "Rapide amélioration du temps";
r.message = "- Nuageux, rapide amélioration \n";
r.urgency = 4;
r.colorCode = "sun_behind_small_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d >= +1)
{
r.message = "Amélioration du temps";
r.message = "- Nuageux, en amélioration \n";
r.urgency = 0;
r.colorCode = "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d <= -3)
{
r.message = "Fort risque de pluie ou vent";
r.message = "- Nuageux, fort risque de pluie ou vent \n";
r.urgency = 4;
r.colorCode = "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d <= -1)
{
r.message = "Risque de pluie ou vent";
r.message = "- nuageux, risque de pluie ou vent \n";
r.urgency = 2;
r.colorCode = "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1010 && d <= 0.5)
{
r.message = "Nuageux avec des éclaircies";
r.message = "- Nuageux avec des éclaircies \n";
r.urgency = 2;
r.colorCode = "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1000 && d >= +3)
{
r.message = "Variable, amélioration rapide";
r.message = "- Variable, amélioration rapide \n";
r.urgency = 4;
r.colorCode = "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1000 && d >= +1)
{
r.message = "Variable, tendance au beau";
r.message = "- Variable, tendance au beau \n";
r.urgency = 0;
r.colorCode = "sun_behind_large_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1000 && d <= -3)
{
r.message = "Pluie ou perturbation, dégradation rapide";
r.message = "- Pluie ou perturbation, dégradation rapide \n";
r.urgency = 4;
r.colorCode = "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p >= 1000 && d <= -1)
{
r.message = "Pluie ou perturbation";
r.message = "- Pluie ou perturbation \n";
r.urgency = 2;
r.colorCode = "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 990 && d <= -3)
{
r.message = "Tempête ou orage";
r.message = "- Tempête ou orage \n";
r.urgency = 5;
r.colorCode = "cloud_with_lightning";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 1000 && d >= +3)
{
r.message = "Accalmie temporaire, amélioration rapide";
r.message = "- Pluie avec accalmie temporaire, amélioration rapide \n";
r.urgency = 1;
r.colorCode = "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 1000 && d >= +1)
{
r.message = "Accalmie temporaire";
r.message = "- Pluie avec accalmie temporaire \n";
r.urgency = 1;
r.colorCode = "sun_behind_rain_cloud";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}else if (p < 1000 && d <= -1)
{
r.message = "Mauvais temps durable";
r.message = "- Mauvais temps durable \n";
r.urgency = 4;
r.colorCode = "cloud_with_rain";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
if (qAbs(d) < 0.5)
if (qAbs(d) < 1)
{
r.message = "Stable, pas de changement significatif";
r.message += "- Stable, pas de changement significatif \n";
r.urgency = 0;
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
// Risque de neige
if (p < 1000 && d < -1 && temperatureC <= 1.0 && humidityPercent > 80.0)
{
r.snowRisk = true;
r.message += " Risque de neige";
r.message += "- Risque de neige \n";
r.urgency = qMax(r.urgency, 3);
r.colorCode += "snowflake,";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
// Risque de pluie
else if (p < 1010 && d < -1 && temperatureC > 1.0 && humidityPercent > 70.0)
{
r.rainRisk = true;
r.message += " Risque de pluie";
r.message += "- Risque de pluie \n";
r.urgency = qMax(r.urgency, 2);
r.colorCode += "cloud_with_rain,";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
// Risque dorage
if (p < 995 && d < -3 && temperatureC > 20.0 && humidityPercent > 70.0)
{
r.stormRisk = true;
r.message += " Risque dorage";
r.message += "- Risque dorage \n";
r.urgency = qMax(r.urgency, 4);
r.colorCode += "cloud_with_lightning,";
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
if (temperatureC <= 0.5 && humidityPercent >= 85.0) {
@@ -239,10 +269,58 @@ public:
if (r.blackIce)
{
r.message += "Risque de verglas";
r.message += "- Risque de verglas \n";
r.colorCode += "ice_cube,";
r.urgency = qMax(r.urgency, 4);
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
}
// --- Prévision à 1 heure ---
if (d <= -1.5 && p < 1010 && humidityPercent > 80)
{
r.prevision1h = "☔ Pluie probable dans lheure \n";
r.urgency = qMax(r.urgency, 4);
r.confiance = 80;
}else if (d >= +1.5 && p > 1015)
{
r.prevision1h = "🌤 Amélioration probable dans lheure \n";
r.confiance = 85;
}else if (qAbs(d) < 0.3 && qAbs(temperatureC) < 0.5)
{
r.prevision1h = "⛅ Conditions stables pour la prochaine heure \n";
r.confiance = 70;
}else if (temperatureC < 0 && humidityPercent > 85)
{
r.prevision1h = "❄️ Possible formation de givre ou verglas dans lheure \n";
r.urgency = qMax(r.urgency, 4);
r.confiance = 75;
}
// --- Ajustement de confiance selon stabilité barométrique ---
if (qAbs(d) > 3.0)
{
r.confiance -= 15; // variations trop fortes → prévision moins fiable
}
if (p < 990 || p > 1030)
{
r.confiance -= 10; // situations extrêmes, moins prédictibles
}
if (r.blackIce)
{
r.confiance += 5; // phénomène local très probable
}
r.confiance = qBound((quint8)0, r.confiance, (quint8)100); // borne entre 0 et 100
// --- Résultat complet ---
if (!r.prevision1h.isEmpty())
{
r.message += "**Prévision dans l'heure** \n";
r.message += r.prevision1h;
r.message += "- " + QByteArray::number(r.confiance) + "% \n";
}
debug(DEBUGMACRO, "message : " + r.message, DEBUG);
return r;
}

View File

@@ -1,5 +1,4 @@
#ifndef HTTPSERVER_H
#define HTTPSERVER_H
#pragma once
#include <QtHttpServer/QHttpServer>
@@ -9,6 +8,3 @@ class HttpServer : QObject
public:
int port = 5000;
};
#endif // HTTPSERVER_H

View File

@@ -1,5 +1,4 @@
#ifndef MQTT_H
#define MQTT_H
#pragma once
#include <cstring>
#include <cstdio>
@@ -187,5 +186,3 @@ class MqttClient : public QObject
// void updateMessage();
};
#endif //MQTT_H

View File

@@ -323,7 +323,7 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
if (prevision != newPrevision)
{
prevision = newPrevision;
propertyList["prevision"] = "- " + prevision + " \n";
propertyList["prevision"] = prevision;
priority = setPriority(priority, ret.urgency);
tag += ret.colorCode;
}
@@ -393,8 +393,12 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
}
debug(DEBUGMACRO, "Name = " + name + ", value = " + value, DEBUG);
if (! (name == "prevision"))
{
notif += propertyList[name];
}
}
notif += "**Prévisions** \n" + propertyList["prevision"];
debug(DEBUGMACRO, "calling notify with notif = #" + notif + "#", DEBUG);
if (changed)
{
@@ -630,7 +634,7 @@ void notify(QString notif, QString priority, QString inputPath, QString tag)
std::string readBuffer;
priority = "Priority: " + priority;
debug (DEBUGMACRO, "notifying at priority " + priority + " - message : " + notif, DEBUG);
debug (DEBUGMACRO, "notifying at priority " + priority + "with tag : " + tag + " - message : " + notif, DEBUG);
// Initialise libcurl
curl_global_init(CURL_GLOBAL_DEFAULT);

View File

@@ -1,5 +1,4 @@
#ifndef PWS2MQTT_H
#define PWS2MQTT_H
#pragma once
#include <QString>
#include <QByteArray>
@@ -65,4 +64,3 @@ void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qre
double windChill(double airT, double vent);
double calculerHumidex(double temperature, double humiditeRelative);
#endif // PWS2MQTT_H

View File

@@ -1,8 +1,6 @@
#ifndef VERSION_H
#define VERSION_H
#pragma once
#include <string>
std::string version = "1.0.54";
#endif // VERSION_H