Пример #1
0
    def handle_ottawa_date_and_time(date, _time):
        if is_null_or_empty(date):
            raise Exception("Date is empty/null")
        if is_null_or_empty(_time):
            raise Exception("Time is empty/null")

        return datetime.strptime(date, '%Y-%m-%d').date(), datetime.strptime(
            _time, '%I:%M:%S %p').time()
    def handle_weather(weather):
        if is_null_or_empty(weather) or is_missing_or_unavailable(weather):
            return None, NOT_AVAILABLE

        if is_estimated(weather):
            return weather, ESTIMATED

        return weather, AVAILABLE
Пример #3
0
    def handle_toronto_light_condition(light):
        flag = AVAILABLE
        if is_null_or_empty(light):
            flag = NOT_AVAILABLE
            return None, flag

        if light.lower().strip() not in VISIBILITY:
            raise Exception(
                "{} is an invalid/unknown visibility variable".format(light))
        return light.lower().strip(), flag
    def handle_float_data_and_flag(data, flag):
        if is_null_or_empty(data) or is_missing_or_unavailable(flag):
            return None, NOT_AVAILABLE

        value = round(float(data), 2)

        if is_estimated(flag):  # estimated data
            return value, ESTIMATED

        return value, AVAILABLE
Пример #5
0
    def handle_toronto_impact_condition(impact):
        flag = AVAILABLE
        if is_null_or_empty(impact):
            flag = NOT_AVAILABLE
            return None, flag

        if impact.lower().strip() not in IMPACT_TYPE:
            raise Exception(
                "{} is an invalid/unknown impact variable".format(impact))

        return impact.lower().strip(), flag
Пример #6
0
    def handle_ottawa_light_condition(light):
        flag = AVAILABLE
        if is_null_or_empty(light):
            flag = NOT_AVAILABLE
            return None, flag

        env = light.split('-')
        if env[1].lower().strip() not in VISIBILITY:
            raise Exception(
                "{} is an invalid/unknown visibility variable".format(env[1]))
        return env[1].lower().strip(), flag
Пример #7
0
    def handle_toronto_environment(environment):
        flag = AVAILABLE
        if is_null_or_empty(environment):
            flag = NOT_AVAILABLE
            return None, flag

        if environment.lower().strip() not in ENVIRONMENT:
            raise Exception(
                "{} is an invalid/unknown environment variable".format(
                    environment))
        return environment.lower().strip(), flag
Пример #8
0
    def handle_ottawa_environment(environment):
        flag = AVAILABLE
        if is_null_or_empty(environment):
            flag = NOT_AVAILABLE
            return None, flag

        env = environment.split('-')
        if env[1].lower().strip() not in ENVIRONMENT:
            raise Exception(
                "{} is an invalid/unknown environment variable".format(env[1]))
        return env[1].lower().strip(), flag
Пример #9
0
    def handle_toronto_collision_condition(collision):
        flag = AVAILABLE
        if is_null_or_empty(collision):
            flag = NOT_AVAILABLE
            return None, flag

        if collision.lower().strip() not in COLLISION_CLASSIFICATION:
            raise Exception(
                "{} is an invalid/unknown collision classification variable".
                format(collision))

        return collision.lower().strip(), flag
Пример #10
0
    def handle_toronto_traffic_condition(traffic):
        flag = AVAILABLE
        if is_null_or_empty(traffic):
            flag = NOT_AVAILABLE
            return None, flag

        if traffic.lower().strip() not in TRAFFIC_CONTROL:
            raise Exception(
                "{} is an invalid/unknown traffic control variable".format(
                    traffic))

        return traffic.lower().strip(), flag
Пример #11
0
    def handle_toronto_road_surface_condition(surface):
        flag = AVAILABLE
        if is_null_or_empty(surface):
            flag = NOT_AVAILABLE
            return None, flag

        if surface.lower().strip() not in ROAD_SURFACE:
            raise Exception(
                "{} is an invalid/unknown road surface variable".format(
                    surface))

        return surface.lower().strip(), flag
Пример #12
0
    def handle_accident_data(row, city):
        if city == "Ottawa":
            if is_null_or_empty(row['longitude']):
                raise Exception("Longitude is empty/null")
            if is_null_or_empty(row['latitude']):
                raise Exception("Latitude is empty/null")
            if is_null_or_empty(row['location']):
                raise Exception("Location is empty/null")

            longitude = row['longitude']
            latitude = row['latitude']
            street_name, street1, street2 = LocationDimensionPreStage.parse_ottawa_location(
                row['location'])

            return float(longitude), float(
                latitude), street_name, street1, street2

        elif city == "Toronto":
            if is_null_or_empty(row['longitude']):
                raise Exception("Longitude is empty/null")
            if is_null_or_empty(row['latitude']):
                raise Exception("Latitude is empty/null")
            if is_null_or_empty(row['street1']):
                raise Exception("Street name is empty/null")

            longitude = row['longitude']
            latitude = row['latitude']
            street_name = row['street1']
            street1 = row['street2']

            return float(longitude), float(latitude), street_name, street1
    def handle_location_data(row, city):
        if city == "Ottawa":
            if is_null_or_empty(row['longitude']):
                raise Exception("Longitude is empty/null")
            if is_null_or_empty(row['latitude']):
                raise Exception("Latitude is empty/null")
            if is_null_or_empty(row['location']):
                raise Exception("Location is empty/null")

            longitude = row['longitude']
            latitude = row['latitude']
            street_name, intersection_1, intersection_2 = LocationDimensionPreStage.parse_ottawa_location(
                row['location'])

            return float(longitude), float(
                latitude), street_name, intersection_1, intersection_2

        elif city == "Toronto":
            if is_null_or_empty(row['longitude']):
                raise Exception("Longitude is empty/null")
            if is_null_or_empty(row['latitude']):
                raise Exception("Latitude is empty/null")
            if is_null_or_empty(row['street1']):
                raise Exception("Street name is empty/null")

            longitude = row['longitude']
            latitude = row['latitude']
            street_name = row['street1']
            intersection_1 = row['street2']
            neighbourhood = row['district']

            return float(longitude), float(
                latitude), street_name, intersection_1, neighbourhood
Пример #14
0
    def handle_ottawa_road_surface_condition(surface):
        flag = AVAILABLE
        if is_null_or_empty(surface):
            flag = NOT_AVAILABLE
            return None, flag

        env = surface.split('-')
        if env[1].lower().strip() not in ROAD_SURFACE:
            raise Exception(
                "{} is an invalid/unknown road surface variable".format(
                    env[1]))

        return env[1].lower().strip(), flag
    def handle_station_data(station_name, station_inventory):
        if is_null_or_empty(station_name):
            raise Exception("Station name is empty/null")

        if station_name not in station_inventory:
            raise Exception("Station name does not exist in station inventory")

        station_data = station_inventory.get(station_name)

        longitude = station_data['longitude']
        latitude = station_data['latitude']
        elevation = station_data['elevation']

        if is_null_or_empty(longitude) or is_null_or_empty(latitude):
            raise Exception("Longitude/Latitude is empty/null")

        if is_null_or_empty(elevation):
            raise Exception("Elevation is empty/null")

        return station_name, round(float(longitude),
                                   2), round(float(latitude),
                                             2), round(float(elevation), 2)
Пример #16
0
    def handle_ottawa_impact_condition(impact):
        flag = AVAILABLE
        if is_null_or_empty(impact):
            flag = NOT_AVAILABLE
            return None, flag

        env = impact.split('-')

        if env[1].lower().strip() not in IMPACT_TYPE:
            raise Exception("{} is an invalid/unknown impact variable".format(
                env[1].lower().strip()))

        return env[1].lower().strip(), flag
Пример #17
0
    def handle_ottawa_traffic_condition(traffic):
        flag = AVAILABLE
        if is_null_or_empty(traffic):
            flag = NOT_AVAILABLE
            return None, flag

        env = traffic.split('-')
        if env[1].lower().strip() == "ped. crossover":
            return "pedestrian crossover", AVAILABLE

        if env[1].lower().strip() not in TRAFFIC_CONTROL:
            raise Exception(
                "{} is an invalid/unknown traffic control variable".format(
                    env[1]))

        return env[1].lower().strip(), flag
Пример #18
0
    def handle_ottawa_collision_condition(collision):
        flag = AVAILABLE
        if is_null_or_empty(collision):
            flag = NOT_AVAILABLE
            return None, flag

        r = re.compile(r"^([^-]+)-")
        env = r.split(collision)

        if env[-1].lower().strip() == "fatal injury":
            env[-1] = "fatal"

        if env[-1].lower().strip() not in COLLISION_CLASSIFICATION:
            raise Exception(
                "{} is an invalid/unknown collision classification variable".
                format(env[-1].lower().strip()))

        return env[-1].lower().strip(), flag
Пример #19
0
    def handle_toronto_date_and_time(date):
        if is_null_or_empty(date):
            raise Exception("Date is empty/null")

        date_time = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ")
        return date_time, date_time
    def handle_date_time(date_time):
        if is_null_or_empty(date_time):
            raise Exception("Date is empty/null")

        return datetime.strptime(date_time, '%Y-%m-%d %H:%M')