コード例 #1
0
def addPollutionLeveltoRoutes(routes, hour_offset):
    for route in routes:
        route['pollution'] = 0
        length = len(route['coords'])
        # Pollution due to weather data + traffic data
        for i in [
                0, length / 2, length - 1
        ]:  # First, middle, and last point (for these points traffic data is calculated twice
            #  but this fine since the user might be standing there for a bit of time)
            route['pollution'] += pollution.get_pollution_value(
                route['coords'][i][0], route['coords'][i][1], hour_offset)
        # Pollution due to traffic data, sample size = min(MAX_SIMPE_SIZE, length/SAMPLE_POINT_STEP)
        for i in xrange(
                0, length, SAMPLE_POINT_STEP if length <
            (SAMPLE_POINT_STEP * MAX_SAMPLE_SIZE) else length /
                MAX_SAMPLE_SIZE):
            route['pollution'] += traffic.get_traffic_data(
                route['coords'][i][0], route['coords'][i][1])
コード例 #2
0
def addPollutionLeveltoRoutes(routes, hour_offset):
    for route in routes:
        route["pollution"] = 0
        length = len(route["coords"])
        # Pollution due to weather data + traffic data
        for i in [
            0,
            length / 2,
            length - 1,
        ]:  # First, middle, and last point (for these points traffic data is calculated twice
            #  but this fine since the user might be standing there for a bit of time)
            route["pollution"] += pollution.get_pollution_value(
                route["coords"][i][0], route["coords"][i][1], hour_offset
            )
        # Pollution due to traffic data, sample size = min(MAX_SIMPE_SIZE, length/SAMPLE_POINT_STEP)
        for i in xrange(
            0, length, SAMPLE_POINT_STEP if length < (SAMPLE_POINT_STEP * MAX_SAMPLE_SIZE) else length / MAX_SAMPLE_SIZE
        ):
            route["pollution"] += traffic.get_traffic_data(route["coords"][i][0], route["coords"][i][1])
コード例 #3
0
ファイル: fusion.py プロジェクト: bakshi41c/luftwagen-backend
def main():
    london_x1 = 51.700559
    london_y1 = -0.497709

    london_x2 = 51.308527
    london_y2 = 0.246893

    big_tile = tiles.Tile(london_x1, london_y1, london_x2, london_y2)
    smaller_tiles = tiles.fragment_tile(big_tile, tiles.m_to_lat(200),
                                        tiles.m_to_lon(200 / 3, london_x1))

    filename = 'fusion.csv'

    done_tiles = {}

    for i in xrange(len(smaller_tiles)):
        done_tiles[i] = -1.0

    for i in xrange(len(smaller_tiles)):
        tile = smaller_tiles[i]
        key = tile.key

        if done_tiles[key] >= 0:
            continue

        pollution_value = pollution.get_pollution_value(
            tile.start_x, tile.start_y, 0)

        done_tiles[key] = pollution_value

        neighbour_keys = [
            key + 1, key - 1, (key + 169), (key - 169), (key + 170),
            (key + 168), (key - 170), (key - 168)
        ]

        weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for j in xrange(len(neighbour_keys)):
            index = neighbour_keys[j]

            if 0 < index < len(smaller_tiles):
                if done_tiles[index] >= 0:
                    done_tiles[index] = (done_tiles[index] +
                                         (weights[j] * pollution_value)) / 2.0
                else:
                    done_tiles[index] = weights[j] * pollution_value

        print "Progress: " + str(i) + "/" + str(len(smaller_tiles))

    with open(filename, 'w') as f:
        for tile in smaller_tiles:
            line = "\"" + tile.kml() + "\"" + ", " + str(
                done_tiles[tile.key]) + ", " + str(tile.key) + "\n"
            f.write(line)

    success = False
    tries = 0
    while (success is False) and tries < 3:
        tries += 1
        try:
            print "Try no:" + str(tries) + " to update table"
            update_table(filename)
            success = True
        except Exception:
            print "Failed to update table"

    if success:
        print "Last fusion update: " + str(datetime.datetime.now())
コード例 #4
0
ファイル: fusion.py プロジェクト: bakshi41c/luftwagen-backend
def main():
    london_x1 = 51.700559
    london_y1 = -0.497709

    london_x2 = 51.308527
    london_y2 = 0.246893

    big_tile = tiles.Tile(london_x1, london_y1, london_x2, london_y2)
    smaller_tiles = tiles.fragment_tile(big_tile, tiles.m_to_lat(200), tiles.m_to_lon(200 / 3, london_x1))

    filename = 'fusion.csv'

    done_tiles = {}

    for i in xrange(len(smaller_tiles)):
        done_tiles[i] = -1.0

    for i in xrange(len(smaller_tiles)):
        tile = smaller_tiles[i]
        key = tile.key

        if done_tiles[key] >= 0:
            continue

        pollution_value = pollution.get_pollution_value(tile.start_x, tile.start_y, 0)

        done_tiles[key] = pollution_value

        neighbour_keys = [key + 1, key - 1, (key + 169), (key - 169), (key + 170), (key + 168), (key - 170),
                          (key - 168)]

        weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for j in xrange(len(neighbour_keys)):
            index = neighbour_keys[j]

            if 0 < index < len(smaller_tiles):
                if done_tiles[index] >= 0:
                    done_tiles[index] = (done_tiles[index] + (weights[j] * pollution_value)) / 2.0
                else:
                    done_tiles[index] = weights[j] * pollution_value

        print "Progress: " + str(i) + "/" + str(len(smaller_tiles))

    with open(filename, 'w') as f:
        for tile in smaller_tiles:
            line = "\"" + tile.kml() + "\"" + ", " + str(done_tiles[tile.key]) + ", " + str(tile.key) + "\n"
            f.write(line)

    success = False
    tries = 0
    while (success is False) and tries < 3:
        tries += 1
        try:
            print "Try no:" + str(tries) + " to update table"
            update_table(filename)
            success = True
        except Exception:
            print "Failed to update table"

    if success:
        print "Last fusion update: " + str(datetime.datetime.now())