mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-24 02:16:14 +00:00
format date depending of server localization and disable sorting because only compatible with English format
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
from dateutil import tz
|
||||
from geojson import Feature, FeatureCollection, MultiLineString
|
||||
|
||||
from Car import Cars, Car
|
||||
@@ -43,7 +44,7 @@ class Trip:
|
||||
if diff_level < 0:
|
||||
logger.debugv("trip has negative consumption")
|
||||
diff_level = 0
|
||||
self.consumption = diff_level * self.car.battery_power/100
|
||||
self.consumption = diff_level * self.car.battery_power / 100
|
||||
self.consumption_km = 100 * self.consumption / self.distance # kw/100 km
|
||||
return self.consumption_km
|
||||
|
||||
@@ -76,10 +77,11 @@ class Trip:
|
||||
"average consumption fuel": self.consumption_fuel_km})
|
||||
|
||||
def get_info(self):
|
||||
res = {"start_at": self.start_at.astimezone(None).strftime("%x %X"),
|
||||
"end_at": self.end_at.astimezone(None).strftime("%x %X"), "duration": self.duration * 60,
|
||||
"speed_average": self.speed_average, "consumption_km": self.consumption_km,
|
||||
"consumption_fuel_km": self.consumption_fuel_km, "distance": self.distance, "mileage": self.mileage}
|
||||
res = {"start_at": self.start_at.astimezone(tz.tzlocal()).replace(tzinfo=None).strftime("%x %X"),
|
||||
# convert to naive tz,
|
||||
"duration": self.duration * 60, "speed_average": self.speed_average,
|
||||
"consumption_km": self.consumption_km, "consumption_fuel_km": self.consumption_fuel_km,
|
||||
"distance": self.distance, "mileage": self.mileage}
|
||||
return res
|
||||
|
||||
|
||||
@@ -99,7 +101,7 @@ class Trips(list):
|
||||
"consumption": tr.consumption})
|
||||
return res
|
||||
|
||||
def check_and_append(self,tr:Trip):
|
||||
def check_and_append(self, tr: Trip):
|
||||
if tr.consumption_km <= tr.car.max_elec_consumption and tr.consumption_fuel_km <= tr.car.max_fuel_consumption:
|
||||
self.append(tr)
|
||||
return True
|
||||
@@ -135,7 +137,7 @@ class Trips(list):
|
||||
except ZeroDivisionError:
|
||||
speed_average = 0
|
||||
restart_trip = False
|
||||
if trip_parser.is_refuel(start, end, distance ):
|
||||
if trip_parser.is_refuel(start, end, distance):
|
||||
restart_trip = True
|
||||
elif speed_average < 0.2 and duration > 0.05:
|
||||
restart_trip = True
|
||||
@@ -181,7 +183,7 @@ class Trips(list):
|
||||
diff_level, diff_level_fuel = trip_parser.get_level_consumption(start, end)
|
||||
tr.car = car
|
||||
if diff_level != 0:
|
||||
tr.set_consumption(diff_level)# kw
|
||||
tr.set_consumption(diff_level) # kw
|
||||
if diff_level_fuel != 0:
|
||||
tr.set_fuel_consumption(diff_level_fuel)
|
||||
tr.mileage = end["mileage"]
|
||||
|
||||
+1
-1
@@ -19,11 +19,11 @@ app = None
|
||||
dash_app = None
|
||||
dispatcher = None
|
||||
|
||||
|
||||
def start_app(title, base_path, debug: bool, host, port):
|
||||
global app, dash_app, dispatcher
|
||||
try:
|
||||
lang = locale.getlocale()[0].split("_")[0]
|
||||
locale.setlocale(locale.LC_TIME, ".".join(locale.getlocale())) #make sure LC_TIME is set
|
||||
locale_url = [f"https://cdn.plot.ly/plotly-locale-{lang}-latest.js"]
|
||||
except IndexError:
|
||||
locale_url = None
|
||||
|
||||
+11
-9
@@ -54,7 +54,8 @@ battery_table = None
|
||||
|
||||
|
||||
def get_figures(trips: Trips, charging: List[dict]):
|
||||
global consumption_fig, consumption_df, trips_map, consumption_fig_by_speed, table_fig, info, battery_info, battery_table
|
||||
global consumption_fig, consumption_df, trips_map, consumption_fig_by_speed, table_fig, info, battery_info, \
|
||||
battery_table
|
||||
lats = []
|
||||
lons = []
|
||||
names = []
|
||||
@@ -73,7 +74,7 @@ def get_figures(trips: Trips, charging: List[dict]):
|
||||
table_fig = dash_table.DataTable(
|
||||
id='trips-table',
|
||||
sort_action='native',
|
||||
sort_by=[{'column_id': 'start_at', 'direction': 'desc'}],
|
||||
# sort_by=[{'column_id': 'start_at', 'direction': 'desc'}],
|
||||
columns=[{'id': 'start_at', 'name': 'start at', 'type': 'datetime'},
|
||||
{'id': 'duration', 'name': 'duration', 'type': 'numeric',
|
||||
'format': deepcopy(nb_format).symbol_suffix(" min").precision(0)},
|
||||
@@ -87,7 +88,8 @@ def get_figures(trips: Trips, charging: List[dict]):
|
||||
'format': nb_format.symbol_suffix(" km").precision(1)},
|
||||
{'id': 'mileage', 'name': 'mileage', 'type': 'numeric',
|
||||
'format': nb_format.symbol_suffix(" km").precision(1)}],
|
||||
data=[tr.get_info() for tr in trips],
|
||||
data=[tr.get_info() for tr in trips[::-1]],
|
||||
page_size=50
|
||||
)
|
||||
# consumption_fig
|
||||
consumption_df = DataFrame.from_records(trips.get_long_trips())
|
||||
@@ -130,12 +132,12 @@ def get_figures(trips: Trips, charging: List[dict]):
|
||||
{"name": " ", "value:": "{:.1f} g/kWh".format(co2_per_kw)},
|
||||
{"name": "Average charge speed:", "value": "{:.3f} kW".format(charge_speed)}])
|
||||
battery_info = html.Div(children=[html.Tr(
|
||||
[
|
||||
html.Td('Average emission:', rowSpan=2),
|
||||
html.Td("{:.1f} g/km".format(co2_per_km)),
|
||||
]
|
||||
),
|
||||
html. Tr(
|
||||
[
|
||||
html.Td('Average emission:', rowSpan=2),
|
||||
html.Td("{:.1f} g/km".format(co2_per_km)),
|
||||
]
|
||||
),
|
||||
html.Tr(
|
||||
[
|
||||
"{:.1f} g/kWh".format(co2_per_kw),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user