log dicts instead of object representations
This commit is contained in:
parent
7e3445f6ed
commit
c6e23189de
@ -53,7 +53,11 @@ class EventLogger:
|
|||||||
else:
|
else:
|
||||||
key = 'UNKNOWN'
|
key = 'UNKNOWN'
|
||||||
|
|
||||||
|
try:
|
||||||
|
to_log = json.dumps(msg.to_dict())
|
||||||
|
except AttributeError:
|
||||||
to_log = str(msg)
|
to_log = str(msg)
|
||||||
|
|
||||||
if self.log_to_redis:
|
if self.log_to_redis:
|
||||||
self.redis.append(key, "{}<br>".format(to_log))
|
self.redis.append(key, "{}<br>".format(to_log))
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
|
|||||||
@ -14,3 +14,13 @@ class DAF:
|
|||||||
velocity: float
|
velocity: float
|
||||||
near_crash_event: bool
|
near_crash_event: bool
|
||||||
timestamp: datetime
|
timestamp: datetime
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {'vehicle_identification_number': self.vehicle_identification_number,
|
||||||
|
'gps_location': {'latitude': self.gps_location.latitude,
|
||||||
|
'longitude': self.gps_location.longitude
|
||||||
|
},
|
||||||
|
'velocity': self.velocity,
|
||||||
|
'near_crash_event': self.near_crash_event,
|
||||||
|
'timestamp': self.timestamp.timestamp()
|
||||||
|
}
|
||||||
|
|||||||
@ -5,3 +5,6 @@ from dataclasses import dataclass
|
|||||||
class TargetVelocity:
|
class TargetVelocity:
|
||||||
vin: str
|
vin: str
|
||||||
target_velocity: float
|
target_velocity: float
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return self.__dict__
|
||||||
|
|||||||
@ -9,3 +9,8 @@ class TrafficLightState:
|
|||||||
tlid: str
|
tlid: str
|
||||||
color: TrafficLightColor
|
color: TrafficLightColor
|
||||||
last_switch: datetime
|
last_switch: datetime
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {'tlid': self.tlid,
|
||||||
|
'color': self.color.name,
|
||||||
|
'last_switch': self.last_switch.timestamp()}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user