use shared libs;

added event store which intercepts the message broker wrapper if exchange name is not logger
This commit is contained in:
Marco Zeisler
2021-05-27 19:38:49 +02:00
parent 4e1666ec5a
commit dc89332bd5
5 changed files with 61 additions and 31 deletions
+14 -16
View File
@@ -6,11 +6,12 @@ from datetime import datetime
from circuitbreaker import circuit
# Default switching time in seconds
from shared import TrafficLightColor
from shared.TrafficLightColor import TrafficLightColor
from shared import traffic_light_color
from shared.traffic_light_color import TrafficLightColor
from shared.message_broker_wrapper import MBWrapper
from shared.traffic_light_state import TrafficLightState
SWITCHING_TIME = 120
SWITCHING_TIME = 500
# Scale speed of switching by factor x
SCALING = 100
@@ -68,23 +69,20 @@ class TrafficLight:
@circuit(failure_threshold=10, expected_exception=ConnectionError)
def send_status_update(self):
print(self.tlid, self.current_color, self.last_switch)
self._tl_mb.send(pickle.dumps({
'tlid': self.tlid,
'color': self.current_color,
'last_switch': self.last_switch
}))
self._tl_mb.send(pickle.dumps(
TrafficLightState(tlid=self.tlid, color=self.current_color, last_switch=self.last_switch)))
if __name__ == '__main__':
# TODO fetch and use data from Entity Ident
tl1 = TrafficLight(tlid='traffic-light-1', switching_time=120)
tl1 = TrafficLight(tlid='traffic-light-1', switching_time=SWITCHING_TIME)
tl1.start()
time.sleep(1)
tl2 = TrafficLight(tlid='traffic-light-2', switching_time=240)
tl2.start()
time.sleep(1)
tl3 = TrafficLight(tlid='traffic-light-3', switching_time=360)
tl3.start()
# time.sleep(1)
# tl2 = TrafficLight(tlid='traffic-light-2', switching_time=240)
# tl2.start()
#
# time.sleep(1)
# tl3 = TrafficLight(tlid='traffic-light-3', switching_time=360)
# tl3.start()
+13 -10
View File
@@ -12,6 +12,8 @@ from shared.daf import DAF
from shared.message_broker_wrapper import MBWrapper
# Lat, Long
from shared.target_velocity import TargetVelocity
STARTING_POINT = geopy.Point(48.853, 2.349)
# in km/h
STARTING_VELOCITY = 130
@@ -24,7 +26,7 @@ UPDATE_INTERVAL = 2
# At x km the NCE shall happen
NCE_KM = 30
# Time in seconds to recover from NCE (will be scaled)
TIME_TO_RECOVER = 100
TIME_TO_RECOVER = 500
# Resets vehicle at km x
RESET_KM = 50
@@ -205,8 +207,9 @@ class Vehicle:
print(self.driven_kms, '\t', self.daf)
self._daf_mb.send(pickle.dumps(self.daf))
def new_velocity(self, velocity: bytes):
velocity = float(velocity)
def new_velocity(self, response: bytes):
response: TargetVelocity = pickle.loads(response)
velocity = response.target_velocity
print('Received new velocity {}'.format(velocity))
self.velocity = velocity
@@ -217,10 +220,10 @@ if __name__ == "__main__":
v1 = Vehicle(vin='SB164ABN1PE082000')
v1.start_driving()
time.sleep(1)
v2 = Vehicle(vin='SB999ABN1PE082111')
v2.start_driving()
time.sleep(0.5)
v3 = Vehicle(vin='SB555ABN1PE082555')
v3.start_driving()
# time.sleep(1)
# v2 = Vehicle(vin='SB999ABN1PE082111')
# v2.start_driving()
#
# time.sleep(0.5)
# v3 = Vehicle(vin='SB555ABN1PE082555')
# v3.start_driving()