From 16c715c774dbbc1190c4c00a656e25b36d7ed5ad Mon Sep 17 00:00:00 2001 From: Marco Zeisler Date: Sat, 15 May 2021 16:41:32 +0200 Subject: [PATCH] added check for NCE --- components/i_feed/vehicle.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/i_feed/vehicle.py b/components/i_feed/vehicle.py index 2cc64ce..3a70f87 100644 --- a/components/i_feed/vehicle.py +++ b/components/i_feed/vehicle.py @@ -15,6 +15,8 @@ STARTING_VELOCITY = 130 BEARING = 90 # Scale speed of vehicles by factor x SCALING = 1 +# At x km the NCE shall happen +NCE_KM = 0.1 class Vehicle: @@ -23,6 +25,7 @@ class Vehicle: timestamp: Union[datetime, None] _driven_kms: int _gps_location: geopy.Point + _nce_happened = False def __init__(self, vin: str, @@ -32,12 +35,23 @@ class Vehicle: self._gps_location = starting_point self.velocity = starting_velocity - def daf(self, invoke_nce=False): + @property + def nce(self): + nce = self._nce_happened + if nce: + if NCE_KM >= self._driven_kms: + nce = True + self._nce_happened = nce + self.velocity = 0 + return nce + + @property + def daf(self): return DAF(vehicle_identification_number=self.vin, gps_location=self.gps_location, velocity=self.velocity, timestamp=self.timestamp, - near_crash_event=invoke_nce + near_crash_event=self.nce ) @property