Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ba967983a4
@ -18,7 +18,7 @@ export class RestService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCarEvents(vin) {
|
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() {
|
getTrafficLights() {
|
||||||
|
|||||||
@ -3,21 +3,21 @@
|
|||||||
"id": "1",
|
"id": "1",
|
||||||
"location": [16.20719, 47.89584],
|
"location": [16.20719, 47.89584],
|
||||||
"range": 2000,
|
"range": 2000,
|
||||||
"switchingTime": 5,
|
"switchingTime": 26,
|
||||||
"color": "RED"
|
"color": "RED"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "2",
|
"id": "2",
|
||||||
"location": [16.20814, 47.90937],
|
"location": [16.20814, 47.90937],
|
||||||
"range": 800,
|
"range": 800,
|
||||||
"switchingTime": 15,
|
"switchingTime": 16,
|
||||||
"color": "GREEN"
|
"color": "GREEN"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "3",
|
"id": "3",
|
||||||
"location": [16.20917, 47.92703],
|
"location": [16.20917, 47.92703],
|
||||||
"range": 1000,
|
"range": 1000,
|
||||||
"switchingTime": 10,
|
"switchingTime": 20,
|
||||||
"color": "RED"
|
"color": "RED"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -13,7 +13,7 @@ from pika.exceptions import AMQPConnectionError
|
|||||||
|
|
||||||
SWITCHING_TIME = 15
|
SWITCHING_TIME = 15
|
||||||
# Scale speed of switching by factor x
|
# Scale speed of switching by factor x
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
|
|
||||||
|
|
||||||
class TrafficLight:
|
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
|
# Driving direction in degrees: 0=N, 90=E, 180=S, 270=W
|
||||||
BEARING = 2
|
BEARING = 2
|
||||||
# Scale speed of vehicles by factor x
|
# Scale speed of vehicles by factor x
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
# in km/h
|
# in km/h
|
||||||
STARTING_VELOCITY = 130 * SCALING
|
STARTING_VELOCITY = 130 * SCALING
|
||||||
# Interval between status updates in seconds (is not scaled)
|
# Interval between status updates in seconds (is not scaled)
|
||||||
@ -170,7 +170,7 @@ class Vehicle:
|
|||||||
driving_time = (updated_timestamp - old_timestamp).total_seconds()
|
driving_time = (updated_timestamp - old_timestamp).total_seconds()
|
||||||
|
|
||||||
# reached distance in kilometers: convert km/h to km/s and multiply by driving time
|
# 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.
|
# Define a general distance object, initialized with a distance of k km.
|
||||||
d = geopy.distance.distance(kilometers=kilometers)
|
d = geopy.distance.distance(kilometers=kilometers)
|
||||||
@ -231,6 +231,7 @@ class Vehicle:
|
|||||||
self._driven_kms = 0
|
self._driven_kms = 0
|
||||||
self.last_update = datetime.now()
|
self.last_update = datetime.now()
|
||||||
self.nce = False
|
self.nce = False
|
||||||
|
self.velocity = STARTING_VELOCITY
|
||||||
|
|
||||||
@circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
|
@circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
|
||||||
def send_status_update(self):
|
def send_status_update(self):
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import pickle
|
|||||||
import sys
|
import sys
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from math import floor, ceil
|
from math import floor
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from dse_shared_libs import daf, traffic_light_state, traffic_light_color, target_velocity
|
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/'
|
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
||||||
|
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
|
|
||||||
|
|
||||||
class Orchestrator:
|
class Orchestrator:
|
||||||
@ -110,7 +110,7 @@ class Orchestrator:
|
|||||||
switching_time = self.tls[tl_id]['switching_time'] / float(SCALING)
|
switching_time = self.tls[tl_id]['switching_time'] / float(SCALING)
|
||||||
# Time until next switch must be scaled accordingly
|
# Time until next switch must be scaled accordingly
|
||||||
next_switch_time = self.tls[tl_id]['last_switch'] + timedelta(seconds=switching_time)
|
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('Distance to TL: {}'.format(distance))
|
||||||
print('Time until switch in seconds: {}'.format(time_until_switch))
|
print('Time until switch in seconds: {}'.format(time_until_switch))
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
flask
|
flask==1.1.4
|
||||||
Flask-Cors
|
Flask-Cors
|
||||||
requests
|
requests
|
||||||
Flask-PyMongo
|
Flask-PyMongo
|
||||||
|
|||||||
@ -5,27 +5,26 @@ from bson import json_util
|
|||||||
from flask import Flask, jsonify
|
from flask import Flask, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from flask import request
|
from flask import request
|
||||||
import json;
|
import json
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
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)
|
API = flask_restx.Api(api_bp)
|
||||||
app.register_blueprint(api_bp)
|
app.register_blueprint(api_bp)
|
||||||
|
|
||||||
|
NAMESPACE = API.namespace("resources")
|
||||||
NAMESPACE = API.namespace("car_events")
|
|
||||||
|
|
||||||
|
|
||||||
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
||||||
EVENT_STORE_URL = 'http://eventstore:5001/api/keys/'
|
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):
|
class CarsEvents(flask_restx.Resource):
|
||||||
@NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car',
|
@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):
|
def get(self):
|
||||||
vin = request.args.get('vin')
|
vin = request.args.get('vin')
|
||||||
|
|
||||||
@ -40,45 +39,57 @@ class CarsEvents(flask_restx.Resource):
|
|||||||
return jsonify(cars)
|
return jsonify(cars)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1/resources/traffic_light_events', methods=['GET'])
|
@NAMESPACE.route('/traffic_light_events', doc={'description': 'Get most current traffic light event'
|
||||||
def get_traffic_light_events():
|
'for specific traffic light'})
|
||||||
id = request.args.get('id')
|
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:
|
try:
|
||||||
response = requests.get(EVENT_STORE_URL + 'TL:' + id + '/0/')
|
response = requests.get(EVENT_STORE_URL + 'TL:' + id + '/0/')
|
||||||
traffic_lights = json.loads(response.text)
|
traffic_lights = json.loads(response.text)
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
print("Is the EVENT_STORE_URL running and reachable?")
|
print("Is the EVENT_STORE_URL running and reachable?")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
return json_util.dumps(traffic_lights)
|
return jsonify(traffic_lights)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1/resources/cars', methods=['GET'])
|
@NAMESPACE.route('/cars', doc={'description': 'Get entity details for all cars'})
|
||||||
def get_cars():
|
class Car(flask_restx.Resource):
|
||||||
try:
|
@NAMESPACE.response(200, 'Success')
|
||||||
response = requests.get(ENTITY_IDENT_URL + 'cars')
|
def get(self):
|
||||||
cars = response.json()['cursor']
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
try:
|
||||||
print("Is the entity_ident_server running and reachable?")
|
response = requests.get(ENTITY_IDENT_URL + 'cars')
|
||||||
raise e
|
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'])
|
@NAMESPACE.route('/traffic_lights', doc={'description': 'Get entity details for all traffic lights'})
|
||||||
def get_traffic_lights():
|
class TrafficLights(flask_restx.Resource):
|
||||||
try:
|
|
||||||
response = requests.get(ENTITY_IDENT_URL + 'traffic_lights')
|
|
||||||
traffic_lights = response.json()['cursor']
|
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
@NAMESPACE.response(200, 'Success')
|
||||||
print("Is the entity_ident_server running and reachable?")
|
def get(self):
|
||||||
raise e
|
|
||||||
|
|
||||||
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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user