# 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



import geojson
import codecs
import copy
import argparse
import sys
import time
import pandas as pd
import roadmaptools.inout
import roadmaptools.road_structures
from typing import Dict, Set, List, Tuple
from tqdm import tqdm, trange
from geojson import FeatureCollection, Feature
from pandas import DataFrame
from roadmaptools.printer import print_info
from roadmaptools.init import config
# properties that will not be deleted
SET_OF_USEFUL_PROPERTIES = {'highway', 'id', 'lanes', 'maxspeed', 'oneway', 'bridge', 'width', 'tunnel',
                            'traffic_calming', 'lanes:forward', 'lanes:backward', 'junction'}

# for correct type conversion
dict_of_useful_properties = {'highway': str, 'id': int, 'lanes': int, 'maxspeed': int, 'oneway': str, 'bridge': str,
                             'width': float, 'tunnel': str, 'traffic_calming': str, 'lanes:forward': int,
                             'lanes:backward': int, 'junction': str}

nonempty_columns = set()


def _is_int(string: str) -> bool:
    try:
        int(string)
        return True
    except ValueError:
        return False


def clean_geojson_files(input_file_path: str = config.geojson_file,
                        output_file_path: str = config.cleaned_geojson_file,
                        keep_attributes: Set[str] = SET_OF_USEFUL_PROPERTIES,
                        remove_attributes: Set[str] = None):
    print_info('Cleaning geoJSON - input file: {}, cleaned file: {}'.format(input_file_path, output_file_path))

    start_time = time.time()
    feature_collection = roadmaptools.inout.load_geojson(input_file_path)
    prune_geojson_file(feature_collection, keep_attributes, remove_attributes)


# 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/clean_geojson.py
import geojson
import codecs
import copy
import argparse
import sys
import time
import pandas as pd
import roadmaptools.inout
import roadmaptools.road_structures
from typing import Dict, Set, List, Tuple
from tqdm import tqdm, trange
from geojson import FeatureCollection, Feature
from pandas import DataFrame
from roadmaptools.printer import print_info
from roadmaptools.init import config

# properties that will not be deleted
SET_OF_USEFUL_PROPERTIES = {'highway', 'id', 'lanes', 'maxspeed', 'oneway', 'bridge', 'width', 'tunnel',
                            'traffic_calming', 'lanes:forward', 'lanes:backward', 'junction'}

# for correct type conversion
dict_of_useful_properties = {'highway': str, 'id': int, 'lanes': int, 'maxspeed': int, 'oneway': str, 'bridge': str,
                             'width': float, 'tunnel': str, 'traffic_calming': str, 'lanes:forward': int,
                             'lanes:backward': int, 'junction': str}

nonempty_columns = set()


def _is_int(string: str) -> bool:
    try:
        int(string)
        return True
    except ValueError:
        return False


def clean_geojson_files(input_file_path: str = config.geojson_file,
                        output_file_path: str = config.cleaned_geojson_file,
                        keep_attributes: Set[str] = SET_OF_USEFUL_PROPERTIES,
                        remove_attributes: Set[str] = None):
    print_info('Cleaning geoJSON - input file: {}, cleaned file: {}'.format(input_file_path, output_file_path))

    start_time = time.time()
    feature_collection = roadmaptools.inout.load_geojson(input_file_path)
    prune_geojson_file(feature_collection, keep_attributes, remove_attributes)


    print_info('Cleaning complete. (%.2f secs)' % (time.time() - start_time))