log dicts instead of object representations
This commit is contained in:
parent
7e3445f6ed
commit
c6e23189de
@ -53,7 +53,11 @@ class EventLogger:
|
||||
else:
|
||||
key = 'UNKNOWN'
|
||||
|
||||
to_log = str(msg)
|
||||
try:
|
||||
to_log = json.dumps(msg.to_dict())
|
||||
except AttributeError:
|
||||
to_log = str(msg)
|
||||
|
||||
if self.log_to_redis:
|
||||
self.redis.append(key, "{}<br>".format(to_log))
|
||||
if self.verbose:
|
||||
|
||||
@ -14,3 +14,13 @@ class DAF:
|
||||
velocity: float
|
||||
near_crash_event: bool
|
||||
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:
|
||||
vin: str
|
||||
target_velocity: float
|
||||
|
||||
def to_dict(self):
|
||||
return self.__dict__
|
||||
|
||||
@ -9,3 +9,8 @@ class TrafficLightState:
|
||||
tlid: str
|
||||
color: TrafficLightColor
|
||||
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