[eval_records]
- fixed date/time parsing
This commit is contained in:
+39
-18
@@ -1,6 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
import dateutil.parser as dup
|
||||
|
||||
import numpy as np
|
||||
|
||||
from jay_diff import jay_merge_full
|
||||
from matplotlib import pyplot as plot
|
||||
|
||||
@@ -10,7 +14,7 @@ VIN = 'WVWZZZE1ZMP010760'
|
||||
USER = 'alex'
|
||||
YEAR = 2024
|
||||
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):
|
||||
@@ -58,7 +62,7 @@ class Endpoint:
|
||||
|
||||
# Extract timestamp
|
||||
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]
|
||||
|
||||
def remove_dups(self):
|
||||
@@ -90,14 +94,22 @@ class Endpoint:
|
||||
|
||||
|
||||
end_points = {
|
||||
'odo': Endpoint('data/measurements/odometerStatus/value/odometer', 'info/timestamp'),
|
||||
'soc': Endpoint('data/measurements/fuelLevelStatus/value/currentSOC_pct', 'info/timestamp'),
|
||||
'engine': Endpoint('data/fuelStatus/rangeStatus/value/primaryEngine', 'info/timestamp')
|
||||
'odo': Endpoint('data/measurements/odometerStatus/value/odometer', 'data/measurements/odometerStatus/value/carCapturedTimestamp'),
|
||||
'soc': Endpoint('data/measurements/fuelLevelStatus/value/currentSOC_pct', 'data/measurements/fuelLevelStatus/value/carCapturedTimestamp'),
|
||||
}
|
||||
|
||||
|
||||
def convert(timestamp_str: str, pattern: str = "%Y-%m-%dT%H:%M:%S.%f%z"):
|
||||
ts = datetime.strptime(timestamp_str, pattern)
|
||||
def convert(_filename: str):
|
||||
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 = 100*result + ts.month
|
||||
result = 100*result + ts.day
|
||||
@@ -123,15 +135,15 @@ month_path = path
|
||||
record_list = []
|
||||
last = {}
|
||||
|
||||
for day in day_list:
|
||||
if DAY is not None:
|
||||
if day not in DAY:
|
||||
for _day in DAYS:
|
||||
day = str(_day)
|
||||
if day not in day_list:
|
||||
continue
|
||||
day_path = os.path.join(month_path, day)
|
||||
|
||||
# Sort out files with unknown nickname
|
||||
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, "' :")
|
||||
# prints all files
|
||||
print(file_list_sorted)
|
||||
@@ -149,10 +161,8 @@ for day in day_list:
|
||||
if 'is_delta' in record['info']:
|
||||
if record['info']['is_delta']:
|
||||
is_header = False
|
||||
print(f"Found delta record #{record['info']['record_id']}")
|
||||
|
||||
if is_header:
|
||||
print(f"Found full record #{record['info']['record_id']}")
|
||||
last = {}
|
||||
|
||||
except KeyError as e:
|
||||
@@ -172,13 +182,24 @@ for day in day_list:
|
||||
for k in end_points.keys():
|
||||
end_points[k].remove_dups()
|
||||
|
||||
plot.subplot(2, 1, 1)
|
||||
plot.plot(end_points['odo'].timestamps, end_points['odo'].values)
|
||||
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]
|
||||
_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.grid()
|
||||
plot.subplot(2, 1, 2)
|
||||
plot.plot(end_points['odo'].timestamps, end_points['soc'].values)
|
||||
plot.title("Akku in %")
|
||||
plot.subplot(3, 1, 2)
|
||||
plot.plot(end_points['odo'].timestamps, speed)
|
||||
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.show()
|
||||
|
||||
Reference in New Issue
Block a user