#include "weatherplugin.h"
#include "../utils.h"
#include "weatherdata.h"
bool isSimiliar(const QString &string, const QString &other, double similarityFactor = 0.8)
{
return strings::calculateSimilarity(string.mid(0, other.length()), other) >= similarityFactor;
}
bool WeatherPlugin::isValid(const QString &text)
{
if (isSimiliar(text, tr("what's the weather")))
return true;
if (isSimiliar(text, tr("what is the weather")))
return true;
if (isSimiliar(text, tr("how's the weather")))
return true;
if (isSimiliar(text, tr("tell me about the weather")))
return true;
if (isSimiliar(text, tr("is it going to rain")))
return true;
if (isSimiliar(text, tr("is it sunny today")))
return true;
if (isSimiliar(text, tr("will it be hot")))
return true;
if (isSimiliar(text, tr("is there a chance of thunderstorms")))
return true;
if (isSimiliar(text, tr("how cold is it outside")))
return true;
return false; // No weather-related phrases found
}
void WeatherPlugin::run(const QString &text)
{
// TODO: Implement the logic for handling the weather request
// You can use the provided 'text' parameter to determine the specific weather action to take
// For example, you could make an API call to retrieve weather data and display it to the user
// or perform any other relevant operations.
// Ensure that the function implementation is consistent with your application's requirements.
WeatherData data;
data.parseWeatherData(
R"({"latitude":51.04,"longitude":13.74,"generationtime_ms":1.230001449584961,"utc_offset_seconds":7200,"timezone":"Europe/Berlin","timezone_abbreviation":"CEST","elevation":117.0,"current_weather":{"temperature":25.3,"windspeed":14.8,"winddirection":86.0,"weathercode":2,"is_day":1,"time":"2023-05-21T18:00"},"hourly_units":{"time":"iso8601","temperature_2m":"°C","apparent_temperature":"°C","weathercode":"wmo code","windspeed_10m":"km/h","winddirection_10m":"°","relativehumidity_2m":"%","visibility":"m","is_day":""},"hourly":{"time":["2023-05-21T00:00","2023-05-21T01:00","2023-05-21T02:00","2023-05-21T03:00","2023-05-21T04:00","2023-05-21T05:00","2023-05-21T06:00","2023-05-21T07:00","2023-05-21T08:00","2023-05-21T09:00","2023-05-21T10:00","2023-05-21T11:00","2023-05-21T12:00","2023-05-21T13:00","2023-05-21T14:00","2023-05-21T15:00","2023-05-21T16:00","2023-05-21T17:00","2023-05-21T18:00","2023-05-21T19:00","2023-05-21T20:00","2023-05-21T21:00","2023-05-21T22:00","2023-05-21T23:00","2023-05-22T00:00","2023-05-22T01:00","2023-05-22T02:00","2023-05-22T03:00","2023-05-22T04:00","2023-05-22T05:00","2023-05-22T06:00","2023-05-22T07:00","2023-05-22T08:00","2023-05-22T09:00","2023-05-22T10:00","2023-05-22T11:00","2023-05-22T12:00","2023-05-22T13:00","2023-05-22T14:00","2023-05-22T15:00","2023-05-22T16:00","2023-05-22T17:00","2023-05-22T18:00","2023-05-22T19:00","2023-05-22T20:00","2023-05-22T21:00","2023-05-22T22:00","2023-05-22T23:00","2023-05-23T00:00","2023-05-23T01:00","2023-05-23T02:00","2023-05-23T03:00","2023-05-23T04:00","2023-05-23T05:00","2023-05-23T06:00","2023-05-23T07:00","2023-05-23T08:00","2023-05-23T09:00","2023-05-23T10:00","2023-05-23T11:00","2023-05-23T12:00","2023-05-23T13:00","2023-05-23T14:00","2023-05-23T15:00","2023-05-23T16:00","2023-05-23T17:00","2023-05-23T18:00","2023-05-23T19:00","2023-05-23T20:00","2023-05-23T21:00","2023-05-23T22:00","2023-05-23T23:00","2023-05-24T00:00","2023-05-24T01:00","2023-05-24T02:00","2023-05-24T03:00","2023-05-24T04:00","2023-05-24T05:00","2023-05-24T06:00","2023-05-24T07:00","2023-05-24T08:00","2023-05-24T09:00","2023-05-24T10:00","2023-05-24T11:00","2023-05-24T12:00","2023-05-24T13:00","2023-05-24T14:00","2023-05-24T15:00","2023-05-24T16:00","2023-05-24T17:00","2023-05-24T18:00","2023-05-24T19:00","2023-05-24T20:00","2023-05-24T21:00","2023-05-24T22:00","2023-05-24T23:00","2023-05-25T00:00","2023-05-25T01:00","2023-05-25T02:00","2023-05-25T03:00","2023-05-25T04:00","2023-05-25T05:00","2023-05-25T06:00","2023-05-25T07:00","2023-05-25T08:00","2023-05-25T09:00","2023-05-25T10:00","2023-05-25T11:00","2023-05-25T12:00","2023-05-25T13:00","2023-05-25T14:00","2023-05-25T15:00","2023-05-25T16:00","2023-05-25T17:00","2023-05-25T18:00","2023-05-25T19:00","2023-05-25T20:00","2023-05-25T21:00","2023-05-25T22:00","2023-05-25T23:00","2023-05-26T00:00","2023-05-26T01:00","2023-05-26T02:00","2023-05-26T03:00","2023-05-26T04:00","2023-05-26T05:00","2023-05-26T06:00","2023-05-26T07:00","2023-05-26T08:00","2023-05-26T09:00","2023-05-26T10:00","2023-05-26T11:00","2023-05-26T12:00","2023-05-26T13:00","2023-05-26T14:00","2023-05-26T15:00","2023-05-26T16:00","2023-05-26T17:00","2023-05-26T18:00","2023-05-26T19:00","2023-05-26T20:00","2023-05-26T21:00","2023-05-26T22:00","2023-05-26T23:00","2023-05-27T00:00","2023-05-27T01:00","2023-05-27T02:00","2023-05-27T03:00","2023-05-27T04:00","2023-05-27T05:00","2023-05-27T06:00","2023-05-27T07:00","2023-05-27T08:00","2023-05-27T09:00","2023-05-27T10:00","2023-05-27T11:00","2023-05-27T12:00","2023-05-27T13:00","2023-05-27T14:00","2023-05-27T15:00","2023-05-27T16:00","2023-05-27T17:00","2023-05-27T18:00","2023-05-27T19:00","2023-05-27T20:00","2023-05-27T21:00","2023-05-27T22:00","2023-05-27T23:00"],"temperature_2m":[14.7,14.2,12.8,12.5,12.4,11.5,11.4,12.7,15.5,18.1,21.1,23.7,25.3,26.2,26.0,27.2,25.8,26.1,25.3,24.1,22.9,21.0,19.3,18.0,16.7,16.0,15.4,14.9,14.6,14.1,13.9,14.8,16.7,19.5,22.1,24.1,24.9,25.5,26.2,26.9,26.9,26.2,25.6,24.5,23.0,21.2,19.6,18.3,17.3,16.7,16.7,16.4,16.3,15.9,15.9,15.9,15.7,16.3,17.6,17.8,18.0,18.3,18.2,18.7,19.0,20.3,20.7,18.0,17.0,16.0,14.9,14.6,14.6,14.4,14.1,13.6,12.9,12.4,11.6,11.1,10.8,10.4,10.4,10.6,11.0,11.7,12.0,12.3,13.6,14.4,14.5,14.9,14.6,14.3,13.9,13.5,13.4,13.5,13.4,13.2,13.0,12.8,12.9,13.0,13.4,14.0,14.7,15.7,17.2,18.8,20.0,20.6,20.7,20.6,20.4,19.9,19.1,18.0,16.5,15.2,14.2,13.3,12.4,11.2,10.0,9.4,9.4,10.0,10.9,12.2,13.7,15.2,16.4,17.4,18.1,18.4,18.6,18.4,17.7,16.6,15.5,14.6,13.8,13.0,12.4,11.9,11.2,10.1,8.9,8.4,8.9,10.1,11.4,12.8,14.3,15.7,16.7,17.5,18.2,18.6,18.9,18.8,18.4,17.7,16.6,15.0,13.0,11.1],"apparent_temperature":[14.5,13.9,12.6,12.0,12.3,10.9,11.1,12.3,15.2,18.0,21.3,24.0,25.3,26.0,27.2,26.7,25.6,25.2,23.7,23.1,22.5,20.6,19.4,18.4,17.3,16.4,15.8,15.1,14.5,14.2,13.6,15.0,16.8,19.2,21.9,24.2,25.6,26.1,26.5,27.1,26.3,24.8,24.1,23.0,22.0,20.9,19.5,18.3,17.1,16.3,16.1,15.5,15.9,15.9,15.9,16.3,16.4,17.6,18.7,18.0,18.0,18.9,19.1,18.4,18.5,19.4,19.8,16.2,15.6,14.6,13.5,13.4,13.2,12.8,12.3,11.5,10.6,9.7,8.9,8.4,7.8,7.2,7.4,7.6,8.0,8.8,9.3,10.0,11.4,12.1,13.2,13.5,13.4,13.2,12.7,12.3,12.2,12.3,12.2,12.1,12.0,11.9,11.9,12.0,12.3,12.9,13.6,14.6,15.9,17.3,18.4,19.0,19.1,19.2,19.0,18.6,18.0,17.1,15.8,14.5,13.2,11.7,10.5,9.3,8.1,7.4,7.3,7.8,8.4,9.6,10.8,12.6,14.1,15.1,15.8,15.9,15.8,15.1,14.3,13.4,12.7,12.2,11.9,11.4,11.0,10.4,9.8,8.7,7.4,6.8,7.4,8.6,9.8,11.0,12.2,13.9,15.3,16.2,16.8,16.9,16.6,15.9,15.3,14.9,14.1,12.8,11.1,9.3],"weathercode":[3,2,3,3,3,3,2,2,2,3,3,3,2,1,1,1,2,3,2,3,2,0,1,1,2,2,2,3,3,3,3,3,2,2,1,1,2,2,2,1,3,2,2,1,2,1,1,2,3,3,3,3,80,3,61,61,95,61,80,61,80,61,80,80,3,2,2,2,3,3,3,3,3,3,3,3,3,3,61,61,3,3,3,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,2,2,2,1,1,1,0,0,0,0,0,0,0,0,0],"windspeed_10m":[4.8,4.8,3.8,4.7,2.8,4.2,2.6,3.8,4.3,5.6,7.0,8.9,9.8,11.6,11.1,11.7,17.7,14.5,14.8,12.2,8.2,5.6,3.4,2.9,2.6,3.4,2.8,3.3,3.6,2.3,4.1,1.8,2.5,6.0,7.6,8.9,10.2,10.7,10.2,11.0,11.6,15.0,13.6,12.1,8.3,6.3,4.2,3.6,4.5,5.9,5.9,6.2,4.3,3.8,3.3,3.4,2.8,0.0,2.6,8.0,8.9,7.9,6.9,13.7,11.1,10.2,13.7,16.6,13.8,13.8,12.3,10.8,11.7,12.4,14.1,14.0,14.7,16.1,15.1,14.1,15.0,16.2,13.9,14.0,14.7,14.1,12.8,10.9,12.5,12.8,6.9,7.6,7.1,6.5,6.2,5.8,5.8,5.8,5.8,5.9,6.2,6.4,7.4,8.4,9.3,9.7,9.7,10.0,10.5,11.3,11.4,11.4,10.9,10.4,9.8,9.3,8.4,7.0,4.9,3.8,4.3,5.6,6.1,5.6,4.9,5.0,6.3,8.2,10.0,11.2,12.8,13.6,14.2,14.7,14.7,17.2,17.2,17.1,16.1,14.5,12.4,9.8,6.5,4.3,3.6,3.3,3.3,3.0,2.9,2.9,3.0,3.2,3.8,5.7,8.2,10.3,11.0,11.2,11.2,11.6,12.1,11.8,10.5,9.0,7.3,5.8,4.9,4.4],"winddirection_10m":[153,132,139,148,140,149,146,139,132,117,111,111,107,106,77,101,57,83,86,104,113,117,162,150,164,148,140,174,174,162,165,101,135,115,109,104,80,76,67,71,68,73,73,78,92,121,110,135,151,137,142,144,265,163,139,302,230,180,304,252,249,270,279,297,306,302,293,304,303,303,291,274,281,287,289,288,287,290,288,289,287,287,280,282,287,285,286,278,311,322,313,278,285,276,277,277,277,274,277,284,291,297,299,301,306,312,321,330,338,343,347,347,343,340,336,332,329,325,324,319,318,320,320,315,306,300,301,308,311,315,320,323,324,324,324,327,331,335,340,346,350,352,354,355,360,6,13,14,7,7,14,27,41,55,61,65,67,69,69,68,67,67,68,74,81,94,107,125],"relativehumidity_2m":[82,83,88,88,89,91,92,86,74,68,62,53,45,40,52,34,55,46,43,48,52,53,63,70,78,80,83,83,82,84,83,81,71,60,55,46,49,45,41,40,39,42,41,42,46,55,60,65,68,72,69,66,70,76,76,81,86,85,82,79,76,81,84,80,70,59,63,67,71,76,78,79,79,79,79,78,79,78,78,79,77,77,76,73,73,71,71,72,70,67,68,67,71,72,72,72,72,72,73,76,80,83,84,85,84,82,78,73,66,59,53,51,50,51,52,54,57,61,65,68,68,66,66,68,71,73,74,74,72,66,58,50,43,37,33,37,39,42,45,48,52,56,60,63,66,68,71,75,80,82,80,75,70,64,58,52,48,44,41,38,36,35,36,39,43,50,59,67],"visibility":[24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,23920.00,23860.00,24140.00,20860.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,23840.00,24140.00,24140.00,24140.00,24140.00,20020.00,24140.00,24140.00,24140.00,8160.00,6920.00,20620.00,24140.00,24140.00,24140.00,18320.00,21900.00,24140.00,24140.00,24140.00,24140.00,21080.00,24140.00,24140.00,23480.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,15600.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,14680.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00,24140.00],"is_day":[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0]},"daily_units":{"time":"iso8601","temperature_2m_max":"°C","temperature_2m_min":"°C","sunrise":"iso8601","sunset":"iso8601","uv_index_max":""},"daily":{"time":["2023-05-21","2023-05-22","2023-05-23","2023-05-24","2023-05-25","2023-05-26","2023-05-27"],"temperature_2m_max":[27.2,26.9,20.7,14.9,20.7,18.6,18.9],"temperature_2m_min":[11.4,13.9,14.6,10.4,12.8,9.4,8.4],"sunrise":["2023-05-21T05:05","2023-05-22T05:03","2023-05-23T05:02","2023-05-24T05:01","2023-05-25T05:00","2023-05-26T04:59","2023-05-27T04:58"],"sunset":["2023-05-21T20:58","2023-05-22T20:59","2023-05-23T21:00","2023-05-24T21:02","2023-05-25T21:03","2023-05-26T21:04","2023-05-27T21:05"],"uv_index_max":[6.20,6.75,2.40,4.20,3.90,4.70,6.20]}})");
qDebug() << data;
bridge->say(tr("I don't know. This is not implemented yet."));
}
You can use the provided 'text' parameter to determine the specific weather action to take
For example, you could make an API call to retrieve weather data and display it to the user
or perform any other relevant operations.
Ensure that the function implementation is consistent with your application's requirements.
https://api.github.com/tim-gromeyer/VoiceAssistant/blob/35519c1397713fb8b279c6b268aff2eb9b296cf7/plugins/weather/weatherplugin.cpp#L45