diff --git a/components/event_store/service/event_logger.py b/components/event_store/service/event_logger.py index 456d9af..5be2671 100644 --- a/components/event_store/service/event_logger.py +++ b/components/event_store/service/event_logger.py @@ -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, "{}
".format(to_log)) if self.verbose: diff --git a/components/shared/dse_shared_libs/daf.py b/components/shared/dse_shared_libs/daf.py index 2c43a2b..3c388fc 100644 --- a/components/shared/dse_shared_libs/daf.py +++ b/components/shared/dse_shared_libs/daf.py @@ -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() + } diff --git a/components/shared/dse_shared_libs/target_velocity.py b/components/shared/dse_shared_libs/target_velocity.py index c3c8e5e..8936573 100644 --- a/components/shared/dse_shared_libs/target_velocity.py +++ b/components/shared/dse_shared_libs/target_velocity.py @@ -5,3 +5,6 @@ from dataclasses import dataclass class TargetVelocity: vin: str target_velocity: float + + def to_dict(self): + return self.__dict__ diff --git a/components/shared/dse_shared_libs/traffic_light_state.py b/components/shared/dse_shared_libs/traffic_light_state.py index c1422b3..906ce54 100644 --- a/components/shared/dse_shared_libs/traffic_light_state.py +++ b/components/shared/dse_shared_libs/traffic_light_state.py @@ -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()}