def test_list_without_stoping_point(self):
     list_processor = WaypointListProcessor(
         self.waypoints_list_without_stoping_point)
     assert list_processor.get_trips() == [
         Trip(distance=567954.096,
              start=Waypoint(timestamp='2018-08-10T20:10:22Z',
                             lat=54.54987,
                             lng=12.41039),
              end=Waypoint(timestamp='2018-08-10T20:22:22Z',
                           lat=59.64987,
                           lng=12.41039))
     ]
 def test_list_starts_with_not_moving_points(self):
     # List beginning with same points, which means that
     # the car has not moved yet
     list_processor = WaypointListProcessor(
         self.waypoints_list_starts_with_not_moving_points)
     assert list_processor.get_trips() == [
         Trip(distance=779395.536,
              start=Waypoint(timestamp='2018-08-10T20:10:22Z',
                             lat=52.54987,
                             lng=12.41039),
              end=Waypoint(timestamp='2018-08-10T20:17:22Z',
                           lat=59.54987,
                           lng=12.41039))
     ]
 def test_list_with_two_trips(self):
     list_processor = WaypointListProcessor(
         self.waypoints_list_with_two_trips)
     assert list_processor.get_trips() == [
         Trip(distance=222593.124,
              start=Waypoint(timestamp='2018-08-10T20:04:22Z',
                             lat=52.54987,
                             lng=12.41039),
              end=Waypoint(timestamp='2018-08-10T20:06:22Z',
                           lat=54.54987,
                           lng=12.41039)),
         Trip(distance=556802.412,
              start=Waypoint(timestamp='2018-08-10T20:10:22Z',
                             lat=54.54987,
                             lng=12.41039),
              end=Waypoint(timestamp='2018-08-10T20:17:22Z',
                           lat=59.54987,
                           lng=12.41039))
     ]
def main():
    parser = argparse.ArgumentParser(
        description='extrace trips from a stream or list of Waypoints.')
    parser.add_argument('--stream',
                        action='store_true',
                        help='extrace trips from a stream of Waypoints')
    parser.add_argument('--list',
                        action='store_true',
                        help='extrace trips from a list of Waypoints')
    parser.add_argument('--source',
                        dest='source',
                        help='data source file with vaild json format',
                        required=True)
    args = parser.parse_args()

    data_json = load_from_json_file(args.source)

    if isinstance(data_json, list):
        waypoints = convert_data_to_waypoints(data_json)
    else:
        print("Error: %s" % data_json)
        parser.print_help()
        exit(0)

    if args.list:
        list_processor = WaypointListProcessor(waypoints)
        trips = list_processor.get_trips()
        print(json.dumps(trip_waypoint_format(trips)))
    elif args.stream:
        stream_processor = WaypointStreamProcessor()
        trips = [
            stream_processor.process_waypoint(waypoint)
            for waypoint in waypoints
        ]
        trips = filter(None, trips)
        print(json.dumps(trip_waypoint_format(trips)))
    else:
        parser.print_help()
 def test_list_with_distance_less_15m(self):
     list_processor = WaypointListProcessor(
         self.waypoints_list_with_distance_less_15m)
     assert list_processor.get_trips() == []
 def test_car_trip_has_ended(self, points, expected):
     list_processor = WaypointListProcessor([])
     assert list_processor._car_trip_has_ended(points) == expected
 def test_car_on_move(self, current_point, next_point, expected):
     list_processor = WaypointListProcessor([])
     assert list_processor._car_in_move(current_point,
                                        next_point) == expected