# Path: roadmaptools/calculate_curvature.py
# def get_length(coords):
#     length = 0
#     for i in range(0, len(coords) - 1):
#         point1 = get_node(coords[i])
#         point2 = get_node(coords[i + 1])
#         length += get_distance_between_coords(point1, point2)
#     return length
# 
# 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/init.py



from typing import Tuple
from roadmaptools.calculate_curvature import get_length
from geojson import Feature
from roadmaptools.printer import print_info
from roadmaptools.init import config
import geojson
import codecs
import sys
import argparse
import time

    save_geojson(geojson_out, output_stream)
    input_stream.close()
    output_stream.close()

    print_info('Speed estimation completed. (%.2f secs)' % (time.time() - start_time))


def estimate_speeds(input_stream, output_stream):
    json_dict = load_geojson(input_stream)
    get_speeds(json_dict)
    save_geojson(json_dict, output_stream)


def get_geojson_with_speeds(json_dict):
    get_speeds(json_dict)
    return json_dict


def load_geojson(in_stream):
    json_dict = geojson.load(in_stream)
    return json_dict


def get_speeds(json_dict):
    for item in json_dict['features']:
        item['properties']['maxspeed'] = get_posted_speed(item)

        item['properties']['length_gps'] = get_length(item['geometry']['coordinates'])
        if item['geometry']['type'].lower() == 'linestring':
            item['properties']['maxspeed'] = get_posted_speed(item)

# Path: roadmaptools/calculate_curvature.py
# def get_length(coords):
#     length = 0
#     for i in range(0, len(coords) - 1):
#         point1 = get_node(coords[i])
#         point2 = get_node(coords[i + 1])
#         length += get_distance_between_coords(point1, point2)
#     return length
# 
# 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/init.py



# Path: roadmaptools/estimate_speed_from_osm.py
from typing import Tuple
from roadmaptools.calculate_curvature import get_length
from geojson import Feature
from roadmaptools.printer import print_info
from roadmaptools.init import config
import geojson
import codecs
import sys
import argparse
import time

    save_geojson(geojson_out, output_stream)
    input_stream.close()
    output_stream.close()

    print_info('Speed estimation completed. (%.2f secs)' % (time.time() - start_time))


def estimate_speeds(input_stream, output_stream):
    json_dict = load_geojson(input_stream)
    get_speeds(json_dict)
    save_geojson(json_dict, output_stream)


def get_geojson_with_speeds(json_dict):
    get_speeds(json_dict)
    return json_dict


def load_geojson(in_stream):
    json_dict = geojson.load(in_stream)
    return json_dict


def get_speeds(json_dict):
    for item in json_dict['features']:
        item['properties']['maxspeed'] = get_posted_speed(item)

        item['properties']['length_gps'] = get_length(item['geometry']['coordinates'])
        if item['geometry']['type'].lower() == 'linestring':
            item['properties']['maxspeed'] = get_posted_speed(item)

            item['properties']['length_gps'] = get_length(item['geometry']['coordinates'])
