From 9225dc471c53f35ae603594c4c97ffa49885a410 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Wed, 28 Apr 2021 21:20:09 +0200 Subject: [PATCH] clode clean --- trip.py | 7 +++---- web/db.py | 4 ++-- web/figures.py | 4 ++-- web/views.py | 8 ++++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/trip.py b/trip.py index 36dd39c..158e2ce 100644 --- a/trip.py +++ b/trip.py @@ -1,4 +1,3 @@ -import traceback from statistics import mean from typing import List, Dict @@ -233,8 +232,8 @@ class Trips(list): def get_info(self): res = [] - id = 1 + row_id = 1 for trip in self: - res.append(trip.get_info(id)) - id += 1 + res.append(trip.get_info(row_id)) + row_id += 1 return res diff --git a/web/db.py b/web/db.py index 8eab1aa..df41969 100644 --- a/web/db.py +++ b/web/db.py @@ -156,8 +156,8 @@ class Database: logger.warning("There is %s to fetch from API, it can take some time", nb_null) try: while True: - res = conn.execute(f"SELECT DISTINCT latitude,longitude " - f"FROM position WHERE altitude IS NULL LIMIT {max_pos_by_req};").fetchall() + res = conn.execute("SELECT DISTINCT latitude,longitude " + "FROM position WHERE altitude IS NULL LIMIT ?;", max_pos_by_req).fetchall() nb_res = len(res) if nb_res > 0: logger.debug("add altitude for %s positions point", len(nb_null)) diff --git a/web/figures.py b/web/figures.py index ebada39..a8d8812 100644 --- a/web/figures.py +++ b/web/figures.py @@ -3,6 +3,7 @@ from datetime import datetime from typing import List +import pytz import dash_bootstrap_components as dbc import dash_table import numpy as np @@ -14,7 +15,6 @@ import plotly.graph_objects as go from pandas import DataFrame from pandas import options as pandas_options import dash_html_components as html -import pytz from libs.car import Car from libs.elec_price import ElecPrice @@ -256,7 +256,7 @@ def get_battery_curve_fig(row: dict, car: Car): return html.Div(Graph(figure=fig)) -def get_altitude_fig(trip:Trip): +def get_altitude_fig(trip: Trip): conn = Database.get_db() res = list(map(list, conn.execute("SELECT mileage, altitude FROM position WHERE Timestamp>=? and Timestamp<=?;", (trip.start_at, trip.end_at)).fetchall())) diff --git a/web/views.py b/web/views.py index 47d1722..c312763 100644 --- a/web/views.py +++ b/web/views.py @@ -127,7 +127,7 @@ def get_altitude(active_cell, close, is_open): # pylint: disable=unused-argumen if is_open is None: is_open = False if active_cell is not None and active_cell["column_id"] in ["altitude_diff"] and not is_open: - return figures.get_altitude_fig(trips[active_cell["row_id"]-1]), True + return figures.get_altitude_fig(trips[active_cell["row_id"] - 1]), True return "", False @@ -356,9 +356,9 @@ def serve_layout(): dbc.Tab(label="Map", tab_id="map", children=[maps]), dbc.Tab(label="Control", tab_id="control", children=dbc.Tabs(id="control-tabs", children=__get_control_tabs()))], - id="tabs", - active_tab="summary", - persistence=True), + id="tabs", + active_tab="summary", + persistence=True), html.Div(id=EMPTY_DIV), html.Div(id=EMPTY_DIV + "1") ])])