diff --git a/components/control_center/src/app/services/rest.service.ts b/components/control_center/src/app/services/rest.service.ts index af42907..54033d2 100644 --- a/components/control_center/src/app/services/rest.service.ts +++ b/components/control_center/src/app/services/rest.service.ts @@ -18,7 +18,7 @@ export class RestService { } getCarEvents(vin) { - return this.http.get(this.currentLocation + 'car_events/?vin=' + vin, {observe: 'response'}); + return this.http.get(this.currentLocation + 'car_events?vin=' + vin, {observe: 'response'}); } getTrafficLights() { 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 710379c..e6f2282 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 3b11fd7..e36b9a5 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: @@ -110,7 +110,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)) diff --git a/components/x_way/requirements.txt b/components/x_way/requirements.txt index ec961a5..b09968e 100644 --- a/components/x_way/requirements.txt +++ b/components/x_way/requirements.txt @@ -1,4 +1,4 @@ -flask +flask==1.1.4 Flask-Cors requests Flask-PyMongo diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py index 794754f..007db8c 100644 --- a/components/x_way/x_way_server.py +++ b/components/x_way/x_way_server.py @@ -5,27 +5,26 @@ from bson import json_util from flask import Flask, jsonify from flask_cors import CORS from flask import request -import json; +import json app = Flask(__name__) CORS(app) -api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1/resources") +api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1") API = flask_restx.Api(api_bp) app.register_blueprint(api_bp) - -NAMESPACE = API.namespace("car_events") - +NAMESPACE = API.namespace("resources") ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' EVENT_STORE_URL = 'http://eventstore:5001/api/keys/' -@NAMESPACE.route('/') +@NAMESPACE.route('/car_events', doc={'description': 'Get most current car event for specific car'}) class CarsEvents(flask_restx.Resource): @NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car', - 'type': 'String', 'default': '5GZCZ43D13S812715'}}) + 'type': 'String', 'default': '5GZCZ43D13S812715'}}) + @NAMESPACE.response(200, 'Success') def get(self): vin = request.args.get('vin') @@ -40,45 +39,57 @@ class CarsEvents(flask_restx.Resource): return jsonify(cars) -@app.route('/api/v1/resources/traffic_light_events', methods=['GET']) -def get_traffic_light_events(): - id = request.args.get('id') +@NAMESPACE.route('/traffic_light_events', doc={'description': 'Get most current traffic light event' + 'for specific traffic light'}) +class TrafficLightEvents(flask_restx.Resource): + @NAMESPACE.doc(params={'id': {'description': 'Unique ID of traffic light', + 'type': 'int', 'default': '1'}}) + @NAMESPACE.response(200, 'Success') + def get(self): + id = request.args.get('id') - try: - response = requests.get(EVENT_STORE_URL + 'TL:' + id + '/0/') - traffic_lights = json.loads(response.text) + try: + response = requests.get(EVENT_STORE_URL + 'TL:' + id + '/0/') + traffic_lights = json.loads(response.text) - except requests.exceptions.ConnectionError as e: - print("Is the EVENT_STORE_URL running and reachable?") - raise e + except requests.exceptions.ConnectionError as e: + print("Is the EVENT_STORE_URL running and reachable?") + raise e - return json_util.dumps(traffic_lights) + return jsonify(traffic_lights) -@app.route('/api/v1/resources/cars', methods=['GET']) -def get_cars(): - try: - response = requests.get(ENTITY_IDENT_URL + 'cars') - cars = response.json()['cursor'] +@NAMESPACE.route('/cars', doc={'description': 'Get entity details for all cars'}) +class Car(flask_restx.Resource): + @NAMESPACE.response(200, 'Success') + def get(self): - except requests.exceptions.ConnectionError as e: - print("Is the entity_ident_server running and reachable?") - raise e + try: + response = requests.get(ENTITY_IDENT_URL + 'cars') + cars = response.json()['cursor'] - return json_util.dumps(cars) + except requests.exceptions.ConnectionError as e: + print("Is the entity_ident_server running and reachable?") + raise e + + return jsonify(cars) -@app.route('/api/v1/resources/traffic_lights', methods=['GET']) -def get_traffic_lights(): - try: - response = requests.get(ENTITY_IDENT_URL + 'traffic_lights') - traffic_lights = response.json()['cursor'] +@NAMESPACE.route('/traffic_lights', doc={'description': 'Get entity details for all traffic lights'}) +class TrafficLights(flask_restx.Resource): - except requests.exceptions.ConnectionError as e: - print("Is the entity_ident_server running and reachable?") - raise e + @NAMESPACE.response(200, 'Success') + def get(self): - return json_util.dumps(traffic_lights) + try: + response = requests.get(ENTITY_IDENT_URL + 'traffic_lights') + traffic_lights = response.json()['cursor'] + + except requests.exceptions.ConnectionError as e: + print("Is the entity_ident_server running and reachable?") + raise e + + return jsonify(traffic_lights) if __name__ == '__main__':