Exemplo n.º 1
0
    def testSetBestLap(self):
        lap = gps_pb2.Lap()
        lap.duration.FromSeconds(100)
        point = lap.points.add()
        point.speed_ms = 88  # m/s

        self.leds.SetBestLap(lap)
        first_tree = self.leds.tree

        lap = gps_pb2.Lap()
        lap.duration.FromSeconds(99)
        point = lap.points.add()
        point.speed_ms = 88  # m/s
        self.leds.SetBestLap(lap)
        self.assertNotEqual(first_tree, self.leds.tree)
Exemplo n.º 2
0
 def testCalcTimeAfterFinish(self):
     start_finish = gps_pb2.Point()
     start_finish.lat = 45.595015
     start_finish.lon = -122.694526
     lap = gps_pb2.Lap()
     point_a = lap.points.add()
     point_b = lap.points.add()
     point_c = lap.points.add()
     point_a.time.FromMilliseconds(1)
     point_b.time.FromMilliseconds(2)
     point_c.time.FromMilliseconds(3)
     point_a.lat = 45.593988
     point_a.lon = -122.693587
     point_b.lat = 45.594988
     point_b.lon = -122.694587
     point_c.lat = 45.595000
     point_c.lon = -122.694638
     point_b.start_finish_distance = common_lib.PointDelta(
         start_finish, point_b)
     point_c.start_finish_distance = common_lib.PointDelta(
         start_finish, point_c)
     point_a.speed_ms = 68.2
     point_b.speed_ms = 70
     point_c.speed_ms = 70.2
     self.assertEqual(1000000.0548742702, lap_lib.CalcTimeAfterFinish(lap))
Exemplo n.º 3
0
    def testUpdateLeds(self, mock_fill):
        lap = gps_pb2.Lap()
        point = lap.points.add()
        point.speed_ms = 88  # m/s
        self.leds.UpdateLeds(point)
        self.assertFalse(mock_fill.mock_calls)  # No BallTree yet.

        self.leds.SetBestLap(lap)  # Used to build the BallTree.
        self.leds.UpdateLeds(point)
        color = (0, 255, 0)  # Green
        mock_fill.assert_called_once_with(color)
        deltas = collections.deque(maxlen=FLAGS.speed_deltas)
        deltas.append(0.0)
        self.assertSequenceEqual(deltas, self.leds.speed_deltas)
Exemplo n.º 4
0
 def testProcessPoint(self):
     prior_point = gps_pb2.Point()
     prior_point.lat = 12.000000
     prior_point.lon = 23.000000
     prior_point.time.FromJsonString(u'2020-05-23T17:47:44.100Z')
     point = gps_pb2.Point()
     point.lat = 12.000001
     point.lon = 23.000002
     point.time.FromJsonString(u'2020-05-23T17:47:44.200Z')
     es = main.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.º 5
0
    def testProcessSession(self):
        point = gps_pb2.Point()
        point.speed_ms = 21
        lap = gps_pb2.Lap()
        session = gps_pb2.Session()
        es = main.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_ms = 1
        es.point = point
        es.ProcessSession()
Exemplo n.º 6
0
 def testCalculateElapsedValues(self):
     before_point = gps_pb2.Point()
     prior_point = gps_pb2.Point()
     prior_point.lat = 12.000000
     prior_point.lon = 23.000000
     prior_point.time.FromJsonString(u'2020-05-23T17:47:44.100Z')
     point = gps_pb2.Point()
     point.lat = 12.000001
     point.lon = 23.000002
     point.time.FromJsonString(u'2020-05-23T17:47:44.200Z')
     es = main.ExitSpeed()
     es.lap = gps_pb2.Lap()
     es.lap.points.extend([before_point, prior_point, point])
     es.point = point
     es.ProcessPoint()
     self.assertEqual(prior_point.elapsed_duration_ms, 0)
     self.assertEqual(prior_point.elapsed_distance_m, 0)
     self.assertEqual(point.elapsed_duration_ms, 100)
     self.assertEqual(point.elapsed_distance_m, 0.2430443280901163)
Exemplo n.º 7
0
    def testFindNearestBestLapPoint(self):
        lap = gps_pb2.Lap()
        point = lap.points.add()
        point.lat = 1
        point.lon = 1
        point = lap.points.add()
        point.lat = 5
        point.lon = 5
        point = lap.points.add()
        point.lat = 20
        point.lon = 20

        self.leds.SetBestLap(lap)  # Build the tree.
        point = gps_pb2.Point()
        point.lat = 4
        point.lon = 4
        nearest = self.leds.FindNearestBestLapPoint(point)
        self.assertEqual(nearest.lat, 5)
        self.assertEqual(nearest.lon, 5)
Exemplo n.º 8
0
 def testGetPriorUniquePoint(self):
     point_c = gps_pb2.Point()
     point_c.time.FromMilliseconds(10)
     point_c.lat = 1
     point_c.lon = -1
     lap = gps_pb2.Lap()
     point = lap.points.add()
     point.time.FromMilliseconds(7)
     point = lap.points.add()
     point.time.FromMilliseconds(8)
     point.lat = 8
     point.lon = -8
     point = lap.points.add()
     point.time.FromMilliseconds(9)
     point = lap.points.add()
     point.time.FromMilliseconds(10)  # second point at 10.
     point.lat = 10
     point.lon = -10
     returned = lap_lib.GetPriorUniquePoint(lap, point_c)
     self.assertEqual(8, returned.time.ToMilliseconds())