final dashboard commit
This commit is contained in:
parent
76b5c25fee
commit
99e6901655
2 changed files with 49 additions and 48 deletions
|
@ -415,6 +415,7 @@ class PlantGrowthDashboard:
|
|||
params['ambient_mode'] = self.ambient_mode.get()
|
||||
|
||||
current_mode = self.ambient_mode.get()
|
||||
happy_data = 0
|
||||
if current_mode == "open":
|
||||
happy_data = self.happyMeteo.openMeteoCall(days_difference)
|
||||
|
||||
|
@ -432,6 +433,9 @@ class PlantGrowthDashboard:
|
|||
'end_date': self.calendar.get_date().isoformat()
|
||||
}
|
||||
|
||||
if current_mode == "open":
|
||||
submission_data['meteoForecast'] = happy_data
|
||||
|
||||
#Remove plant_info_text
|
||||
self.plant_info_text.delete(1.0, tk.END)
|
||||
|
||||
|
|
|
@ -31,53 +31,50 @@ class HappyMeteo:
|
|||
print(f"Error getting location: {e}")
|
||||
return None, None
|
||||
|
||||
def openMeteoCall(self, timeLapse):
|
||||
lat, lon = self.get_current_location()
|
||||
|
||||
# Make sure all required weather variables are listed here
|
||||
# The order of variables in hourly or daily is important to assign them correctly below
|
||||
url = "https://api.open-meteo.com/v1/forecast"
|
||||
params = {
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"daily": ["weather_code", "temperature_2m_mean", "rain_sum", "showers_sum", "precipitation_sum", "daylight_duration", "relative_humidity_2m_mean"],
|
||||
"timezone": "auto",
|
||||
"forecast_days": timeLapse
|
||||
def openMeteoCall(self, timeLapse):
|
||||
lat, lon = self.get_current_location()
|
||||
|
||||
# Make sure all required weather variables are listed here
|
||||
# The order of variables in hourly or daily is important to assign them correctly below
|
||||
url = "https://api.open-meteo.com/v1/forecast"
|
||||
params = {
|
||||
"latitude": lat,
|
||||
"longitude": lon,
|
||||
"daily": ["weather_code", "temperature_2m_mean", "rain_sum", "showers_sum", "precipitation_sum", "daylight_duration", "relative_humidity_2m_mean"],
|
||||
"timezone": "auto",
|
||||
"forecast_days": timeLapse
|
||||
}
|
||||
responses = self.openmeteo.weather_api(url, params=params)
|
||||
|
||||
# Process first location. Add a for-loop for multiple locations or weather models
|
||||
response = responses[0]
|
||||
|
||||
# Process daily data. The order of variables needs to be the same as requested.
|
||||
daily = response.Daily()
|
||||
daily_weather_code = daily.Variables(0).ValuesAsNumpy()
|
||||
daily_temperature_2m_mean = daily.Variables(1).ValuesAsNumpy()
|
||||
daily_rain_sum = daily.Variables(2).ValuesAsNumpy()
|
||||
daily_showers_sum = daily.Variables(3).ValuesAsNumpy()
|
||||
daily_precipitation_sum = daily.Variables(4).ValuesAsNumpy()
|
||||
daily_daylight_duration = daily.Variables(5).ValuesAsNumpy()
|
||||
daily_relative_humidity_2m_mean = daily.Variables(6).ValuesAsNumpy()
|
||||
|
||||
# Return comprehensive data structure
|
||||
return {
|
||||
"daily_data": {
|
||||
"weather_code": daily_weather_code.tolist(),
|
||||
"temperature_2m_mean": daily_temperature_2m_mean.tolist(),
|
||||
"rain_sum": daily_rain_sum.tolist(),
|
||||
"showers_sum": daily_showers_sum.tolist(),
|
||||
"precipitation_sum": daily_precipitation_sum.tolist(),
|
||||
"daylight_duration": daily_daylight_duration.tolist(),
|
||||
"relative_humidity_2m_mean": daily_relative_humidity_2m_mean.tolist()
|
||||
},
|
||||
"summary": {
|
||||
"avg_temperature": float(daily_temperature_2m_mean.mean()),
|
||||
"total_precipitation": float(daily_precipitation_sum.sum()),
|
||||
"avg_humidity": float(daily_relative_humidity_2m_mean.mean()),
|
||||
"total_daylight_hours": float(daily_daylight_duration.sum() / 3600) # Convert seconds to hours
|
||||
}
|
||||
responses = self.openmeteo.weather_api(url, params=params)
|
||||
|
||||
# Process first location. Add a for-loop for multiple locations or weather models
|
||||
response = responses[0]
|
||||
print(f"Coordinates: {response.Latitude()}°N {response.Longitude()}°E")
|
||||
print(f"Elevation: {response.Elevation()} m asl")
|
||||
print(f"Timezone: {response.Timezone()}{response.TimezoneAbbreviation()}")
|
||||
print(f"Timezone difference to GMT+0: {response.UtcOffsetSeconds()}s")
|
||||
|
||||
# Process daily data. The order of variables needs to be the same as requested.
|
||||
daily = response.Daily()
|
||||
daily_weather_code = daily.Variables(0).ValuesAsNumpy()
|
||||
daily_temperature_2m_mean = daily.Variables(1).ValuesAsNumpy()
|
||||
daily_rain_sum = daily.Variables(2).ValuesAsNumpy()
|
||||
daily_showers_sum = daily.Variables(3).ValuesAsNumpy()
|
||||
daily_precipitation_sum = daily.Variables(4).ValuesAsNumpy()
|
||||
daily_daylight_duration = daily.Variables(5).ValuesAsNumpy()
|
||||
daily_relative_humidity_2m_mean = daily.Variables(6).ValuesAsNumpy()
|
||||
|
||||
daily_data = {"date": pd.date_range(
|
||||
start = pd.to_datetime(daily.Time(), unit = "s", utc = True),
|
||||
end = pd.to_datetime(daily.TimeEnd(), unit = "s", utc = True),
|
||||
freq = pd.Timedelta(seconds = daily.Interval()),
|
||||
inclusive = "left"
|
||||
)}
|
||||
|
||||
daily_data["weather_code"] = daily_weather_code
|
||||
daily_data["temperature_2m_mean"] = daily_temperature_2m_mean
|
||||
daily_data["rain_sum"] = daily_rain_sum
|
||||
daily_data["showers_sum"] = daily_showers_sum
|
||||
daily_data["precipitation_sum"] = daily_precipitation_sum
|
||||
daily_data["daylight_duration"] = daily_daylight_duration
|
||||
daily_data["relative_humidity_2m_mean"] = daily_relative_humidity_2m_mean
|
||||
|
||||
daily_dataframe = pd.DataFrame(data = daily_data)
|
||||
print("\nDaily data\n", daily_dataframe)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue