From 81a41226a07bf250c2783819bb7255b021584e9e Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Thu, 17 Jun 2021 19:52:52 +0200 Subject: [PATCH] Implement correct scaling --- components/entitiy_ident/mongo/traffic_lights.json | 6 +++--- components/i_feed/devices/traffic_light.py | 2 +- components/i_feed/devices/vehicle.py | 5 +++-- components/orchestration/orchestrator.py | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/components/entitiy_ident/mongo/traffic_lights.json b/components/entitiy_ident/mongo/traffic_lights.json index 0fbe8e3..782e9d8 100644 --- a/components/entitiy_ident/mongo/traffic_lights.json +++ b/components/entitiy_ident/mongo/traffic_lights.json @@ -3,21 +3,21 @@ "id": "1", "location": [16.20719, 47.89584], "range": 2000, - "switchingTime": 5, + "switchingTime": 26, "color": "RED" }, { "id": "2", "location": [16.20814, 47.90937], "range": 800, - "switchingTime": 15, + "switchingTime": 16, "color": "GREEN" }, { "id": "3", "location": [16.20917, 47.92703], "range": 1000, - "switchingTime": 10, + "switchingTime": 20, "color": "RED" } ] \ No newline at end of file diff --git a/components/i_feed/devices/traffic_light.py b/components/i_feed/devices/traffic_light.py index 3b3c7e8..e8d55b1 100644 --- a/components/i_feed/devices/traffic_light.py +++ b/components/i_feed/devices/traffic_light.py @@ -13,7 +13,7 @@ from pika.exceptions import AMQPConnectionError SWITCHING_TIME = 15 # Scale speed of switching by factor x -SCALING = 1 +SCALING = 6 class TrafficLight: diff --git a/components/i_feed/devices/vehicle.py b/components/i_feed/devices/vehicle.py index d4b55d5..c34318e 100644 --- a/components/i_feed/devices/vehicle.py +++ b/components/i_feed/devices/vehicle.py @@ -19,7 +19,7 @@ STARTING_POINT = geopy.Point(47.89053, 16.20703) # Driving direction in degrees: 0=N, 90=E, 180=S, 270=W BEARING = 2 # Scale speed of vehicles by factor x -SCALING = 1 +SCALING = 6 # in km/h STARTING_VELOCITY = 130 * SCALING # Interval between status updates in seconds (is not scaled) @@ -170,7 +170,7 @@ class Vehicle: driving_time = (updated_timestamp - old_timestamp).total_seconds() # reached distance in kilometers: convert km/h to km/s and multiply by driving time - kilometers = self.velocity / 3600 * driving_time * SCALING + kilometers = self.velocity / 3600 * driving_time # Define a general distance object, initialized with a distance of k km. d = geopy.distance.distance(kilometers=kilometers) @@ -231,6 +231,7 @@ class Vehicle: self._driven_kms = 0 self.last_update = datetime.now() self.nce = False + self.velocity = STARTING_VELOCITY @circuit(failure_threshold=10, expected_exception=AMQPConnectionError) def send_status_update(self): diff --git a/components/orchestration/orchestrator.py b/components/orchestration/orchestrator.py index 5277a01..b358d71 100644 --- a/components/orchestration/orchestrator.py +++ b/components/orchestration/orchestrator.py @@ -3,7 +3,7 @@ import pickle import sys from typing import List, Dict from datetime import datetime, timedelta -from math import floor, ceil +from math import floor import requests from dse_shared_libs import daf, traffic_light_state, traffic_light_color, target_velocity @@ -22,7 +22,7 @@ sys.modules['target_velocity'] = target_velocity ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' -SCALING = 1 +SCALING = 6 class Orchestrator: @@ -109,7 +109,7 @@ class Orchestrator: switching_time = self.tls[tl_id]['switching_time'] / float(SCALING) # Time until next switch must be scaled accordingly next_switch_time = self.tls[tl_id]['last_switch'] + timedelta(seconds=switching_time) - time_until_switch = (next_switch_time - datetime.now()).total_seconds() + time_until_switch = (next_switch_time - datetime.utcnow()).total_seconds() print('Distance to TL: {}'.format(distance)) print('Time until switch in seconds: {}'.format(time_until_switch)) if self.tls[tl_id]['color'] is TrafficLightColor.RED: