示例#1
0
 def test_tracker_on_real_devices(self):    
     device_ids = []
     trip_suffixes_list = []
     device_ids.append('ofer_995357870c491cad')
     device_ids.append('ofer_207fabab5f381476')
     for device_id in device_ids:
         suffix_list = [x[x.index('_'):] for x in trip_ground_truth.data[device_id]]
         
         trip_suffixes_list.append(suffix_list)
     
     stop_detector_test.remove_from_redis(device_ids)
     
     for i in xrange(len(device_ids)):
         device_id = device_ids[i] 
         trip_suffixes = trip_suffixes_list[i]
         tracker_id, trips = track_device(device_id, do_preload_reports=True)
         for trip_id in trips:
             timetable.services.print_trip_stop_times(trip_id)
         stop_detector.print_tracked_stop_times(device_id)
         
         self.assertEquals(len(trips), len(trip_suffixes))
         for trip_suffix in trip_suffixes:
             self.assertTrue(self.is_trip_in_list(trips, trip_suffix))
   
     stop_detector_test.remove_from_redis(device_ids)
示例#2
0
    def _stop_detector_on_real_trip(self, device_id='1cb87f1e', do_preload_reports=True, set_reports_to_same_weekday_last_week=True, do_show_fig=False):
        remove_from_redis([device_id])
        now = ot_utils.get_localtime_now()
        reports_queryset = get_device_id_reports(device_id)
        tracker_id = device_id
        if do_show_fig:
            display_utils.draw_map()

        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 % 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
            if do_show_fig:
                plt.scatter(report.my_loc.lat, report.my_loc.lon)
                plt.show()
            #print i, ot_utils.get_localtime(report.timestamp)
            is_updated_stop_time = add_report(tracker_id, report)
            if is_updated_stop_time:
                logger.debug('stop_time updated')

        stop_detector.print_tracked_stop_times(device_id)
        detected_stop_times = stop_detector.get_detected_stop_times(device_id)
        ground_truth_stops = stop_detector_ground_truth.data[device_id]
        for x, y in zip(detected_stop_times, ground_truth_stops):
            self.assertEquals(x.__str__(), y.__str__())

        remove_from_redis([device_id])
        print 'done'
        return tracker_id
def run_tracker_on_trips_without_ground_truth(device_ids=None):    
    trip_suffixes_list = []
    if not device_ids:
        device_ids = [x for x in trip_ground_truth.data if not trip_ground_truth.data[x]]
    
    stop_detector_test.remove_from_redis(device_ids)
    
    for i in xrange(len(device_ids)):
        device_id = device_ids[i] 
        tracker_id, trips = train_tracker_test.track_device(device_id, do_preload_reports=True, report_limit=100)
        print 'DEVICE_ID=%s' % device_id
        for trip_id in trips:
            timetable.services.print_trip_stop_times(trip_id)
        stop_detector.print_tracked_stop_times(device_id)
        
    stop_detector_test.remove_from_redis(device_ids)
示例#4
0
 def test_stop_detector_on_mock_trip(self, device_id = 'fake_device_1', trip_id = '010414_00168'):
     remove_from_redis([device_id])
     day = datetime.datetime.strptime(trip_id.split('_')[0], '%d%m%y')
     now = ot_utils.get_localtime_now() # we want to get the correct timezone so we take it from get_localtime_now()
     day = now.replace(year=day.year, month=day.month, day=day.day)
     reports = generate_mock_reports(device_id=device_id, trip_id=trip_id, nostop_percent=0.05, day=day)
     tracker_id = device_id
     for i, report in enumerate(reports):
         add_report(tracker_id, report=report)
         if (i % 100) == 0:
             print i
             stop_detector.print_tracked_stop_times(tracker_id)
         
     self.evaluate_detected_stop_times(tracker_id, trip_id)
     remove_from_redis([device_id])
     print 'done'