[eval_records]

- fixed date/time parsing
This commit is contained in:
2024-10-24 09:04:23 +02:00
parent 87fc8d6119
commit 5204a6e027
+39 -18
View File
@@ -1,6 +1,10 @@
import json import json
import os import os
from datetime import datetime from datetime import datetime
import dateutil.parser as dup
import numpy as np
from jay_diff import jay_merge_full from jay_diff import jay_merge_full
from matplotlib import pyplot as plot from matplotlib import pyplot as plot
@@ -10,7 +14,7 @@ VIN = 'WVWZZZE1ZMP010760'
USER = 'alex' USER = 'alex'
YEAR = 2024 YEAR = 2024
MONTH = 10 MONTH = 10
DAY = ['15', '16', '17', '18', '19', '20', '21', '22', '23'] DAYS = [15, 16, 17, 18, 19, 20, 21, 22, 23]
def has_diff_entries(diff): def has_diff_entries(diff):
@@ -58,7 +62,7 @@ class Endpoint:
# Extract timestamp # Extract timestamp
capture_time = self.deref_multi(_record, self._ts_path_keys) capture_time = self.deref_multi(_record, self._ts_path_keys)
timestamp_int = convert(capture_time, self._ts_format) timestamp_int = convert(capture_time)
self._timestamps += [timestamp_int] self._timestamps += [timestamp_int]
def remove_dups(self): def remove_dups(self):
@@ -90,14 +94,22 @@ class Endpoint:
end_points = { end_points = {
'odo': Endpoint('data/measurements/odometerStatus/value/odometer', 'info/timestamp'), 'odo': Endpoint('data/measurements/odometerStatus/value/odometer', 'data/measurements/odometerStatus/value/carCapturedTimestamp'),
'soc': Endpoint('data/measurements/fuelLevelStatus/value/currentSOC_pct', 'info/timestamp'), 'soc': Endpoint('data/measurements/fuelLevelStatus/value/currentSOC_pct', 'data/measurements/fuelLevelStatus/value/carCapturedTimestamp'),
'engine': Endpoint('data/fuelStatus/rangeStatus/value/primaryEngine', 'info/timestamp')
} }
def convert(timestamp_str: str, pattern: str = "%Y-%m-%dT%H:%M:%S.%f%z"): def convert(_filename: str):
ts = datetime.strptime(timestamp_str, pattern) name = _filename
if "records_" in _filename:
name = os.path.splitext(_filename)[0].split("_")[1]
date_str = name.split("T")[0]
time_str = name.split("T")[1]
if "-" in time_str:
time_str = time_str.replace("-", ":")
timestamp_str = f"{date_str}T{time_str}"
ts = dup.parse(timestamp_str)
result = ts.year result = ts.year
result = 100*result + ts.month result = 100*result + ts.month
result = 100*result + ts.day result = 100*result + ts.day
@@ -123,15 +135,15 @@ month_path = path
record_list = [] record_list = []
last = {} last = {}
for day in day_list: for _day in DAYS:
if DAY is not None: day = str(_day)
if day not in DAY: if day not in day_list:
continue continue
day_path = os.path.join(month_path, day) day_path = os.path.join(month_path, day)
# Sort out files with unknown nickname # Sort out files with unknown nickname
file_list = os.listdir(day_path) file_list = os.listdir(day_path)
file_list_sorted = sorted(file_list, key=lambda f: convert(f, pattern=f"records_%Y-%m-%dT%H-%M-%S.json")) file_list_sorted = sorted(file_list, key=lambda f: convert(f))
print("Files in '", day_path, "' :") print("Files in '", day_path, "' :")
# prints all files # prints all files
print(file_list_sorted) print(file_list_sorted)
@@ -149,10 +161,8 @@ for day in day_list:
if 'is_delta' in record['info']: if 'is_delta' in record['info']:
if record['info']['is_delta']: if record['info']['is_delta']:
is_header = False is_header = False
print(f"Found delta record #{record['info']['record_id']}")
if is_header: if is_header:
print(f"Found full record #{record['info']['record_id']}")
last = {} last = {}
except KeyError as e: except KeyError as e:
@@ -172,13 +182,24 @@ for day in day_list:
for k in end_points.keys(): for k in end_points.keys():
end_points[k].remove_dups() end_points[k].remove_dups()
plot.subplot(2, 1, 1) speed = [0]
plot.plot(end_points['odo'].timestamps, end_points['odo'].values) 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]
_speed = dv/dt
speed.append(_speed)
plot.subplot(3, 1, 1)
plot.plot(end_points['odo'].timestamps, np.array(end_points['odo'].values) - end_points['odo'].values[0])
plot.title("Kilometerstand") plot.title("Kilometerstand")
plot.grid() plot.grid()
plot.subplot(2, 1, 2) plot.subplot(3, 1, 2)
plot.plot(end_points['odo'].timestamps, end_points['soc'].values) plot.plot(end_points['odo'].timestamps, speed)
plot.title("Akku in %") plot.title("Speed")
plot.grid()
plot.subplot(3, 1, 3)
plot.plot(end_points['soc'].timestamps, end_points['soc'].values)
plot.title("Akkustand")
plot.grid() plot.grid()
plot.show() plot.show()