mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
- weather: add more data to struct
Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
@@ -42,9 +42,10 @@
|
||||
|
||||
#define UPDATE_CYCLE 15 // minutes
|
||||
|
||||
CWeather *weather = NULL;
|
||||
|
||||
CWeather *CWeather::getInstance()
|
||||
{
|
||||
static CWeather *weather = NULL;
|
||||
if (!weather)
|
||||
weather = new CWeather();
|
||||
return weather;
|
||||
@@ -73,7 +74,7 @@ void CWeather::setCoords(std::string new_coords, std::string new_city)
|
||||
{
|
||||
coords = new_coords;
|
||||
city = new_city;
|
||||
GetWeatherDetails();
|
||||
checkUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +131,10 @@ bool CWeather::GetWeatherDetails()
|
||||
timezone = DataValues["timezone"].asString();
|
||||
current.timestamp = DataValues["currently"].get("time", 0).asDouble();
|
||||
current.temperature = DataValues["currently"].get("temperature", "").asFloat();
|
||||
current.windSpeed = DataValues["currently"].get("windSpeed", 0).asFloat();
|
||||
current.windBearing = DataValues["currently"].get("windBearing", 0).asDouble();
|
||||
current.pressure = DataValues["currently"].get("pressure", "").asFloat();
|
||||
current.humidity = DataValues["currently"].get("humidity", "").asFloat();
|
||||
current.windSpeed = DataValues["currently"].get("windSpeed", "").asFloat();
|
||||
current.windBearing = DataValues["currently"].get("windBearing", "").asDouble();
|
||||
current.icon = DataValues["currently"].get("icon", "").asString();
|
||||
if (current.icon.empty())
|
||||
current.icon = "unknown.png";
|
||||
@@ -144,6 +147,7 @@ bool CWeather::GetWeatherDetails()
|
||||
for (unsigned int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
daily_data.timestamp = elements[i].get("time", 0).asDouble();
|
||||
daily_data.weekday = (int)(localtime(&daily_data.timestamp)->tm_wday);
|
||||
daily_data.icon = elements[i].get("icon", "").asString();
|
||||
if (daily_data.icon.empty())
|
||||
daily_data.icon = "unknown.png";
|
||||
@@ -151,6 +155,8 @@ bool CWeather::GetWeatherDetails()
|
||||
daily_data.icon = daily_data.icon + ".png";
|
||||
daily_data.temperatureMin = elements[i].get("temperatureMin", "").asFloat();
|
||||
daily_data.temperatureMax = elements[i].get("temperatureMax", "").asFloat();
|
||||
daily_data.sunriseTime = elements[i].get("sunriseTime", 0).asDouble();
|
||||
daily_data.sunsetTime = elements[i].get("sunsetTime", 0).asDouble();
|
||||
daily_data.windSpeed = elements[i].get("windSpeed", 0).asFloat();
|
||||
daily_data.windBearing = elements[i].get("windBearing", 0).asDouble();
|
||||
|
||||
|
@@ -39,13 +39,17 @@ struct current_data
|
||||
time_t timestamp;
|
||||
std::string icon;
|
||||
float temperature;
|
||||
float humidity;
|
||||
float pressure;
|
||||
float windSpeed;
|
||||
int windBearing;
|
||||
|
||||
current_data():
|
||||
timestamp(0),
|
||||
icon(""),
|
||||
icon("unknown.png"),
|
||||
temperature(0),
|
||||
humidity(0),
|
||||
pressure(0),
|
||||
windSpeed(0),
|
||||
windBearing(0)
|
||||
{}
|
||||
@@ -54,9 +58,12 @@ struct current_data
|
||||
typedef struct
|
||||
{
|
||||
time_t timestamp;
|
||||
int weekday; // 0=Sunday, 1=Monday, ...
|
||||
std::string icon;
|
||||
float temperatureMin;
|
||||
float temperatureMax;
|
||||
time_t sunriseTime;
|
||||
time_t sunsetTime;
|
||||
float windSpeed;
|
||||
int windBearing;
|
||||
} forecast_data;
|
||||
@@ -81,10 +88,13 @@ class CWeather
|
||||
bool checkUpdate(bool forceUpdate = false);
|
||||
void setCoords(std::string new_coords, std::string new_city = "Unknown");
|
||||
|
||||
// globals
|
||||
std::string getCity()
|
||||
{
|
||||
return city;
|
||||
};
|
||||
|
||||
// current conditions
|
||||
#if 0
|
||||
std::string getCurrentTimestamp()
|
||||
{
|
||||
@@ -99,6 +109,14 @@ class CWeather
|
||||
{
|
||||
return to_string((int)(current.temperature + 0.5));
|
||||
};
|
||||
std::string getCurrentHumidity()
|
||||
{
|
||||
return to_string((int)(current.humidity * 100.0));
|
||||
};
|
||||
std::string getCurrentPressure()
|
||||
{
|
||||
return to_string(current.pressure);
|
||||
};
|
||||
std::string getCurrentWindSpeed()
|
||||
{
|
||||
return to_string(current.windSpeed);
|
||||
@@ -111,24 +129,46 @@ class CWeather
|
||||
{
|
||||
return ICONSDIR"/weather/" + current.icon;
|
||||
};
|
||||
|
||||
// forecast conditions
|
||||
int getForecastSize()
|
||||
{
|
||||
return (int)v_forecast.size();
|
||||
};
|
||||
int getForecastWeekday(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return v_forecast[i].weekday;
|
||||
};
|
||||
std::string getForecastTemperatureMin(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return to_string((int)(v_forecast[i].temperatureMin + 0.5));
|
||||
};
|
||||
std::string getForecastTemperatureMax(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return to_string((int)(v_forecast[i].temperatureMax + 0.5));
|
||||
};
|
||||
std::string getForecastWindSpeed(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return to_string(v_forecast[i].windSpeed);
|
||||
};
|
||||
std::string getForecastWindBearing(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return to_string(v_forecast[i].windBearing);
|
||||
};
|
||||
std::string getForecastIcon(int i = 0)
|
||||
{
|
||||
if (i > (int)v_forecast.size())
|
||||
i = (int)v_forecast.size();
|
||||
return ICONSDIR"/weather/" + v_forecast[i].icon;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user