diff --git a/components/control_center/src/app/component/landing/landing.component.html b/components/control_center/src/app/component/landing/landing.component.html
index f5a10eb..59ad539 100644
--- a/components/control_center/src/app/component/landing/landing.component.html
+++ b/components/control_center/src/app/component/landing/landing.component.html
@@ -1,8 +1,6 @@
-
-
- 0" id="map" #map [zoom]="zoom" [latitude]="center.lat" [longitude]="center.lng" style="height: 900px; width: 1200px">
-
-
+
+
+
+
diff --git a/components/control_center/src/app/component/landing/landing.component.ts b/components/control_center/src/app/component/landing/landing.component.ts
index 481018e..1fa38fa 100644
--- a/components/control_center/src/app/component/landing/landing.component.ts
+++ b/components/control_center/src/app/component/landing/landing.component.ts
@@ -1,7 +1,9 @@
import {Component, OnInit, ViewChild} from '@angular/core';
-import {AgmMap, AgmMarker} from '@agm/core';
+import {AgmMap} from '@agm/core';
import {RestService} from '../../services/rest.service';
import {NGXLogger} from 'ngx-logger';
+import {interval, Subscription} from 'rxjs';
+import {startWith, switchMap} from 'rxjs/operators';
@Component({
selector: 'app-landing',
@@ -22,72 +24,111 @@ export class LandingComponent implements OnInit {
zoom = 14;
center = {lat: 47.90620, lng: 16.20785};
- // Test Data
- markers = [
- {
- Id: 1,
- name: 'Car-1',
- lat: 47.89053,
- lng: 16.20703,
- visible: true,
- iconUrl: 'assets/pictures/car.png'
- },
- {
- Id: 2,
- name: 'Car-2',
- lat: 47.89853,
- lng: 16.20703,
- visible: true,
- iconUrl: 'assets/pictures/car.png'
- },
- ];
- traffic_light_markers = [];
+ traffic_light_markers = new Map();
+ car_markers = new Map();
+
+ timeInterval: Subscription;
+
+ TL_RED_IMAGE = 'assets/pictures/traffic_light_red.png';
+ TL_GREEN_IMAGE = 'assets/pictures/traffic_light_green.png';
+ CAR_IMAGE = 'assets/pictures/car.png';
ngOnInit() {
- let traffic_lights = [];
+ this.getTrafficLights();
+ this.getCars();
+ }
+
+ getCarEvents(vin) {
+ this.timeInterval = interval(1000)
+ .pipe(
+ startWith(0),
+ switchMap(() => this.restService.getCarEvents(vin))
+ ).subscribe((data: any) => {
+ const car = data.body['cursor'];
+ car['vin'] = car['vehicle_identification_number'];
+ //TODO: if (car['near_crash_event']) {
+ car['iconUrl'] = this.CAR_IMAGE;
+
+ car['lat'] = car['gps_location']['latitude'];
+ car['lng'] = car['gps_location']['longitude'];
+ this.car_markers.set(car['vin'], car);
+
+ },
+ err => this.logger.error(err),
+ () => {
+ this.logger.debug('loaded traffic light events');
+ }
+ );
+ }
+
+ getTrafficLightEvents(tlid) {
+
+ this.timeInterval = interval(1000)
+ .pipe(
+ startWith(0),
+ switchMap(() => this.restService.getTrafficLightEvents(tlid))
+ ).subscribe(
+ (data: any) => {
+ const traffic_light_event = data.body['cursor'];
+ const traffic_light = this.traffic_light_markers.get(traffic_light_event['tlid']);
+ traffic_light['color'] = traffic_light_event['color'];
+ traffic_light['last_switch'] = traffic_light_event['last_switch'];
+ traffic_light['iconUrl'] = this.trafficLightToImage(traffic_light['color']);
+
+ this.traffic_light_markers.set(traffic_light_event['tlid'], traffic_light);
+ },
+ err => this.logger.error(err),
+ () => {
+ this.logger.debug('loaded traffic light events');
+ }
+ );
+ }
+
+ getTrafficLights() {
this.restService.getTrafficLights().subscribe(
(data: any) => {
- traffic_lights = data;
- console.log(data['cursor']);
for (const traffic_light of data['cursor']) {
- traffic_light['iconUrl'] = 'assets/pictures/traffic_light_red.png';
+ traffic_light['iconUrl'] = this.trafficLightToImage(traffic_light['color']);
traffic_light['lat'] = traffic_light['location'][1];
traffic_light['lng'] = traffic_light['location'][0];
- console.log(traffic_light);
- this.traffic_light_markers.push(traffic_light);
+ this.traffic_light_markers.set(traffic_light['id'], traffic_light);
}
},
err => this.logger.error(err),
() => {
this.logger.debug('loaded traffic lights');
+ for (const value of this.traffic_light_markers.values()) {
+ this.getTrafficLightEvents(value['id']);
+ }
}
);
}
-
- getDelta(source, destination, steps) {
- return {
- lat: (destination.lat - source.lat) / steps,
- lng: (destination.lng - source.lng) / steps
- };
- }
-
- toggleMarker() {
- const delta = this.getDelta(this.markers[0], this.markers[1], 100);
-
- this.move(this.markers[0], delta, 0, 10, 100);
+ getCars() {
+ this.restService.getCars().subscribe(
+ (data: any) => {
+ for (const car of data['cursor']) {
+ car['iconUrl'] = 'assets/pictures/car.png';
+ this.car_markers.set(car['vin'], car);
+ }
+ },
+ err => this.logger.error(err),
+ () => {
+ this.logger.debug('loaded cars');
+ console.log(this.car_markers);
+ for (const value of this.car_markers.values()) {
+ this.getCarEvents(value['vin']);
+ }
+ }
+ );
}
- move(source, delta, counter, delay, steps) {
- source.lat += delta.lat;
- source.lng += delta.lng;
- if (counter !== steps) {
- counter++;
- setTimeout(this.move.bind(this), delay, source, delta, counter, delay, steps);
- }
+ private trafficLightToImage(trafficLight) {
+ return (trafficLight === 'RED') ? this.TL_RED_IMAGE : this.TL_GREEN_IMAGE;
}
+
}
diff --git a/components/control_center/src/app/services/rest.service.ts b/components/control_center/src/app/services/rest.service.ts
index 0a60896..1ea55ab 100644
--- a/components/control_center/src/app/services/rest.service.ts
+++ b/components/control_center/src/app/services/rest.service.ts
@@ -2,7 +2,6 @@ import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {NGXLogger} from 'ngx-logger';
import {environment} from '../../environments/environment';
-import {Observable} from 'rxjs';
@Injectable()
export class RestService {
@@ -14,7 +13,20 @@ export class RestService {
) {
}
+ getTrafficLightEvents(tlid) {
+ return this.http.get(this.currentLocation + 'traffic_light_events?id=' + tlid, {observe: 'response'});
+ }
+
+ getCarEvents(vin) {
+ return this.http.get(this.currentLocation + 'car_events?vin=' + vin, {observe: 'response'});
+ }
+
getTrafficLights() {
return this.http.get(this.currentLocation + 'traffic_lights');
}
+
+ getCars() {
+ return this.http.get(this.currentLocation + 'cars');
+ }
+
}
diff --git a/components/entitiy_ident/mongo/traffic_lights.json b/components/entitiy_ident/mongo/traffic_lights.json
index cf91b92..52c18cf 100644
--- a/components/entitiy_ident/mongo/traffic_lights.json
+++ b/components/entitiy_ident/mongo/traffic_lights.json
@@ -4,20 +4,20 @@
"location": [16.20719, 47.89584],
"range": 542,
"switchingTime": 15,
- "initialColor": "RED"
+ "color": "RED"
},
{
"id": "2",
"location": [16.20814, 47.90937],
"range": 725,
"switchingTime": 20,
- "initialColor": "GREEN"
+ "color": "GREEN"
},
{
"id": "3",
"location": [16.20917, 47.92703],
"range": 910,
"switchingTime": 25,
- "initialColor": "RED"
+ "color": "RED"
}
]
\ No newline at end of file
diff --git a/components/orchestration/orchestrator.py b/components/orchestration/orchestrator.py
index 8db0469..cfd64b7 100644
--- a/components/orchestration/orchestrator.py
+++ b/components/orchestration/orchestrator.py
@@ -52,7 +52,7 @@ class Orchestrator:
self.vins.append(car['vin'])
for traffic_light in traffic_lights['cursor']:
- self.tls[traffic_light['id']] = {'color': traffic_light['initialColor'],
+ self.tls[traffic_light['id']] = {'color': traffic_light['color'],
'switching_time': traffic_light['switchingTime'],
'last_switch': datetime.now()}
diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py
index 3c6954b..ee6582f 100644
--- a/components/x_way/x_way_server.py
+++ b/components/x_way/x_way_server.py
@@ -27,6 +27,21 @@ def get_cars_events():
return json_util.dumps({'cursor': cars})
+@app.route('/api/v1/resources/traffic_light_events', methods=['GET'])
+def get_traffic_light_events():
+ id = request.args.get('id')
+
+ 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
+
+ return json_util.dumps({'cursor': traffic_lights})
+
+
@app.route('/api/v1/resources/cars', methods=['GET'])
def get_cars():
try: