コード例 #1
0
 def test_matcher_on_full_trip(self, trip_id = '010414_00168'):
     detected_stop_times_gtfs, relevant_service_ids = self.load_trip_info_for_matcher(trip_id)
         
     trips, time_deviation_in_seconds = get_matched_trips('test_matcher_on_full_trip', detected_stop_times_gtfs,\
                            relevant_service_ids, print_debug_info=True)
     matched_trip_id = get_trusted_trip_or_none(trips, time_deviation_in_seconds)        
     self.assertEquals(matched_trip_id, trip_id)
コード例 #2
0
    def test_matcher_on_partial_random_trip(self, trip_id = '010414_00168', 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, relevant_service_ids = 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]
                trips, time_deviation_in_seconds = get_matched_trips('test_matcher_on_full_trip', detected_stop_times_gtfs,\
                                       relevant_service_ids, print_debug_info=True)

                matched_trip_id = get_trusted_trip_or_none(trips, time_deviation_in_seconds)        
                self.assertEquals(matched_trip_id, unicode(trip_id))
コード例 #3
0
  def test_stop_detector_on_real_trip(self, device_id = '1cb87f1e', trip_id = '010414_00168', do_print=False, do_preload_reports=True, set_reports_to_same_weekday_last_week=True):
      remove_from_redis([device_id])
      now = ot_utils.get_localtime_now()
      reports_queryset = get_device_id_reports(device_id)
      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 % fps_period_length == 0:
              elapsed = (time.clock() - fps_period_start)
              if elapsed > 0:
                  print('%d\t%.1f qps' % (i, fps_period_length/elapsed))
              else:
                  print('Elapsed time should be positive but is %d' % (elapsed))
              fps_period_start = time.clock()                
          
          if i % 900 == 0:
              trips = get_trips(tracker_id)
          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(tracker_id, report)
          
 
      #tracker.print_tracked_stop_times()
      #tracker.print_possible_trips()
      trips, time_deviation_in_seconds = get_trips(tracker_id)
      trip = get_trusted_trip_or_none(trips, time_deviation_in_seconds)
      return tracker_id, [trip]
      remove_from_redis([device_id])
      print 'done'
コード例 #4
0
 def track_mock_reports(self, reports, tracker_id):
     for i, report in enumerate(reports):
         add_report(report)
     trips, time_deviation_in_seconds = get_trips(tracker_id)
     trip = get_trusted_trip_or_none(trips, time_deviation_in_seconds)
     return trip