# Path: lib/bikestations.py
# def get_text(node):
# def get_int(node):
# def get_float(node):
#     def __init__(self, url, name, metadata):
#     def import_data(self):
#     def update_from_db(self):
#     def to_string(self):
# class BikeStationImporter():
# 
# Path: lib/gtfs_reader.py
# def distance(c1, c2):
# def convert(filename, session, start_date, end_date):
#         C = math.radians(delta)
# 
# Path: lib/kalkati_reader.py
# def distance(c1, c2):
# def normalize_service(start, end, services, service_start):
#     def __init__(self, session, start_date, end_date):
#     def startElement(self, name, attrs): 
#     def endElement(self, name):
#     def endDocument(self):
# def convert(filename, session, start_date, end_date):
#         C = math.radians(delta)
# class KalkatiHandler(ContentHandler): 


import sys
import osm4routing
import os.path
import datetime
import csv
from lib.core.mumoro import *
from lib.core import mumoro
from lib import bikestations, gtfs_reader, kalkati_reader
from lib.datastructures import *
from sqlalchemy import *
from sqlalchemy.orm import mapper, sessionmaker, clear_mappers
    
    def import_kalkati(self, filename, start_date, end_date, network_name = "GTFS"):
        print "Adding municipal data from " + filename
        print "From " + start_date + " to " + end_date + " for " + network_name + " network"
        nodes2 = Metadata(network_name, "Nodes", filename)
        self.session.add(nodes2)
        self.session.commit()
        mapper(PT_Node, create_pt_nodes_table(str(nodes2.id), self.metadata))

        services = Metadata(network_name, "Services", filename)
        self.session.add(services)
        self.session.commit()
        mapper(PT_Service, create_services_table(str(services.id), self.metadata))

        edges2 = Metadata(network_name, "Edges", filename)
        self.session.add(edges2)
        self.session.commit()
        mapper(PT_Edge, create_pt_edges_table(str(edges2.id), self.metadata, str(services.id)))
        self.session.commit()

        kalkati_reader.convert(filename, self.session, start_date, end_date)
        self.init_mappers()
        print "Done importing municipal data from " + filename + " for network '" + network_name + "'"
        print "---------------------------------------------------------------------"

    def import_bike(self, url, name):
        print "Adding public bike service from " + url
        bike_service = Metadata(name, "bike_stations", url )
        self.session.add(bike_service)
        self.session.commit()

# Path: lib/bikestations.py
# def get_text(node):
# def get_int(node):
# def get_float(node):
#     def __init__(self, url, name, metadata):
#     def import_data(self):
#     def update_from_db(self):
#     def to_string(self):
# class BikeStationImporter():
# 
# Path: lib/gtfs_reader.py
# def distance(c1, c2):
# def convert(filename, session, start_date, end_date):
#         C = math.radians(delta)
# 
# Path: lib/kalkati_reader.py
# def distance(c1, c2):
# def normalize_service(start, end, services, service_start):
#     def __init__(self, session, start_date, end_date):
#     def startElement(self, name, attrs): 
#     def endElement(self, name):
#     def endDocument(self):
# def convert(filename, session, start_date, end_date):
#         C = math.radians(delta)
# class KalkatiHandler(ContentHandler): 


# Path: data_import.py
import sys
import osm4routing
import os.path
import datetime
import csv
from lib.core.mumoro import *
from lib.core import mumoro
from lib import bikestations, gtfs_reader, kalkati_reader
from lib.datastructures import *
from sqlalchemy import *
from sqlalchemy.orm import mapper, sessionmaker, clear_mappers

    
    def import_kalkati(self, filename, start_date, end_date, network_name = "GTFS"):
        print "Adding municipal data from " + filename
        print "From " + start_date + " to " + end_date + " for " + network_name + " network"
        nodes2 = Metadata(network_name, "Nodes", filename)
        self.session.add(nodes2)
        self.session.commit()
        mapper(PT_Node, create_pt_nodes_table(str(nodes2.id), self.metadata))

        services = Metadata(network_name, "Services", filename)
        self.session.add(services)
        self.session.commit()
        mapper(PT_Service, create_services_table(str(services.id), self.metadata))

        edges2 = Metadata(network_name, "Edges", filename)
        self.session.add(edges2)
        self.session.commit()
        mapper(PT_Edge, create_pt_edges_table(str(edges2.id), self.metadata, str(services.id)))
        self.session.commit()

        kalkati_reader.convert(filename, self.session, start_date, end_date)
        self.init_mappers()
        print "Done importing municipal data from " + filename + " for network '" + network_name + "'"
        print "---------------------------------------------------------------------"

    def import_bike(self, url, name):
        print "Adding public bike service from " + url
        bike_service = Metadata(name, "bike_stations", url )
        self.session.add(bike_service)
        self.session.commit()

        i = bikestations.BikeStationImporter( url, str(bike_service.id), self.metadata)