Optimisation on TemperatureModule
This commit is contained in:
parent
450f1eb9dd
commit
d0fcfd08d1
@ -26,7 +26,7 @@ class Config:
|
||||
gauge_background="red",
|
||||
colors=('#000', '#777'))
|
||||
|
||||
self.charts_opts = {'style': self.pygal_custom_style, 'show_legend': False, 'margin_right': 7, 'margin_left': 2, 'margin_bottom': 1, 'margin_top': 1}
|
||||
self.charts_opts = {'style': self.pygal_custom_style, 'show_legend': False, 'margin_right': 7, 'margin_left': 2, 'margin_bottom': 4, 'margin_top': 1}
|
||||
|
||||
class RuleModule:
|
||||
|
||||
|
@ -185,19 +185,19 @@ class WeatherTemperatureModule:
|
||||
def draw_module(self, config, width, height):
|
||||
thisdayweather = WeatherAPI().get_daily()["data"][0]
|
||||
|
||||
line_chart = pygal.Line(interpolate='cubic', width=width, height=height, inverse_y_axis=False, x_label_rotation=45, secondary_range=(0,100) if thisdayweather["precipProbability"] > 0 else (0,8), **config.charts_opts)
|
||||
line_chart = pygal.Line(interpolate='cubic', width=width, height=height, inverse_y_axis=False, x_label_rotation=45, secondary_range=(0,100) if thisdayweather["precipProbability"] > 0 else (0,10), **config.charts_opts)
|
||||
line_chart.value_formatter = lambda x: "%d" % x
|
||||
|
||||
hours_weather = WeatherAPI().get_hourly()
|
||||
|
||||
line_chart.x_labels = [datetime.fromtimestamp(d["time"], tz=timezone.utc).strftime("%Hh") for d in hours_weather["data"][:self.limit_futur]]
|
||||
line_chart.x_labels = [datetime.fromtimestamp(d["time"], tz=timezone.utc).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]]
|
||||
|
||||
line_chart.add('Températures', [d["temperature"] for d in hours_weather["data"][:self.limit_futur]], show_dots=False)
|
||||
|
||||
if thisdayweather["precipProbability"] > 0:
|
||||
line_chart.add('Précipitations', [d["precipProbability"] * 100 for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False)
|
||||
line_chart.add('Précipitations', [d["precipProbability"] * 100 for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False, fill=True)
|
||||
else:
|
||||
line_chart.add('Précipitations', [d["uvIndex"] for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False)
|
||||
line_chart.add('Index UV', [d["uvIndex"] for d in hours_weather["data"][:self.limit_futur]], secondary=True, show_dots=False)
|
||||
|
||||
return Image.open(io.BytesIO(line_chart.render_to_png()))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user