From 67b74e93c53555925719a2d317ff4c0870d9142c Mon Sep 17 00:00:00 2001 From: David Eder Date: Sun, 13 Jun 2021 16:21:23 +0200 Subject: [PATCH 1/5] Refactors control center for cars --- .../component/landing/landing.component.html | 24 ++++---- .../component/landing/landing.component.ts | 60 ++++++++++++------- .../src/app/interfaces/interface.ts | 22 +++++++ components/x_way/x_way_server.py | 4 +- 4 files changed, 75 insertions(+), 35 deletions(-) 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 7a44825..0d3266e 100644 --- a/components/control_center/src/app/component/landing/landing.component.html +++ b/components/control_center/src/app/component/landing/landing.component.html @@ -1,16 +1,16 @@ - - -

VIN: {{m.value.vin}}

-

OEM: {{m.value.oem}}

-

Model Type: {{m.value.modelType}}

-

Velocity: {{m.value.velocity}}

-

Timestamp: {{m.value.timestamp}}

-

NCE: {{m.value.near_crash_event}}

+ + +

VIN: {{m.value.carEntity.vin}}

+

OEM: {{m.value.carEntity.oem}}

+

Model Type: {{m.value.carEntity.modelType}}

+

Velocity: {{m.value.carEvent.velocity}}

+

Timestamp: {{m.value.carEvent.timestamp}}

+

NCE: {{m.value.carEvent.near_crash_event}}

this.restService.getCarEvents(vin)) ).subscribe((data: any) => { - const carEvent = data.body['cursor']; - const car = this.car_markers.get(vin); - car['velocity'] = carEvent['velocity']; - car['timestamp'] = carEvent['timestamp']; - car['near_crash_event'] = carEvent['near_crash_event']; - if (car['near_crash_event']) { - car['iconUrl'] = this.CAR_IMAGE_NCE; - this.playCrashSound(); - } else { - car['iconUrl'] = this.CAR_IMAGE; - } - car['lat'] = carEvent['gps_location']['latitude']; - car['lng'] = carEvent['gps_location']['longitude']; + const carEvent = data.body as CarEvent; + const car = this.car_markers.get(vin) as Car; + car.carEvent = carEvent; this.car_markers.set(car['vin'], car); }, err => this.logger.error(err), () => { - this.logger.debug('loaded traffic light events'); + this.logger.debug('loaded car events'); } ); } @@ -117,18 +107,22 @@ export class LandingComponent implements OnInit { 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); + (data: CarEntity[]) => { + for (const carEntity of data) { + + const car: Car = { + carEntity: carEntity, + carEvent: this.getEmptyCarEvent() + }; + car.carEntity = carEntity; + this.car_markers.set(carEntity['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']); + this.getCarEvents(value.carEntity['vin']); } } ); @@ -139,6 +133,15 @@ export class LandingComponent implements OnInit { return (trafficLight === 'RED') ? this.TL_RED_IMAGE : this.TL_GREEN_IMAGE; } + getIconUrlCar(near_crash_event) { + if (near_crash_event === true) { + this.playCrashSound(); + return this.CAR_IMAGE_NCE; + } else { + return this.CAR_IMAGE; + } + } + openInfoWindow(id) { this.infoWindows.set(id, true); } @@ -157,4 +160,19 @@ export class LandingComponent implements OnInit { audio.load(); audio.play(); } + + private getEmptyCarEvent() { + const geoCoordinates = { + latitude: 0, + longitude: 0 + }; + + const carEvent = { + near_crash_event: false, + gps_location: geoCoordinates, + timestamp: '' + }; + + return carEvent; + } } diff --git a/components/control_center/src/app/interfaces/interface.ts b/components/control_center/src/app/interfaces/interface.ts index 3332493..ffc761d 100644 --- a/components/control_center/src/app/interfaces/interface.ts +++ b/components/control_center/src/app/interfaces/interface.ts @@ -5,3 +5,25 @@ export interface WSEvents { error: Observable; close: Observable; } + +export interface GeoCoordinates { + latitude: Number; + longitude: Number; +} + +export interface CarEntity { + oem: String; + modelType: String; + vin: String; +} + +export interface CarEvent { + near_crash_event: Boolean; + gps_location: GeoCoordinates; + timestamp: String; +} + +export interface Car { + carEntity: CarEntity; + carEvent: CarEvent; +} diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py index ee6582f..847bf79 100644 --- a/components/x_way/x_way_server.py +++ b/components/x_way/x_way_server.py @@ -24,7 +24,7 @@ def get_cars_events(): print("Is the EVENT_STORE_URL running and reachable?") raise e - return json_util.dumps({'cursor': cars}) + return json_util.dumps(cars) @app.route('/api/v1/resources/traffic_light_events', methods=['GET']) @@ -52,7 +52,7 @@ def get_cars(): print("Is the entity_ident_server running and reachable?") raise e - return json_util.dumps({'cursor': cars}) + return json_util.dumps(cars) @app.route('/api/v1/resources/traffic_lights', methods=['GET']) From a31f330663ebc6a134186817032cd7a10b632cc8 Mon Sep 17 00:00:00 2001 From: David Eder Date: Sun, 13 Jun 2021 18:32:29 +0200 Subject: [PATCH 2/5] Refactors control center for traffic lights --- .../component/landing/landing.component.html | 17 +++--- .../component/landing/landing.component.ts | 57 +++++++++++-------- .../src/app/interfaces/interface.ts | 19 +++++++ components/x_way/x_way_server.py | 4 +- 4 files changed, 65 insertions(+), 32 deletions(-) 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 0d3266e..b82b0b2 100644 --- a/components/control_center/src/app/component/landing/landing.component.html +++ b/components/control_center/src/app/component/landing/landing.component.html @@ -1,4 +1,5 @@ + @@ -13,14 +14,16 @@

NCE: {{m.value.carEvent.near_crash_event}}

- + + -

Id: {{m.value.id}}

-

Switching Time: {{m.value.switchingTime}}

-

Range: {{m.value.range}}

-

Color: {{m.value.color}}

-

Last Switch: {{m.value.last_switch}}

+

Id: {{m.value.trafficLightEntity.id}}

+

Switching Time: {{m.value.trafficLightEntity.switchingTime}}

+

Range: {{m.value.trafficLightEntity.range}}

+

Color: {{m.value.trafficLightEvent.color}}

+

Last Switch: {{m.value.trafficLightEvent.last_switch}}

+
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 cd17973..b54abce 100644 --- a/components/control_center/src/app/component/landing/landing.component.ts +++ b/components/control_center/src/app/component/landing/landing.component.ts @@ -4,7 +4,13 @@ import {RestService} from '../../services/rest.service'; import {NGXLogger} from 'ngx-logger'; import {interval, Subscription} from 'rxjs'; import {startWith, switchMap} from 'rxjs/operators'; -import {Car, CarEntity, CarEvent, GeoCoordinates} from '../../interfaces/interface'; +import { + Car, + CarEntity, + CarEvent, + GeoCoordinates, TrafficLight, + TrafficLightEntity, TrafficLightEvent +} from '../../interfaces/interface'; @Component({ selector: 'app-landing', @@ -70,13 +76,10 @@ export class LandingComponent implements OnInit { 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); + const trafficLightEvent = data.body as TrafficLightEvent; + const trafficLight = this.traffic_light_markers.get(tlid) as TrafficLight; + trafficLight.trafficLightEvent = trafficLightEvent; + this.traffic_light_markers.set(tlid, trafficLight); }, err => this.logger.error(err), () => { @@ -87,19 +90,21 @@ export class LandingComponent implements OnInit { getTrafficLights() { this.restService.getTrafficLights().subscribe( - (data: any) => { - for (const traffic_light of data['cursor']) { - traffic_light['iconUrl'] = this.trafficLightToImage(traffic_light['color']); - traffic_light['lat'] = traffic_light['location'][1]; - traffic_light['lng'] = traffic_light['location'][0]; - this.traffic_light_markers.set(traffic_light['id'], traffic_light); + (data: TrafficLightEntity[]) => { + for (const trafficLightEntity of data) { + + const trafficLight: TrafficLight = { + trafficLightEntity: trafficLightEntity, + trafficLightEvent: this.getEmptyTrafficLightEvent() + }; + this.traffic_light_markers.set(trafficLightEntity['id'], trafficLight); } }, err => this.logger.error(err), () => { this.logger.debug('loaded traffic lights'); for (const value of this.traffic_light_markers.values()) { - this.getTrafficLightEvents(value['id']); + this.getTrafficLightEvents(value.trafficLightEntity['id']); } } ); @@ -109,12 +114,10 @@ export class LandingComponent implements OnInit { this.restService.getCars().subscribe( (data: CarEntity[]) => { for (const carEntity of data) { - const car: Car = { carEntity: carEntity, carEvent: this.getEmptyCarEvent() }; - car.carEntity = carEntity; this.car_markers.set(carEntity['vin'], car); } }, @@ -129,7 +132,7 @@ export class LandingComponent implements OnInit { } - private trafficLightToImage(trafficLight) { + trafficLightToImage(trafficLight) { return (trafficLight === 'RED') ? this.TL_RED_IMAGE : this.TL_GREEN_IMAGE; } @@ -161,18 +164,26 @@ export class LandingComponent implements OnInit { audio.play(); } - private getEmptyCarEvent() { - const geoCoordinates = { + private getEmptyGeoCoordinates(): GeoCoordinates { + return { latitude: 0, longitude: 0 }; + } - const carEvent = { + private getEmptyCarEvent(): CarEvent { + return { near_crash_event: false, - gps_location: geoCoordinates, + gps_location: this.getEmptyGeoCoordinates(), timestamp: '' }; + } - return carEvent; + private getEmptyTrafficLightEvent(): TrafficLightEvent { + return { + last_switch: 0, + color: '', + tlid: 0 + }; } } diff --git a/components/control_center/src/app/interfaces/interface.ts b/components/control_center/src/app/interfaces/interface.ts index ffc761d..c401a56 100644 --- a/components/control_center/src/app/interfaces/interface.ts +++ b/components/control_center/src/app/interfaces/interface.ts @@ -27,3 +27,22 @@ export interface Car { carEntity: CarEntity; carEvent: CarEvent; } + +export interface TrafficLightEntity { + id: Number; + location: Number[]; + range: Number; + switchingTime: Number; + color: String; +} + +export interface TrafficLightEvent { + last_switch: Number; + color: String; + tlid: Number; +} + +export interface TrafficLight { + trafficLightEntity: TrafficLightEntity; + trafficLightEvent: TrafficLightEvent; +} diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py index 847bf79..8a9bee1 100644 --- a/components/x_way/x_way_server.py +++ b/components/x_way/x_way_server.py @@ -39,7 +39,7 @@ def get_traffic_light_events(): print("Is the EVENT_STORE_URL running and reachable?") raise e - return json_util.dumps({'cursor': traffic_lights}) + return json_util.dumps(traffic_lights) @app.route('/api/v1/resources/cars', methods=['GET']) @@ -65,7 +65,7 @@ def get_traffic_lights(): print("Is the entity_ident_server running and reachable?") raise e - return json_util.dumps({'cursor': traffic_lights}) + return json_util.dumps(traffic_lights) if __name__ == '__main__': From 3c14cb5569b1aa3ea08c46937f9fda925937dc0d Mon Sep 17 00:00:00 2001 From: David Eder Date: Sun, 13 Jun 2021 18:48:45 +0200 Subject: [PATCH 3/5] Fix marker position --- .../src/app/component/landing/landing.component.html | 4 ++-- components/control_center/src/app/interfaces/interface.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) 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 b82b0b2..dd9f0bb 100644 --- a/components/control_center/src/app/component/landing/landing.component.html +++ b/components/control_center/src/app/component/landing/landing.component.html @@ -4,8 +4,8 @@ *ngFor="let m of car_markers | keyvalue" [iconUrl]="getIconUrlCar(m.value.carEvent.near_crash_event)" [latitude]="m.value.carEvent.gps_location.latitude" [longitude]="m.value.carEvent.gps_location.longitude" [animation]="(m.value.carEvent.near_crash_event)?'BOUNCE':''"> + [isOpen]="isInfoWindowOpen(m.value.carEntity.vin)" [latitude]="m.value.carEvent.gps_location.longitude" + [longitude]="m.value.carEvent.gps_location.latitude">

VIN: {{m.value.carEntity.vin}}

OEM: {{m.value.carEntity.oem}}

Model Type: {{m.value.carEntity.modelType}}

diff --git a/components/control_center/src/app/interfaces/interface.ts b/components/control_center/src/app/interfaces/interface.ts index c401a56..728e9bc 100644 --- a/components/control_center/src/app/interfaces/interface.ts +++ b/components/control_center/src/app/interfaces/interface.ts @@ -21,6 +21,7 @@ export interface CarEvent { near_crash_event: Boolean; gps_location: GeoCoordinates; timestamp: String; + velocity: Number; } export interface Car { From 2da3e9bf5280c3f438f8b389762355e366d5c653 Mon Sep 17 00:00:00 2001 From: David Eder Date: Sun, 13 Jun 2021 18:51:59 +0200 Subject: [PATCH 4/5] Fix empty car event type --- .../src/app/component/landing/landing.component.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 b54abce..1c67bb4 100644 --- a/components/control_center/src/app/component/landing/landing.component.ts +++ b/components/control_center/src/app/component/landing/landing.component.ts @@ -173,9 +173,10 @@ export class LandingComponent implements OnInit { private getEmptyCarEvent(): CarEvent { return { - near_crash_event: false, - gps_location: this.getEmptyGeoCoordinates(), - timestamp: '' + near_crash_event: false, + gps_location: this.getEmptyGeoCoordinates(), + timestamp: '', + velocity: 0 }; } From 9aa13bed7b038e391c1522902d0ef2b48936f83b Mon Sep 17 00:00:00 2001 From: David Eder Date: Sun, 13 Jun 2021 19:09:48 +0200 Subject: [PATCH 5/5] Fix lat long in control center --- .../src/app/component/landing/landing.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 dd9f0bb..9f8c68d 100644 --- a/components/control_center/src/app/component/landing/landing.component.html +++ b/components/control_center/src/app/component/landing/landing.component.html @@ -4,8 +4,8 @@ *ngFor="let m of car_markers | keyvalue" [iconUrl]="getIconUrlCar(m.value.carEvent.near_crash_event)" [latitude]="m.value.carEvent.gps_location.latitude" [longitude]="m.value.carEvent.gps_location.longitude" [animation]="(m.value.carEvent.near_crash_event)?'BOUNCE':''"> + [isOpen]="isInfoWindowOpen(m.value.carEntity.vin)" [latitude]="m.value.carEvent.gps_location.latitude" + [longitude]="m.value.carEvent.gps_location.longitude">

VIN: {{m.value.carEntity.vin}}

OEM: {{m.value.carEntity.oem}}

Model Type: {{m.value.carEntity.modelType}}