Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ba967983a4
@ -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() {
|
||||
|
||||
@ -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"
|
||||
}
|
||||
]
|
||||
@ -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:
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
flask
|
||||
flask==1.1.4
|
||||
Flask-Cors
|
||||
requests
|
||||
Flask-PyMongo
|
||||
|
||||
@ -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__':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user