# Path: roadmaptools/calculate_curvature.py
# def get_curvature(coords):
#     if len(coords) < 3:
#         return [0, 0]  # no curvature on edge
#     else:
#         total_curvature = 0
#         max_curvature = -1
#         length_of_edge = 0
#         for i in range(0, len(coords) - 2):
#             point_a = get_node(coords[i])
#             point_b = get_node(coords[i + 1])
#             point_c = get_node(coords[i + 2])
# 
#             length_c = get_distance_between_coords(point_a, point_b)
#             length_a = get_distance_between_coords(point_b, point_c)
#             length_b = get_distance_between_coords(point_c, point_a)
# 
#             # k = 0.5 * (length_b+length_a+length_c)
#             # area = math.sqrt(k*(k-length_a)*(k-length_b)*(k-length_c))
#             # radius = (length_b*length_a*length_c)/(4*area)
#             angle = calculate_angle_in_degree(length_a, length_b, length_c)
#             distance = length_c + length_a
#             curvature = angle / distance
#             if curvature > max_curvature:
#                 max_curvature = curvature
#             total_curvature += angle
#             length_of_edge += distance
# 
#         return [total_curvature / length_of_edge, max_curvature]
# 
# Path: roadmaptools/init.py

# 
# 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)


from typing import Dict
from roadmaptools.calculate_curvature import get_curvature
from geojson import LineString, Feature, FeatureCollection
from tqdm import tqdm
from roadmaptools.init import config
from roadmaptools.printer import print_info
import geojson
import networkx as nx
import codecs
import argparse
import sys
import time
import roadmaptools.inout
import roadmaptools.road_structures

        nbr2 = temp_dict[edge_id]['neighbour'][0]
        coords = filter(None, temp_dict[edge_id]['coords'])
        ret = [False, [n1, n2]]
        for node in coords:
            ret.append(node)
        ret.append([nbr1, nbr2])
        return ret
    else:
        return [True]


def _load_graph(json_dict: dict) -> nx.MultiDiGraph:
    graph = nx.DiGraph()
    for item in tqdm(json_dict['features'], desc="creating road graph"):
        coord = item['geometry']['coordinates']
        coord_u = get_node(coord[0])
        coord_v = get_node(coord[-1])

        # prune loops without any purpose, save loops like traffic roundabout
        if coord_u != coord_v or len(coord) != 2:
            props = item['properties']
            graph.add_edge(
                coord_u,
                coord_v,
                id=item['properties']['id'],
                others=[[]],
                lanes=props['lanes'],
                from_osm_id=props["from_osm_id"],
                to_osm_id=props["to_osm_id"]
            )

# Path: roadmaptools/calculate_curvature.py
# def get_curvature(coords):
#     if len(coords) < 3:
#         return [0, 0]  # no curvature on edge
#     else:
#         total_curvature = 0
#         max_curvature = -1
#         length_of_edge = 0
#         for i in range(0, len(coords) - 2):
#             point_a = get_node(coords[i])
#             point_b = get_node(coords[i + 1])
#             point_c = get_node(coords[i + 2])
# 
#             length_c = get_distance_between_coords(point_a, point_b)
#             length_a = get_distance_between_coords(point_b, point_c)
#             length_b = get_distance_between_coords(point_c, point_a)
# 
#             # k = 0.5 * (length_b+length_a+length_c)
#             # area = math.sqrt(k*(k-length_a)*(k-length_b)*(k-length_c))
#             # radius = (length_b*length_a*length_c)/(4*area)
#             angle = calculate_angle_in_degree(length_a, length_b, length_c)
#             distance = length_c + length_a
#             curvature = angle / distance
#             if curvature > max_curvature:
#                 max_curvature = curvature
#             total_curvature += angle
#             length_of_edge += distance
# 
#         return [total_curvature / length_of_edge, max_curvature]
# 
# Path: roadmaptools/init.py

# 
# 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/simplify_graph.py
from typing import Dict
from roadmaptools.calculate_curvature import get_curvature
from geojson import LineString, Feature, FeatureCollection
from tqdm import tqdm
from roadmaptools.init import config
from roadmaptools.printer import print_info
import geojson
import networkx as nx
import codecs
import argparse
import sys
import time
import roadmaptools.inout
import roadmaptools.road_structures

        nbr2 = temp_dict[edge_id]['neighbour'][0]
        coords = filter(None, temp_dict[edge_id]['coords'])
        ret = [False, [n1, n2]]
        for node in coords:
            ret.append(node)
        ret.append([nbr1, nbr2])
        return ret
    else:
        return [True]


def _load_graph(json_dict: dict) -> nx.MultiDiGraph:
    graph = nx.DiGraph()
    for item in tqdm(json_dict['features'], desc="creating road graph"):
        coord = item['geometry']['coordinates']
        coord_u = get_node(coord[0])
        coord_v = get_node(coord[-1])

        # prune loops without any purpose, save loops like traffic roundabout
        if coord_u != coord_v or len(coord) != 2:
            props = item['properties']
            graph.add_edge(
                coord_u,
                coord_v,
                id=item['properties']['id'],
                others=[[]],
                lanes=props['lanes'],
                from_osm_id=props["from_osm_id"],
                to_osm_id=props["to_osm_id"]
            )

    return graph
