Exemplo n.º 1
0
 def testProcessReport(self):
   report = gps.client.dictwrapper({
       u'epx': 7.409,
       u'epy': 8.266,
       u'epv': 20.01,
       u'ept': 0.005,
       u'lon': -2.1,
       u'eps': 165.32,
       u'lat': 14.2,
       u'track': 0.0,
       u'mode': 3,
       u'time': u'2019-12-19T05:24:24.100Z',
       u'device': u'/dev/ttyACM0',
       u'alt': 6.9,
       u'speed': 0.088,
       u'class': u'TPV'})
   es = exit_speed.ExitSpeed()
   es.PopulatePoint(report)
   point = es.point
   self.assertEqual(point.lat, 14.2)
   self.assertEqual(point.lon, -2.1)
   self.assertEqual(point.alt, 6.9)
   self.assertEqual(point.speed, 0.088)
   self.assertEqual(point.time.seconds, 1576733064)
   self.assertEqual(point.time.nanos, 100000000)
Exemplo n.º 2
0
 def testCrossStartFinish(self):
   point_a = gps_pb2.Point()
   point_b = gps_pb2.Point()
   point_c = gps_pb2.Point()
   point_b.start_finish_distance = 5.613414540798601
   point_c.start_finish_distance = 8.86833983566463
   point_a.time.FromMilliseconds(1000)
   point_b.time.FromMilliseconds(2000)
   point_c.time.FromMilliseconds(3000)
   point_a.lat = 45.594961
   point_a.lon = -122.694508
   point_b.lat = 45.594988
   point_b.lon = -122.694587
   point_c.lat = 45.595000
   point_c.lon = -122.694638
   session = gps_pb2.Session()
   session.track = 'Portland International Raceway'
   session.start_finish.lat = 45.595015
   session.start_finish.lon = -122.694526
   lap = session.laps.add()
   lap.points.extend([point_a, point_b])
   es = exit_speed.ExitSpeed(min_points_per_session=0)
   es.point = point_c
   es.lap = lap
   es.session = session
   es.CrossStartFinish()
   self.assertEqual(2, len(es.session.laps))
   self.assertEqual(2, len(es.session.laps[0].points))
   self.assertEqual(2, len(es.session.laps[1].points))
   self.assertIn(point_a, es.session.laps[0].points)
   self.assertIn(point_b, es.session.laps[0].points)
   self.assertIn(point_b, es.session.laps[1].points)
   self.assertIn(point_c, es.session.laps[1].points)
   self.assertNotIn(point_c, es.session.laps[0].points)
Exemplo n.º 3
0
 def testProcessPoint(self):
   prior_point = gps_pb2.Point()
   prior_point.lat = 12.000000
   prior_point.lon = 23.000000
   point = gps_pb2.Point()
   point.lat = 12.000001
   point.lon = 23.000002
   es = exit_speed.ExitSpeed()
   es.lap = gps_pb2.Lap()
   es.lap.points.extend([prior_point, point])
   es.point = point
   es.ProcessPoint()
   self.assertEqual(2856514.6203466402, point.start_finish_distance)
Exemplo n.º 4
0
 def testSetLapTime(self):
   es = exit_speed.ExitSpeed()
   first_point = gps_pb2.Point()
   first_point.time.FromJsonString(u'2020-05-23T17:47:44.100Z')
   last_point = gps_pb2.Point()
   last_point.time.FromJsonString(u'2020-05-23T17:49:00.100Z')
   session = gps_pb2.Session()
   lap = session.laps.add()
   lap.points.append(first_point)
   lap.points.append(last_point)
   es.lap = lap
   es.session = session
   es.SetLapTime()
   self.assertEqual(76, lap.duration.ToSeconds())
   self.assertEqual(es.leds.best_lap, lap)
Exemplo n.º 5
0
def ReplayLog(filepath, include_sleep=False):
    """Replays data, extermely useful to LED testing.

  Args:
    filepath: A string of the path of lap data.
    include_sleep: If True replays adds sleeps to simulate how data was
                   processed in real time.

  Returns:
    A exit_speed.ExitSpeed instance that has replayed the given data.
  """
    logging.info('Replaying %s', filepath)
    logger = data_logger.Logger(filepath)
    points = list(logger.ReadProtos())
    logging.info('Number of points %d', len(points))
    if include_sleep:
        replay_start = time.time()
        time_shift = int(replay_start * 1e9 - points[0].time.ToNanoseconds())
        session_start = None
    else:
        FLAGS.set_default('commit_cycle', 10000)
    es = exit_speed.ExitSpeed(live_data=not include_sleep)
    for point in points:
        if include_sleep:
            point.time.FromNanoseconds(point.time.ToNanoseconds() + time_shift)
            if not session_start:
                session_start = point.time.ToMilliseconds() / 1000

        es.point = point
        es.ProcessSession()
        if include_sleep:
            run_delta = time.time() - replay_start
            point_delta = point.time.ToMilliseconds() / 1000 - session_start
            if run_delta < point_delta:
                time.sleep(point_delta - run_delta)

    if not include_sleep:
        time.sleep(1)
        qsize = len(es.pusher.point_queue)
        while qsize > 0:
            qsize = len(es.pusher.point_queue)
            logging.log_every_n_seconds(logging.INFO, 'Queue size %s', 2,
                                        qsize)
        es.pusher.stop_process_signal.value = True
        print(time.time())
        es.pusher.process.join(10)
        print(time.time())
    return es
Exemplo n.º 6
0
  def testProcessSession(self):
    point = gps_pb2.Point()
    point.speed = 21
    lap = gps_pb2.Lap()
    session = gps_pb2.Session()
    es = exit_speed.ExitSpeed()
    es.point = point
    es.session = session
    es.ProcessSession()

    for _ in session.laps:
      for lap_point in lap.points:
        self.assertEqual(point, lap_point)

    point = gps_pb2.Point()
    point.speed = 1
    es.point = point
    es.ProcessSession()
Exemplo n.º 7
0
 def testProcessLap(self):
   es = exit_speed.ExitSpeed()
   es.point = es.lap.points.add()
   es.ProcessLap()
   self.assertTrue(es.lap.points)