def make_result(directions_result, departure_time, departure_day): """Builds the initial result dictionary for jsonification.""" result = {} # Prepare the directions result. directions_prepped = prep_directions(directions_result) # Instantiate route object. timed_route = Route(directions_prepped, departure_time, departure_day) # Make list of coordinates and datetimes. coords_time = timed_route.make_coords_time() # Get weather info for coords and times. marker_info = make_marker_info(coords_time) # Make weather report for trip. weather_report = make_weather_report(marker_info) # Convert datetimes to strings. formatted_ct = format_coords_time(coords_time) result["markerInfo"] = marker_info result["weatherReport"] = weather_report result["coordsTime"] = formatted_ct result["routeName"] = None return result
def test_Route_pick_middle(self): result = Route(prep_directions(DIRECTIONS_RESULT_899), "03:01", "tomorrow") coords_time = result.make_coords_time() # Check that it has the correct number of coords. self.assertEqual(len(coords_time), 3) # Check that the correct middle coord was picked. self.assertIn((1, 115), coords_time[1]) # Check that the correct time was paired with the middle coord. self.assertEqual(coords_time[0][1].add(seconds=550), coords_time[1][1])
def test_Route_get_next_coords_time(self): result = Route(prep_directions(DIRECTIONS_RESULT_1999), "03:01", "tomorrow") coords_time = result.make_coords_time() # Check that it has the correct number of coords. self.assertEqual(len(coords_time), 4) # Check that the correct middle coords were picked. self.assertIn((1, 111), coords_time[1]) self.assertIn((1, 120), coords_time[2]) # Check that the second datetime is fifteen minutes past the first datetime. self.assertEqual(coords_time[0][1].add(minutes=15), coords_time[1][1]) # Check that that third datetime is fifteen minutes past the second datetime. self.assertEqual(coords_time[1][1].add(minutes=15), coords_time[2][1])
def test_Route_make_coords_time(self): result = Route(prep_directions(DIRECTIONS_RESULT_899), "03:01", "tomorrow") coords_time = result.make_coords_time() # Check that the ending location coords are in coords_time. self.assertIn((1, 129), coords_time[-1])