log dicts instead of object representations

This commit is contained in:
Marco Zeisler 2021-06-02 22:35:16 +02:00
parent 7e3445f6ed
commit c6e23189de
4 changed files with 23 additions and 1 deletions

View File

@ -53,7 +53,11 @@ class EventLogger:
else:
key = 'UNKNOWN'
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:

View File

@ -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()
}

View File

@ -5,3 +5,6 @@ from dataclasses import dataclass
class TargetVelocity:
vin: str
target_velocity: float
def to_dict(self):
return self.__dict__

View File

@ -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()}