def is_car_direct_path_test(): assert not is_car_direct_path(get_walking_journey()) assert not is_car_direct_path(get_walking_car_journey()) assert not is_car_direct_path(get_car_walking_journey()) assert is_car_direct_path(get_car_journey()) assert not is_car_direct_path(get_bike_car_journey()) assert not is_car_direct_path(get_bss_car_journey())
def compute_car_co2_emission(pb_resp, api_request, instance): if not pb_resp.journeys: return car = next((j for j in pb_resp.journeys if helpers.is_car_direct_path(j)), None) if car is None or not car.HasField('co2_emission'): # if there is no car journey found, we request kraken to give us an estimation of # co2 emission co2_estimation = instance.georef.get_car_co2_emission_on_crow_fly(api_request['origin'], api_request['destination']) if co2_estimation: # Assign car_co2_emission into the resp, these value will be exposed in the final result pb_resp.car_co2_emission.value = co2_estimation.value pb_resp.car_co2_emission.unit = co2_estimation.unit else: # Assign car_co2_emission into the resp, these value will be exposed in the final result pb_resp.car_co2_emission.value = car.co2_emission.value pb_resp.car_co2_emission.unit = car.co2_emission.unit