Example #1
0
    def __call__(self, j1, j2):

        j1_dt = datetime.utcfromtimestamp(j1.departure_date_time)
        j2_dt = datetime.utcfromtimestamp(j2.departure_date_time)
        j1_date = pytz.utc.localize(j1_dt).astimezone(
            pytz.timezone(self.timezone)).date()
        j2_date = pytz.utc.localize(j2_dt).astimezone(
            pytz.timezone(self.timezone)).date()

        # we first sort by date, we want the journey of the first day in first even if it's a non_pt
        if j1_date != j2_date:
            if j1_date < j2_date:
                return -1
            else:
                return 1

        # first we want the pure tc journey
        if is_pure_tc(j1) and is_pure_tc(j2):
            return self.sort_by_time(j1, j2)
        elif is_pure_tc(j1):
            return -1
        elif is_pure_tc(j2):
            return 1

        # after that we want the non pt bss
        if is_non_pt_bss(j1) and is_non_pt_bss(j2):
            return self.sort_by_time(j1, j2)
        elif is_non_pt_bss(j1):
            return -1
        elif is_non_pt_bss(j2):
            return 1

        # then the TC with bss fallback
        if has_bss_and_tc(j1) and has_bss_and_tc(j2):
            return self.sort_by_time(j1, j2)
        elif has_bss_and_tc(j1):
            return -1
        elif has_bss_and_tc(j2):
            return 1

        # then the TC with bike fallback
        if has_bike_and_tc(j1) and has_bike_and_tc(j2):
            return self.sort_by_time(j1, j2)
        elif has_bike_and_tc(j1):
            return -1
        elif has_bike_and_tc(j2):
            return 1

        # if there is any, the car fallback with TC
        if has_car_and_tc(j1) and has_car_and_tc(j2):
            return self.sort_by_time(j1, j2)
        elif has_car_and_tc(j1):
            return -1
        elif has_car_and_tc(j2):
            return 1

        # the walking only trip
        if is_non_pt_walk(j1) and is_non_pt_walk(j2):
            return self.sort_by_time(j1, j2)
        elif is_non_pt_walk(j1):
            return -1
        elif is_non_pt_walk(j2):
            return 1

        # the bike only trip
        if is_non_pt_bike(j1) and is_non_pt_bike(j2):
            return self.sort_by_time(j1, j2)
        elif is_non_pt_bike(j1):
            return -1
        elif is_non_pt_bike(j2):
            return 1

        return 0
Example #2
0
def is_alternative(journey):
    return is_non_pt_bike(journey) or is_non_pt_walk(journey)