# 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

	traffic_models = ["best_guess", "pessimistic", "optimistic"]
	temp_dict = dict()
	json_dict = dict()
	g = nx.DiGraph()

	max_paths_in_request = 10

	def __init__(self, pathname=None):
		self.pathname = pathname

	def find_edge(self, id, model):
		duration = self.temp_dict[id]['duration_' + model]
		distance = self.temp_dict[id]['distance_' + model]
		speed = self.temp_dict[id]['speed_' + model]
		return [duration, distance, speed]

	def google_maps_find_path(self, start: Tuple[float, float], target: Tuple[float, float], time: datetime,
							  model: str= "best_guess"):
		try:
			gmaps = googlemaps.Client(key='AIzaSyDoCeLZhFJkx2JTLH8UMcsouaVUIwbV_wY')
			# time = datetime(2017, 11, 14, 7, 0, 0)  # 7 hours after midnight
			# 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:

# 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

	traffic_models = ["best_guess", "pessimistic", "optimistic"]
	temp_dict = dict()
	json_dict = dict()
	g = nx.DiGraph()

	max_paths_in_request = 10

	def __init__(self, pathname=None):
		self.pathname = pathname

	def find_edge(self, id, model):
		duration = self.temp_dict[id]['duration_' + model]
		distance = self.temp_dict[id]['distance_' + model]
		speed = self.temp_dict[id]['speed_' + model]
		return [duration, distance, speed]

	def google_maps_find_path(self, start: Tuple[float, float], target: Tuple[float, float], time: datetime,
							  model: str= "best_guess"):
		try:
			gmaps = googlemaps.Client(key='AIzaSyDoCeLZhFJkx2JTLH8UMcsouaVUIwbV_wY')
			# time = datetime(2017, 11, 14, 7, 0, 0)  # 7 hours after midnight
			# 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))
