def pick_message(self, new_car, old_car, new_ambu, old_ambu): '''Checks if the current data is relevant, and returns a integer for each case Keyword arguments: new_car -- A tuple containing the cars current position old_car -- A tuple containing the cars previous position new_ambu -- A tuple containing the ambulance current position old_ambu -- A tuple containing the ambulance previous position returns 0 if the situation is not relevant 1 if the ambulance is less than 20 sec behind 2 if the ambulance is less than 2 minutes behind 3 if the ambulance just passed the car and is less than 50 meters ahead ''' new_car_pos = (new_car['latitude'], new_car['longitude']) new_car_time = new_car['timestamp'] old_car_pos = (old_car['latitude'], old_car['longitude']) old_car_time = old_car['timestamp'] car_speed = Calculator.speed(new_car_pos[1], new_car_pos[0], old_car_pos[1], old_car_pos[0], (new_car_time - old_car_time)) print("Car time" + str(new_car_time-old_car_time)) print("Car speed: " + str(car_speed)) new_ambu_pos = (new_ambu['latitude'], new_ambu['longitude']) new_ambu_time = new_car['timestamp'] old_ambu_pos = (old_ambu['latitude'], old_ambu['longitude']) old_ambu_time = old_car['timestamp'] ambu_speed = Calculator.speed(new_ambu_pos[1], new_ambu_pos[0], old_ambu_pos[1], old_ambu_pos[0], (new_ambu_time - old_ambu_time )) print("Ambu speed: " + str(ambu_speed)) car_dir = self._find_direction(new_car_pos, old_car_pos) ambu_dir = self._find_direction(new_ambu_pos, old_ambu_pos) distance_km = Calculator.gps_to_kmeters(new_car_pos[1], new_car_pos[0], new_ambu_pos[1], new_ambu_pos[0]) print("Distance is : " + str(distance_km )) if not self._is_relevant(new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): #0.05km is 50 meters. if distance_km < 0.05\ and car_dir.name == ambu_dir.name: if not self.meter_message: self.meter_message = True self.minute_warning = False self.second_warning = False return 3 else: return 0 return 0 time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print ('The vehicles are: ' + str(distance_km) + ' kms Appart. Time to intersect: ' + str(time_to_intersection)) #time to intersection is less than 20 sec, 1/3 of a minute if time_to_intersection <= (1/3): if not self.second_warning: self.second_warning = True return 1 return 0 if time_to_intersection <= 2: if not self.minute_warning: self.minute_warning = True self.meter_message = False return 2 return 0
def pick_message(self, new_car, old_car, new_ambu, old_ambu): '''Checks if the current data is relevant, and returns a integer for each case Keyword arguments: new_car -- A tuple containing the cars current position old_car -- A tuple containing the cars previous position new_ambu -- A tuple containing the ambulance current position old_ambu -- A tuple containing the ambulance previous position returns 0 if the situation is not relevant 1 if the ambulance is less than 20 sec behind 2 if the ambulance is less than 2 minutes behind 3 if the ambulance just passed the car and is less than 50 meters ahead ''' new_car_pos = (new_car['latitude'], new_car['longitude']) new_car_time = new_car['timestamp'] old_car_pos = (old_car['latitude'], old_car['longitude']) old_car_time = old_car['timestamp'] car_speed = Calculator.speed(new_car_pos[1], new_car_pos[0], old_car_pos[1], old_car_pos[0], (new_car_time - old_car_time)) print("Car time" + str(new_car_time - old_car_time)) print("Car speed: " + str(car_speed)) new_ambu_pos = (new_ambu['latitude'], new_ambu['longitude']) new_ambu_time = new_car['timestamp'] old_ambu_pos = (old_ambu['latitude'], old_ambu['longitude']) old_ambu_time = old_car['timestamp'] ambu_speed = Calculator.speed(new_ambu_pos[1], new_ambu_pos[0], old_ambu_pos[1], old_ambu_pos[0], (new_ambu_time - old_ambu_time)) print("Ambu speed: " + str(ambu_speed)) car_dir = self._find_direction(new_car_pos, old_car_pos) ambu_dir = self._find_direction(new_ambu_pos, old_ambu_pos) distance_km = Calculator.gps_to_kmeters(new_car_pos[1], new_car_pos[0], new_ambu_pos[1], new_ambu_pos[0]) print("Distance is : " + str(distance_km)) if not self._is_relevant(new_car_pos, car_speed, old_car_pos, new_ambu_pos, ambu_speed, old_ambu_pos): #0.05km is 50 meters. if distance_km < 0.05\ and car_dir.name == ambu_dir.name: if not self.meter_message: self.meter_message = True self.minute_warning = False self.second_warning = False return 3 else: return 0 return 0 time_to_intersection = Calculator.time_to_intersection( distance_km, ambu_speed, car_speed) print('The vehicles are: ' + str(distance_km) + ' kms Appart. Time to intersect: ' + str(time_to_intersection)) #time to intersection is less than 20 sec, 1/3 of a minute if time_to_intersection <= (1 / 3): if not self.second_warning: self.second_warning = True return 1 return 0 if time_to_intersection <= 2: if not self.minute_warning: self.minute_warning = True self.meter_message = False return 2 return 0