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