[eval_records]
- refactored
This commit is contained in:
+44
-15
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
import json
|
||||
import numpy as np
|
||||
from datetime import datetime, timedelta
|
||||
import dateutil.parser as dup
|
||||
from jay_diff import jay_merge_full
|
||||
from matplotlib import pyplot as plot
|
||||
@@ -45,7 +46,8 @@ def convert(_filename: str) -> int:
|
||||
|
||||
|
||||
class Endpoint:
|
||||
def __init__(self, _ep_spec: dict, _ts_format='%Y-%m-%dT%H:%M:%S.%f%z'):
|
||||
def __init__(self, _name: str, _ep_spec: dict, _ts_format='%Y-%m-%dT%H:%M:%S.%f%z'):
|
||||
self._name = _name
|
||||
self._ep_path = _ep_spec["values"]
|
||||
self._ep_path_keys = self.to_keys(self._ep_path)
|
||||
self._timestamps = []
|
||||
@@ -57,6 +59,10 @@ class Endpoint:
|
||||
def timestamps_str(self) -> str:
|
||||
return f"{self._ep_path}:{len(self._timestamps)}: {self._timestamps}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def timestamps(self) -> list[int]:
|
||||
return self._timestamps
|
||||
@@ -126,7 +132,7 @@ def check_sel(root_path, sel: list):
|
||||
return res
|
||||
|
||||
|
||||
def process(end_points, base_path: str, user: str, vin: str, sel_years=None, sel_months=None, sel_days=None, sel_hours=None):
|
||||
def process(end_points: list[Endpoint], base_path: str, user: str, vin: str, sel_years=None, sel_months=None, sel_days=None, sel_hours=None):
|
||||
_path = os.path.join(base_path, user)
|
||||
root_path = os.path.join(_path, vin)
|
||||
|
||||
@@ -172,44 +178,67 @@ def process(end_points, base_path: str, user: str, vin: str, sel_years=None, sel
|
||||
vehicle_data = jay_merge_full(last, vehicle_diff)
|
||||
last = vehicle_data
|
||||
try:
|
||||
for k in end_points.keys():
|
||||
end_points[k].assign({'info': record['info'], 'data': vehicle_data})
|
||||
for ep in end_points:
|
||||
ep.assign({'info': record['info'], 'data': vehicle_data})
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
for k in end_points.keys():
|
||||
end_points[k].remove_dups()
|
||||
for ep in end_points:
|
||||
ep.remove_dups()
|
||||
|
||||
|
||||
def find_ep_by_name(end_points: list[Endpoint], name: str):
|
||||
for ep in end_points:
|
||||
if name in ep.name:
|
||||
return ep
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def process_events(_ep_dict: dict, ts_from: datetime, ts_to: datetime, ts_step: timedelta):
|
||||
for ep_key in _ep_dict:
|
||||
for ep in _ep_dict[ep_key]:
|
||||
now = ts_from
|
||||
while now < ts_to:
|
||||
print(f"Date/time: {now}")
|
||||
now += ts_step
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
end_points = {}
|
||||
end_points = []
|
||||
for k in settings.eps.keys():
|
||||
end_points[k] = Endpoint(settings.eps[k])
|
||||
end_points.append(Endpoint(k, settings.eps[k]))
|
||||
|
||||
process(end_points, settings.BASE, settings.USER, settings.VIN, sel_days=settings.sel_days)
|
||||
|
||||
# process_events(end_points, datetime(2024, 10, 25, 0, 0, 0), datetime(2024, 10, 26, 0, 0, 0), timedelta(hours=1))
|
||||
|
||||
speed = [0]
|
||||
_speed = 0
|
||||
for i in range(1, len(end_points['odo'].timestamps)):
|
||||
dt = float(end_points['odo'].timestamps[i] - end_points['odo'].timestamps[i-1])/(60*100000000)
|
||||
dv = end_points['odo'].values[i] - end_points['odo'].values[i-1]
|
||||
ep_odo = find_ep_by_name(end_points, name="odo")
|
||||
ep_soc = find_ep_by_name(end_points, name="soc")
|
||||
ep_range = find_ep_by_name(end_points, name="range")
|
||||
|
||||
for i in range(1, len(ep_odo.timestamps)):
|
||||
dt = float(ep_odo.timestamps[i] - ep_odo.timestamps[i-1])/(60*100000000)
|
||||
dv = ep_odo.values[i] - ep_odo.values[i-1]
|
||||
_speed = 0.9*_speed + 0.1*dv/dt
|
||||
speed.append(_speed)
|
||||
|
||||
plot.subplot(4, 1, 1)
|
||||
plot.plot(np.array(end_points['odo'].timestamps) - end_points['odo'].timestamps[0], np.array(end_points['odo'].values) - end_points['odo'].values[0])
|
||||
plot.plot(np.array(ep_odo.timestamps) - ep_odo.timestamps[0], np.array(ep_odo.values) - ep_odo.values[0])
|
||||
plot.title("Kilometerstand")
|
||||
plot.grid()
|
||||
plot.subplot(4, 1, 2)
|
||||
plot.plot(np.array(end_points['odo'].timestamps) - end_points['odo'].timestamps[0], speed)
|
||||
plot.plot(np.array(ep_odo.timestamps) - ep_odo.timestamps[0], speed)
|
||||
plot.title("Speed")
|
||||
plot.grid()
|
||||
plot.subplot(4, 1, 3)
|
||||
plot.plot(np.array(end_points['soc'].timestamps) - end_points['soc'].timestamps[0], end_points['soc'].values)
|
||||
plot.plot(np.array(ep_soc.timestamps) - ep_soc.timestamps[0], ep_soc.values)
|
||||
plot.title("Akkustand")
|
||||
plot.grid()
|
||||
plot.subplot(4, 1, 4)
|
||||
plot.plot(np.array(end_points['range'].timestamps) - end_points['range'].timestamps[0], end_points['range'].values)
|
||||
plot.plot(np.array(ep_range.timestamps) - ep_range.timestamps[0], ep_range.values)
|
||||
plot.title("Range")
|
||||
plot.grid()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user