diff --git a/apps/predbat/web.py b/apps/predbat/web.py index e9b3e814..105cf7d5 100644 --- a/apps/predbat/web.py +++ b/apps/predbat/web.py @@ -21,7 +21,6 @@ TIME_FORMAT_DAILY = "%Y-%m-%d" - class WebInterface: def __init__(self, base) -> None: self.abort = False @@ -73,7 +72,7 @@ def history_attribute(self, history, state_key="state", last_updated_key="last_u try: state = float(state) * scale if pounds: - state = dp2(state / 100) + state = dp2(state/100) last_updated_time = item[last_updated_key] last_updated_stamp = str2time(last_updated_time) except (ValueError, TypeError): @@ -120,10 +119,10 @@ def history_update(self): self.cost_yesterday_car_hist = self.history_attribute(self.base.get_history_wrapper(self.base.prefix + ".cost_yesterday_car", 28), daily=True, offset_days=-1, pounds=True) self.cost_yesterday_no_car = self.subtract_daily(self.cost_yesterday_hist, self.cost_yesterday_car_hist) - compare_list = self.base.get_arg("compare_list", []) + compare_list = self.base.get_arg('compare_list', []) for item in compare_list: id = item.get("id", None) - if id and self.base.comparison: + if id and self.base.comparison: self.compare_hist[id] = {} result = self.base.comparison.get_comparison(id) if result: @@ -230,7 +229,7 @@ def get_header(self, title, refresh=0): """ Return the HTML header for a page """ - text = "Predbat Web Interface" + text = "Predbat Web Interface" text += """ @@ -344,7 +343,7 @@ def get_chart_series(self, name, results, chart_type, color): text += " }\n" return text - def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname="chart", daily_chart=True): + def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname='chart', daily_chart=True): """ Render a chart """ @@ -405,7 +404,7 @@ def render_chart(self, series_data, yaxis_name, chart_name, now_str, tagname="ch start: 'day' }, """ - + text += " series: [\n" first = True opacity = [] @@ -849,7 +848,7 @@ async def html_charts(self, request): args = request.query chart = args.get("chart", "Battery") self.default_page = "./charts?chart={}".format(chart) - text = self.get_header("Predbat Charts", refresh=60 * 5) + text = self.get_header("Predbat Charts", refresh=60*5) text += "\n" text += "

{} Chart

\n".format(chart) text += '- Battery ' @@ -870,7 +869,7 @@ async def html_apps(self, request): Render apps.yaml as an HTML page """ self.default_page = "./apps" - text = self.get_header("Predbat Apps.yaml", refresh=60 * 5) + text = self.get_header("Predbat Apps.yaml", refresh=60*5) text += "\n" text += "apps.yaml
\n" text += "\n" @@ -991,7 +990,7 @@ async def html_compare(self, request): """ self.default_page = "./compare" - text = self.get_header("Predbat Compare", refresh=5 * 60) + text = self.get_header("Predbat Compare", refresh=5*60) text += "\n" text += '\n' @@ -1013,7 +1012,7 @@ async def html_compare(self, request): text += "" text += "\n" - compare_list = self.base.get_arg("compare_list", []) + compare_list = self.base.get_arg('compare_list', []) for compare in compare_list: name = compare.get("name", "") @@ -1050,7 +1049,7 @@ async def html_compare(self, request): self.compare_hist[id]["metric"][stamp] = dp2(metric / 100) self.compare_hist[id]["cost"][stamp] = dp2(cost / 100.0) - selected = ' Best ' if best else "" + selected = ' Best ' if best else '' if existing_tariff: selected += ' Existing ' @@ -1073,10 +1072,10 @@ async def html_compare(self, request): for compare in compare_list: name = compare.get("name", "") id = compare.get("id", "") - series_data.append({"name": name, "data": self.compare_hist.get(id, {}).get("metric", {}), "chart_type": "bar"}) - series_data.append({"name": "Actual", "data": self.cost_yesterday_hist, "chart_type": "line", "stroke_width": "2"}) + series_data.append({"name" : name, "data" : self.compare_hist.get(id, {}).get("metric", {}), "chart_type": "bar"}) + series_data.append({"name" : "Actual", "data" : self.cost_yesterday_hist, "chart_type": "line", "stroke_width": "2"}) if self.base.car_charging_hold: - series_data.append({"name": "Actual (no car)", "data": self.cost_yesterday_no_car, "chart_type": "line", "stroke_width": "2"}) + series_data.append({"name" : "Actual (no car)", "data" : self.cost_yesterday_no_car, "chart_type": "line", "stroke_width": "2"}) now_str = self.base.now_utc.strftime(TIME_FORMAT)
CarbonResult