# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


import geojson
import googlemaps
import networkx as nx
import codecs
import os.path
from datetime import datetime
from typing import Union, Tuple, List
from roadmaptools.printer import print_info

			# print_info("Request sent")
			result = gmaps.directions(start, target, mode="driving", language="en-GB", units="metric",
										   departure_time=time, traffic_model=model)
			# print_info("Response obtained")
			# print(self.get_velocity(result))
			# duration = result['rows'][0]['elements'][0]['duration_in_traffic']['value']
			# distance = result['rows'][0]['elements'][0]['distance']['value']
			return result
		except (googlemaps.exceptions) as error:
			print_info("Google maps exception: {}".format(error))

	def get_durations_and_distances(self, starts: Union[Tuple[float, float], List[Tuple[float, float]]],
									targets: Union[Tuple[float,float], List[Tuple[float,float]]], time: datetime,
									model: str= "best_guess"):
		rows = []
		for index, start in enumerate(starts):
			start_batch, target_batch = 0
			if index % self.max_paths_in_request == 0:
				if index > 0:
					result = self.google_maps_find_path(start_batch, target_batch, time, model)
					rows.extend(result['rows'])
				start_batch = []
				target_batch = []

			start_batch.append(start)
			target_batch.append(targets[index])

		durations = []
		distances = []
		for row in rows:

# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


# Path: roadmaptools/gmaps.py
import geojson
import googlemaps
import networkx as nx
import codecs
import os.path
from datetime import datetime
from typing import Union, Tuple, List
from roadmaptools.printer import print_info

			# print_info("Request sent")
			result = gmaps.directions(start, target, mode="driving", language="en-GB", units="metric",
										   departure_time=time, traffic_model=model)
			# print_info("Response obtained")
			# print(self.get_velocity(result))
			# duration = result['rows'][0]['elements'][0]['duration_in_traffic']['value']
			# distance = result['rows'][0]['elements'][0]['distance']['value']
			return result
		except (googlemaps.exceptions) as error:
			print_info("Google maps exception: {}".format(error))

	def get_durations_and_distances(self, starts: Union[Tuple[float, float], List[Tuple[float, float]]],
									targets: Union[Tuple[float,float], List[Tuple[float,float]]], time: datetime,
									model: str= "best_guess"):
		rows = []
		for index, start in enumerate(starts):
			start_batch, target_batch = 0
			if index % self.max_paths_in_request == 0:
				if index > 0:
					result = self.google_maps_find_path(start_batch, target_batch, time, model)
					rows.extend(result['rows'])
				start_batch = []
				target_batch = []

			start_batch.append(start)
			target_batch.append(targets[index])

		durations = []
		distances = []
		for row in rows:

			durations.append(row['elements'][0]['duration_in_traffic']['value'])
