diff --git a/eval_records.py b/eval_records.py index 9ef7789..1a52805 100644 --- a/eval_records.py +++ b/eval_records.py @@ -6,34 +6,36 @@ BASE = "results" VIN = 'WVWZZZE1ZMP010760' YEAR = 2024 MONTH = 10 -DAY = None +DAY = "18" class Endpoint: - def __init__(self, _base_path: str, _ep_path: str, ts_spec: dict = {'name': 'carCapturedTimestamp', 'format': '%Y-%m-%dT%H:%M:%S.%f%z'}): - self._base_path = _base_path - self._base_path_keys = self.to_keys(_base_path) + def __init__(self, _ep_path: str, _ts_path: str, _ts_format='%Y-%m-%dT%H:%M:%S.%f%z'): self._ep_path = _ep_path self._ep_path_keys = self.to_keys(_ep_path) self._timestamps = [] self._values = [] - self._ts_spec = ts_spec + self._ts_format = _ts_format + self._ts_path_keys = self.to_keys(_ts_path) def __str__(self): return f"{self._ep_path}:{len(self._values)}: {self._values}" + def timestamps_str(self): + return f"{self._ep_path}:{len(self._timestamps)}: {self._timestamps}" + @property def path(self): - return self._base_path + return self._ep_path def assign(self, _record: dict): - value = self.deref_multi(_record, self._base_path_keys + self._ep_path_keys) + value = self.deref_multi(_record, self._ep_path_keys) self._values += [value] # Extract timestamp - capture_time = self.deref_multi(_record, self._base_path_keys)[self._ts_spec['name']] - timestamp_int = convert(capture_time, self._ts_spec['format']) + capture_time = self.deref_multi(_record, self._ts_path_keys) + timestamp_int = convert(capture_time, self._ts_format) self._timestamps += [timestamp_int] def remove_dups(self): @@ -65,10 +67,10 @@ class Endpoint: end_points = [ - Endpoint('measurements/odometerStatus/value', 'odometer'), - Endpoint('measurements/fuelLevelStatus/value', 'currentSOC_pct'), - Endpoint('vehicleLights/lightsStatus/value', 'lights'), - Endpoint('fuelStatus/rangeStatus/value', 'primaryEngine', ts_spec={'name': 'carCapturedTimestamp', 'format': '%Y-%m-%dT%H:%M:%SZ'}), + Endpoint('data/measurements/odometerStatus/value/odometer', 'info/timestamp'), + Endpoint('data/measurements/fuelLevelStatus/value/currentSOC_pct', 'info/timestamp'), + Endpoint('data/vehicleLights/lightsStatus/value/lights', 'info/timestamp'), + Endpoint('data/fuelStatus/rangeStatus/value/primaryEngine', 'info/timestamp') ] @@ -111,8 +113,6 @@ for day in day_list: with open(file_path, "r") as fp: records = json.load(fp) for record in records: - if "info" in record: - record = record['data'] try: for end_point in end_points: end_point.assign(record) @@ -122,5 +122,6 @@ for day in day_list: for end_point in end_points: end_point.remove_dups() print(end_point) + print(end_point.timestamps_str()) d = convert('2024-10-17T18:37:17.067Z')