# Path: urbanaccess/utils.py
# def log(message, level=None, name=None, filename=None):
#     """
#     Write a message to the log file and/or print to the console.
# 
#     Parameters
#     ----------
#     message : string
#         the content of the message to log
#     level : int, optional
#         one of the logger.level constants
#     name : string, optional
#         name of the logger
#     filename : string, optional
#         name of the log file
# 
#     Returns
#     -------
#     None
#     """
# 
#     if level is None:
#         level = lg.INFO
#     if name is None:
#         name = config.settings.log_name
#     if filename is None:
#         filename = config.settings.log_filename
# 
#     if config.settings.log_file:
#         # get the current logger or create a new one then log message at
#         # requested level
#         logger = _get_logger(level=level, name=name, filename=filename)
#         if level == lg.DEBUG:
#             logger.debug(message)
#         elif level == lg.INFO:
#             logger.info(message)
#         elif level == lg.WARNING:
#             logger.warning(message)
#         elif level == lg.ERROR:
#             logger.error(message)
# 
#     # if logging to console is turned on, convert message to ascii and print
#     #  to the console only
#     if config.settings.log_console:
#         # capture current stdout, then switch it to the console, print the
#         # message, then switch back to what had been the stdout
#         # this prevents logging to notebook - instead, it goes to console
#         standard_out = sys.stdout
#         sys.stdout = sys.__stdout__
# 
#         # convert message to ascii for proper console display in windows
#         # terminals
#         message = unicodedata.normalize('NFKD', str(message)).encode(
#             'ascii', errors='replace').decode()
#         print(message)
#         sys.stdout = standard_out
#     # otherwise print out standard statement
#     else:
#         print(message)
# 
# Path: urbanaccess/network.py
# class urbanaccess_network(object):
#     def __init__(self,
#                  transit_nodes=pd.DataFrame(),
#                  transit_edges=pd.DataFrame(),
#                  net_connector_edges=pd.DataFrame(),
#                  osm_nodes=pd.DataFrame(),
#                  osm_edges=pd.DataFrame(),
#                  net_nodes=pd.DataFrame(),
#                  net_edges=pd.DataFrame()):
# def _nearest_neighbor(df1, df2):
# def integrate_network(urbanaccess_network, headways=False,
#                       urbanaccess_gtfsfeeds_df=None, headway_statistic='mean'):
# def _add_headway_impedance(ped_to_transit_edges_df, headways_df,
#                            headway_statistic='mean'):
# def _route_id_to_node(stops_df, edges_w_routes):
# def _connector_edges(osm_nodes, transit_nodes, travel_speed_mph=3):
# def _format_pandana_edges_nodes(edge_df, node_df):
# def save_network(urbanaccess_network, filename,
#                  dir=config.settings.data_folder,
#                  overwrite_key=False, overwrite_hdf5=False):
# def load_network(dir=config.settings.data_folder, filename=None):


import time
from urbanaccess.utils import log
from urbanaccess.network import ua_network
    Returns
    -------
    ua_network : object
        urbanaccess_network object with osm_edges and osm_nodes DataFrames
    ua_network.osm_edges : pandas.DataFrame
    ua_network.osm_nodes : pandas.DataFrame

    """
    start_time = time.time()

    if not isinstance(network_type, str) or network_type is None:
        raise ValueError('{!s} network_type passed is either not a '
                         'string or is None'.format(network_type))

    # assign impedance to OSM edges
    osm_edges['weight'] = (osm_edges[
                               'distance'] / 1609.34) / travel_speed_mph * 60

    # assign node and edge net type
    osm_edges['net_type'] = network_type
    osm_nodes['net_type'] = network_type

    ua_network.osm_nodes = osm_nodes
    ua_network.osm_edges = osm_edges

    log(
        'Created OSM network with travel time impedance using a travel speed '
        'of {} MPH. Took {:,.2f} seconds'.format(
            travel_speed_mph, time.time() - start_time))


# Path: urbanaccess/utils.py
# def log(message, level=None, name=None, filename=None):
#     """
#     Write a message to the log file and/or print to the console.
# 
#     Parameters
#     ----------
#     message : string
#         the content of the message to log
#     level : int, optional
#         one of the logger.level constants
#     name : string, optional
#         name of the logger
#     filename : string, optional
#         name of the log file
# 
#     Returns
#     -------
#     None
#     """
# 
#     if level is None:
#         level = lg.INFO
#     if name is None:
#         name = config.settings.log_name
#     if filename is None:
#         filename = config.settings.log_filename
# 
#     if config.settings.log_file:
#         # get the current logger or create a new one then log message at
#         # requested level
#         logger = _get_logger(level=level, name=name, filename=filename)
#         if level == lg.DEBUG:
#             logger.debug(message)
#         elif level == lg.INFO:
#             logger.info(message)
#         elif level == lg.WARNING:
#             logger.warning(message)
#         elif level == lg.ERROR:
#             logger.error(message)
# 
#     # if logging to console is turned on, convert message to ascii and print
#     #  to the console only
#     if config.settings.log_console:
#         # capture current stdout, then switch it to the console, print the
#         # message, then switch back to what had been the stdout
#         # this prevents logging to notebook - instead, it goes to console
#         standard_out = sys.stdout
#         sys.stdout = sys.__stdout__
# 
#         # convert message to ascii for proper console display in windows
#         # terminals
#         message = unicodedata.normalize('NFKD', str(message)).encode(
#             'ascii', errors='replace').decode()
#         print(message)
#         sys.stdout = standard_out
#     # otherwise print out standard statement
#     else:
#         print(message)
# 
# Path: urbanaccess/network.py
# class urbanaccess_network(object):
#     def __init__(self,
#                  transit_nodes=pd.DataFrame(),
#                  transit_edges=pd.DataFrame(),
#                  net_connector_edges=pd.DataFrame(),
#                  osm_nodes=pd.DataFrame(),
#                  osm_edges=pd.DataFrame(),
#                  net_nodes=pd.DataFrame(),
#                  net_edges=pd.DataFrame()):
# def _nearest_neighbor(df1, df2):
# def integrate_network(urbanaccess_network, headways=False,
#                       urbanaccess_gtfsfeeds_df=None, headway_statistic='mean'):
# def _add_headway_impedance(ped_to_transit_edges_df, headways_df,
#                            headway_statistic='mean'):
# def _route_id_to_node(stops_df, edges_w_routes):
# def _connector_edges(osm_nodes, transit_nodes, travel_speed_mph=3):
# def _format_pandana_edges_nodes(edge_df, node_df):
# def save_network(urbanaccess_network, filename,
#                  dir=config.settings.data_folder,
#                  overwrite_key=False, overwrite_hdf5=False):
# def load_network(dir=config.settings.data_folder, filename=None):


# Path: urbanaccess/osm/network.py
import time
from urbanaccess.utils import log
from urbanaccess.network import ua_network

    Returns
    -------
    ua_network : object
        urbanaccess_network object with osm_edges and osm_nodes DataFrames
    ua_network.osm_edges : pandas.DataFrame
    ua_network.osm_nodes : pandas.DataFrame

    """
    start_time = time.time()

    if not isinstance(network_type, str) or network_type is None:
        raise ValueError('{!s} network_type passed is either not a '
                         'string or is None'.format(network_type))

    # assign impedance to OSM edges
    osm_edges['weight'] = (osm_edges[
                               'distance'] / 1609.34) / travel_speed_mph * 60

    # assign node and edge net type
    osm_edges['net_type'] = network_type
    osm_nodes['net_type'] = network_type

    ua_network.osm_nodes = osm_nodes
    ua_network.osm_edges = osm_edges

    log(
        'Created OSM network with travel time impedance using a travel speed '
        'of {} MPH. Took {:,.2f} seconds'.format(
            travel_speed_mph, time.time() - start_time))


    return ua_network