Aviation Units #7

Merged
dicijr merged 3 commits from master into master 2019-05-15 08:40:40 +02:00
4 changed files with 42 additions and 16 deletions

View file

@ -19,14 +19,14 @@ class OwmForecasts (WeatherInterface):
return self.api.is_API_online()
except:
return False
def reload(self):
pass
def get_today_forecast (self, location=None):
if self.is_available() is False:
return None
try:
location = self.location if location is None else location
@ -40,10 +40,10 @@ class OwmForecasts (WeatherInterface):
def get_forecast_in_days (self, offset_by_days, location=None):
if offset_by_days is 0:
return self.get_today_forecast(location)
if self.is_available() is False:
return None
location = self.location if location is None else location
try:
forecast = self.api.daily_forecast(location, limit=offset_by_days)
@ -66,16 +66,21 @@ class OwmForecasts (WeatherInterface):
forecast_object.short_description = translate(str(weather.get_status()))
forecast_object.detailed_description = str(weather.get_detailed_status())
forecast_object.air_pressure = str(weather.get_pressure()['press'])
forecast_object.wind_deg = str(int(weather.get_wind()['deg']))
if forecast_object.units == "metric":
forecast_object.air_temperature = str(int(weather.get_temperature(unit='celsius')['temp']))
forecast_object.wind_speed = str(int(weather.get_wind()['speed']))
forecast_object.wind_speed = str(int(weather.get_wind()['speed'])) #kmh
if forecast_object.units == "aviation":
forecast_object.air_temperature = str(int(weather.get_temperature(unit='celsius')['temp']))
forecast_object.wind_speed = str(int(weather.get_wind()['speed'] * 1.94384)) #knots
if forecast_object.units == "imperial":
forecast_object.air_temperature = str(int(weather.get_temperature('fahrenheit')['temp']))
forecast_object.wind_speed = str(int(weather.get_wind()['speed'] * 0.621))
forecast_object.wind_speed = str(int(weather.get_wind()['speed'] * 0.621)) #mph
forecast_object.sunrise = datetime.fromtimestamp(int(weather.get_sunrise_time(timeformat='unix')))
forecast_object.sunset = datetime.fromtimestamp(int(weather.get_sunset_time(timeformat='unix')))
return forecast_object
return forecast_object

View file

@ -30,16 +30,27 @@ class WeatherColumnDesign (DesignEntity):
def __draw_infos__ (self, forecast):
temperature = forecast.air_temperature + " " + self.__get_unit__(("°C", "°F"))
humidity = forecast.air_humidity + "%"
windspeed = forecast.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
if self.forecast.units== "aviation":
if len(forecast.wind_deg)==1:
forecast.wind_deg = "00" + forecast.wind_deg
elif len(forecast.wind_deg)==2:
forecast.wind_deg = "0" + forecast.wind_deg
if int(forecast.wind_speed)<10:
windspeed = forecast.wind_deg + "@" + "0" + forecast.wind_speed + self.__get_unit__(("", "")) #added degrees, if wind<10 add a 0 to make two digit
else:
windspeed = forecast.wind_deg + "@" + forecast.wind_speed + self.__get_unit__(("", "")) #added degrees
else:
windspeed = forecast.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
numbers_list = [ [ forecast.short_description ],
[ temperature ],
[ humidity ],
[ windspeed ]]
[ windspeed ] ]
ypos = info_x_ypos * self.size[0]
pos = (0, ypos)
size = (self.size[0], self.size[1] + info_yresize * self.size[1] - pos[1])
print(size)
line_spacing = (size[1] - len(numbers_list) * fontsize_static) / (len(numbers_list) + 1)
table = TableDesign(size, numbers_list, fontsize=fontsize_static, line_spacing=line_spacing, column_horizontal_alignments=[ "center" ], max_col_size=[ size[0] ], truncate_text=False, truncate_rows=False)
@ -75,7 +86,7 @@ class WeatherColumnDesign (DesignEntity):
def __get_unit__ (self, tuple):
if self.forecast.units == "metric":
if self.forecast.units == "metric" or self.forecast.units == "aviation":
return tuple[0]
else:
return tuple[1]
@ -87,4 +98,4 @@ class WeatherColumnDesign (DesignEntity):
if hours == "24":
return time.strftime('%H:%M')
else:
return time.strftime('%I:%M')
return time.strftime('%I:%M')

View file

@ -29,7 +29,17 @@ class WeatherHeaderDesign (DesignEntity):
return
temperature = cur_weather.air_temperature + " " + self.__get_unit__(("°C", "°F"))
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
if units== "aviation": #pick up aviation
if len(forecast.wind_deg)==1: #if deg is 2, add two zeros for format
forecast.wind_deg = "00" + forecast.wind_deg
elif len(forecast.wind_deg)==2:
forecast.wind_deg = "0" + forecast.wind_deg
if int(cur_weather.wind_speed)<10:
windspeed = cur_weather.wind_deg + "@" + "0" + cur_weather.wind_speed + self.__get_unit__(("", "")) #added degrees, if wind<10 add a 0 to make two digit
else:
windspeed = cur_weather.wind_deg + "@" + cur_weather.wind_speed + self.__get_unit__(("", "")) #added degrees
else:
windspeed = cur_weather.wind_speed + " " + self.__get_unit__(("km/h", "mph"))
self.__draw_text__(temperature, self.__abs_pos__((0.87, 0)), (50,35))
self.__draw_text__(windspeed, self.__abs_pos__((0.297, 0.05)), (100,35))
@ -57,7 +67,7 @@ class WeatherHeaderDesign (DesignEntity):
self.draw_design(txt)
def __get_unit__ (self, tuple):
if units == "metric":
if units == "metric" or units == "aviation":
return tuple[0]
else:
return tuple[1]
@ -66,4 +76,4 @@ class WeatherHeaderDesign (DesignEntity):
if hours == "24":
return time.strftime('%H:%M')
else:
return time.strftime('%I:%M')
return time.strftime('%I:%M')

View file

@ -18,7 +18,7 @@ week_starts_on = "Monday"
display_colours = "bwr"
language = "en"
datetime_encoding = "UTF-8" # UTF-8
units = "metric"
units = "metric" #aviation (celcius,degrees/knots), metric (celcius,kmh), imperial(f,mph)
hours = "24"
update_interval = 60
@ -38,4 +38,4 @@ general_settings = { # General settings that designs may use
render_to_display = True
render_to_file = False # Will be called "design_exported.png" in Calendar-directory
calibrate_hours = [0, 12, 18]
print_technical_data = False
print_technical_data = False