From d0fcfd08d1999e2e15c689ab8b39d9709b8aa1f3 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 11 Aug 2022 15:20:48 +0200 Subject: [PATCH] Optimisation on TemperatureModule --- modules/__init__.py | 2 +- modules/weather.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/__init__.py b/modules/__init__.py index cb669c7..03a3596 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -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: diff --git a/modules/weather.py b/modules/weather.py index 658d0c0..84cc466 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -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()))