def read_source_file(file_name, weather_file_name):
    with open(file_name, 'r') as readCollision:  # r represent read model
        print("Start to read file: " + file_name +
              ". This may take a while...")
        file = csv.reader(readCollision)
        for row in file:
            if "COLLISION_ID" not in row[0]:
                collision = Collision()
                collision.collision_id = row[0]
                collision.location_key = row[1]
                collision.hour_key = row[2]
                collision.environment = row[3]
                collision.light = row[4]
                collision.surface_condition = row[5]
                collision.traffic_control = row[6]
                collision.traffic_control_condition = row[7]
                collision.collision_classification = row[8]
                collision.impace_type = row[9]
                collision.no_of_pedestrians = row[10]
                collision.date = row[11]
                collision.location = row[12]
                collision.is_intersection = row[13]
                collisions.append(collision)
    readCollision.close()

    with open(weather_file_name, 'r') as readWeather:  # r represent read model
        print("Start to read file: " + weather_file_name +
              ". This may take a while...")
        file = csv.reader(readWeather)
        key_ctr = 0
        for row in file:
            weathers.append(row)
            # print(row[0]+" @ "+row[24])
    readWeather.close()
def read_source_file(file_name, hour_file_name):
    with open(file_name, 'r') as readCollision:  # r represent read model
        print("Start to read file: " + file_name +
              ". This may take a while...")
        file = csv.reader(readCollision)
        for row in file:
            if "COLLISION_ID" not in row[0]:
                collision = Collision()
                collision.collision_id = row[0]
                collision.location_key = row[1]
                collision.hour_key = row[2]
                collision.weather_key = row[3]
                collision.environment = row[4]
                collision.light = row[5]
                collision.surface_condition = row[6]
                collision.traffic_control = row[7]
                collision.traffic_control_condition = row[8]
                collision.collision_classification = row[9]
                collision.impace_type = row[10]
                collision.no_of_pedestrians = row[11]
                collision.date = row[12]
                collision.location = row[13]
                collision.is_intersection = row[14]
                collisions.append(collision)
    readCollision.close()

    with open(hour_file_name, 'r') as readHour:  # r represent read model
        print("Start to read file: " + hour_file_name +
              ". This may take a while...")
        file = csv.reader(readHour)
        for row in file:
            if "EVENT_ID" not in row[0]:
                event = Event()
                event.event_id = row[0]
                event.event_name = row[1]
                event.event_start_date = row[2]
                event.event_end_date = row[3]
                if int(event.event_start_date.split("-")[0]) > int(
                        event.event_end_date.split("-")[0]):
                    raise Exception(
                        "Wrong event time - event starting date must be earlier than event ending date: "
                        "START:" + event.event_start_date +
                        " compare to END:" + event.event_end_date)
                if int(event.event_start_date.split("-")[1]) > int(
                        event.event_end_date.split("-")[1]):
                    raise Exception(
                        "Wrong event time - event starting date must be earlier than event ending date: "
                        "START:" + event.event_start_date +
                        " compare to END:" + event.event_end_date)
                events.append(event)
    readHour.close()