debug et modif prevision
This commit is contained in:
84
pws2mqtt.cpp
84
pws2mqtt.cpp
@@ -21,6 +21,7 @@ QStringList previsionList
|
|||||||
{
|
{
|
||||||
"Temps variable (incertain).", \
|
"Temps variable (incertain).", \
|
||||||
"Beau temps stable (anticyclone).", \
|
"Beau temps stable (anticyclone).", \
|
||||||
|
"Beau temps en baisse (anticyclone).", \
|
||||||
"Amélioration progressive (éclaircies).", \
|
"Amélioration progressive (éclaircies).", \
|
||||||
"Risque de pluie légère ou nuages.", \
|
"Risque de pluie légère ou nuages.", \
|
||||||
"Dégradation marquée (pluie/vent/orage).", \
|
"Dégradation marquée (pluie/vent/orage).", \
|
||||||
@@ -320,6 +321,8 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
}
|
}
|
||||||
}else if (name == "baromin")
|
}else if (name == "baromin")
|
||||||
{
|
{
|
||||||
|
//static QDateTime timePrevision = QDateTime::currentDateTime().addSecs(-1000);
|
||||||
|
|
||||||
propertyValue = tohPa(pair.second.toFloat());
|
propertyValue = tohPa(pair.second.toFloat());
|
||||||
debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG);
|
debug (DEBUGMACRO, "Barometre en hPa : " + QByteArray::number(propertyValue), DEBUG);
|
||||||
if (compare (propertyList[name].toFloat(), propertyValue, 0.5))
|
if (compare (propertyList[name].toFloat(), propertyValue, 0.5))
|
||||||
@@ -329,23 +332,23 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
propertyList[name] = propertyValue;
|
propertyList[name] = propertyValue;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
static double prevision;
|
|
||||||
QString ret = pressureVariation(propertyValue);
|
static QString prevision;
|
||||||
|
QString ret = pressureVariation(propertyValue, priority);
|
||||||
if (!ret.isEmpty())
|
if (!ret.isEmpty())
|
||||||
{
|
{
|
||||||
debug (DEBUGMACRO, "baromin ret not empty : " + ret, DEBUG);
|
debug (DEBUGMACRO, "baromin ret not empty : " + ret, DEBUG);
|
||||||
QStringList liste = ret.split(",");
|
QString newPrevision = ret;
|
||||||
double newPrevision = liste[0].toUInt();
|
priority = setPriority(priority, priority);
|
||||||
priority = setPriority(priority, liste[1].toUInt());
|
|
||||||
if (prevision != newPrevision)
|
if (prevision != newPrevision)
|
||||||
{
|
{
|
||||||
prevision = newPrevision;
|
prevision = newPrevision;
|
||||||
propertyList["prevision"] = prevision;
|
propertyList["prevision"] = prevision;
|
||||||
notif += previsionList[prevision] + " \n";
|
|
||||||
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
//debug (DEBUGMACRO, "Notif = #" + notif + "#", DEBUG);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notif += prevision + " \n";
|
||||||
}else if (name == "UV")
|
}else if (name == "UV")
|
||||||
{
|
{
|
||||||
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
|
static QDateTime timeUV = QDateTime::currentDateTime().addSecs(-600);
|
||||||
@@ -427,38 +430,56 @@ void Pws2mqtt::parseData(QList<std::pair<QString, QString>> queryList)
|
|||||||
debug(DEBUGMACRO, "parseData: Returning", DEBUG);
|
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);
|
debug (DEBUGMACRO, "begin", DEBUG);
|
||||||
if (currentPressure > 1020.0 && variation3h >= 0.0)
|
|
||||||
|
if (variation3h == 0.0)
|
||||||
{
|
{
|
||||||
return 0;
|
variation = " - temps stable";
|
||||||
} else if (currentPressure > 1010.0 && currentPressure <= 1020.0 && variation3h > 0.0)
|
}else if (variation3h > 0.2)
|
||||||
{
|
{
|
||||||
return 1;
|
variation = " en amélioration rapide";
|
||||||
} else if (currentPressure > 1000.0 && currentPressure <= 1010.0 && variation3h < 0.0)
|
}else if (variation3h < -2.0)
|
||||||
{
|
{
|
||||||
return 2;
|
variation = "en dégradation rapide";
|
||||||
} else if (currentPressure <= 1000.0 && variation3h < -2.0)
|
}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)
|
} else if (currentPressure < 990.0)
|
||||||
{
|
{
|
||||||
return 4;
|
priority = 5;
|
||||||
} else if (variation3h == 0)
|
return "Tempête ou dépression forte (vigilance)" + variation;
|
||||||
{
|
|
||||||
return 6;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
return 5;
|
|
||||||
}
|
}
|
||||||
|
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)
|
const int NB_MESURES_3H = 360; // 3h × 120 mesures/heure (1 mesure toutes les 30s)
|
||||||
static QVector<double> historiquePressions;
|
static QVector<double> historiquePressions;
|
||||||
|
|
||||||
debug(DEBUGMACRO, "PressureVariation : current pressure = " + QByteArray::number(currentPressure), DEBUG);
|
debug(DEBUGMACRO, "PressureVariation : current pressure = " + QByteArray::number(currentPressure), DEBUG);
|
||||||
|
|
||||||
historiquePressions.append(currentPressure);
|
historiquePressions.append(currentPressure);
|
||||||
@@ -473,7 +494,6 @@ QString pressureVariation(double currentPressure)
|
|||||||
// Calcul de la variation sur 3h si on a assez de mesures
|
// Calcul de la variation sur 3h si on a assez de mesures
|
||||||
if (historiquePressions.size() == NB_MESURES_3H)
|
if (historiquePressions.size() == NB_MESURES_3H)
|
||||||
{
|
{
|
||||||
QString priority = "default";
|
|
||||||
double pressionInitiale = historiquePressions.front();
|
double pressionInitiale = historiquePressions.front();
|
||||||
double pressionFinale = historiquePressions.back();
|
double pressionFinale = historiquePressions.back();
|
||||||
double variation = pressionFinale - pressionInitiale;
|
double variation = pressionFinale - pressionInitiale;
|
||||||
@@ -482,19 +502,13 @@ QString pressureVariation(double currentPressure)
|
|||||||
debug(DEBUGMACRO, "Variation sur 3h : " + QString::number(variation) + " hPa", DEBUG);
|
debug(DEBUGMACRO, "Variation sur 3h : " + QString::number(variation) + " hPa", DEBUG);
|
||||||
|
|
||||||
// Prévision météo
|
// Prévision météo
|
||||||
quint8 prevision = previsionMeteo(pressionFinale, variation);
|
QString prevision = previsionMeteo(pressionFinale, variation, priority);
|
||||||
debug(DEBUGMACRO, "Prévision : " + previsionList[prevision], DEBUG);
|
debug(DEBUGMACRO, "Prévision : " + prevision, DEBUG);
|
||||||
|
|
||||||
// Exemple : Envoi d'une alerte si nécessaire
|
// 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);
|
debug(DEBUGMACRO, "ending pressureVariation with result", DEBUG);
|
||||||
return QByteArray::number(prevision) + "," + priority;
|
return prevision;
|
||||||
}
|
}
|
||||||
debug(DEBUGMACRO, "ending pressureVariation no result", DEBUG);
|
debug(DEBUGMACRO, "ending pressureVariation no result", DEBUG);
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ QString formatNotifString (QString name, QString unit, QByteArray value="");
|
|||||||
double mphTokmh (double value);
|
double mphTokmh (double value);
|
||||||
void notify (QString notif, QString priority = "low", QString inputPath = "");
|
void notify (QString notif, QString priority = "low", QString inputPath = "");
|
||||||
quint8 setPriority (quint8 currentPriority, quint8 newPriority);
|
quint8 setPriority (quint8 currentPriority, quint8 newPriority);
|
||||||
quint8 previsionMeteo(double currentPressure, double variation3h);
|
QString previsionMeteo(double currentPressure, double variation3h, quint8 &priority);
|
||||||
QString pressureVariation(double currentPressure);
|
QString pressureVariation(double currentPressure, quint8 &priority);
|
||||||
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0);
|
void rotateAndSaveImage(const QString &inputPath, const QString &outputPath, qreal angle=0);
|
||||||
|
|
||||||
#endif // PWS2MQTT_H
|
#endif // PWS2MQTT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user