Example #1
0
 def track_mock_reports(self, reports, tracker_id):
     for i, report in enumerate(reports):
         add_report(report)
     trip_delays_ids_list_of_lists = load_by_key(
         get_train_tracker_trip_delays_ids_list_of_lists_key(tracker_id))
     trips = get_trusted_trips(trip_delays_ids_list_of_lists)
     return trips
Example #2
0
    def test_matcher_on_full_trip(self, trip_id="010714_00115"):
        detected_stop_times_gtfs, day = self.load_trip_info_for_matcher(trip_id)

        trip_delays_ids_list_of_lists = get_matched_trips("test_matcher_on_full_trip", detected_stop_times_gtfs, day)
        self.assertEquals(len(trip_delays_ids_list_of_lists), 1)
        matched_trip_ids = get_trusted_trips(trip_delays_ids_list_of_lists)
        self.assertEquals(matched_trip_ids[0], trip_id)
Example #3
0
    def test_matcher_on_trip_set(self, trip_ids=["010714_00283", "010714_00115"]):
        detected_stop_times_gtfs_all = []
        for trip_id in trip_ids:
            detected_stop_times_gtfs, day = self.load_trip_info_for_matcher(trip_id)
            detected_stop_times_gtfs_all += detected_stop_times_gtfs

        trip_delays_ids_list_of_lists = get_matched_trips(
            "test_matcher_on_full_trip", detected_stop_times_gtfs_all, day
        )

        self.assertEquals(len(trip_delays_ids_list_of_lists), 2)
        matched_trip_ids = sorted(get_trusted_trips(trip_delays_ids_list_of_lists))
        self.assertEquals(matched_trip_ids, sorted(trip_ids))
Example #4
0
def track_device(device_id,
                 do_print=False,
                 do_preload_reports=True,
                 set_reports_to_same_weekday_last_week=False,
                 report_limit=10000000):
    #device_coords, device_timestamps, device_accuracies_in_meters, device_accuracies_in_coords = get_location_info_from_device_id(device_id)
    now = ot_utils.get_localtime_now()
    reports_queryset = stop_detector_test.get_device_id_reports(device_id)
    assert reports_queryset.count() > 0, 'No device reports in db'
    tracker_id = device_id

    fps_period_start = time.clock()
    fps_period_length = 100
    if do_preload_reports:
        reports_queryset = list(reports_queryset)
    count = len(reports_queryset) if isinstance(
        reports_queryset, list) else reports_queryset.count()
    for i in xrange(count):
        if i > report_limit:
            break
        if i % fps_period_length == 0:
            elapsed = (time.clock() - fps_period_start)
            if elapsed > 0:
                logger.debug('%d\t%.1f qps' % (i, fps_period_length / elapsed))
            else:
                logger.debug(
                    'Elapsed time should be positive but is %d' % (elapsed))
            fps_period_start = time.clock()

        report = reports_queryset[i]

        if set_reports_to_same_weekday_last_week:
            # fix finding same weekday last week by http://stackoverflow.com/questions/6172782/find-the-friday-of-previous-last-week-in-python
            day_fix = (now.weekday() - report.timestamp.weekday()) % 7
            day = now + datetime.timedelta(days=-day_fix)
            # move day and correct for DST (daylight savings time)
            dst_before = report.get_timestamp_israel_time().dst()
            report.timestamp = report.timestamp.replace(
                year=day.year, month=day.month, day=day.day)
            dst_after = report.get_timestamp_israel_time().dst()
            report.timestamp -= dst_after - dst_before

        add_report(report)

    #tracker.print_tracked_stop_times()
    #tracker.print_possible_trips()
    trip_delays_ids_list_of_lists = load_by_key(
        get_train_tracker_trip_delays_ids_list_of_lists_key(tracker_id))
    trips = get_trusted_trips(trip_delays_ids_list_of_lists)
    return tracker_id, trips
Example #5
0
    def test_matcher_on_partial_random_trip(self, trip_id="010714_00115", seeds=[0, 1, 2, 3], stop_counts=[3, 4, 5]):
        for seed in seeds:
            for stop_count in stop_counts:
                print "seed =", seed, "stop_count =", stop_count
                detected_stop_times_gtfs, day = self.load_trip_info_for_matcher(trip_id)
                random.seed(seed)
                subset_inds = sorted(random.sample(xrange(0, len(detected_stop_times_gtfs)), stop_count))
                detected_stop_times_gtfs_subset = [detected_stop_times_gtfs[i] for i in subset_inds]
                trip_delays_ids_list_of_lists = get_matched_trips(
                    "test_matcher_on_full_trip", detected_stop_times_gtfs, day
                )

                self.assertEquals(len(trip_delays_ids_list_of_lists), 1)
                matched_trip_ids = get_trusted_trips(trip_delays_ids_list_of_lists)
                self.assertEquals(matched_trip_ids[0], unicode(trip_id))