def checkDistances(path, outputPath):
    with open(path + "stations.json", "r") as f:
        stations = json.load(f)

    with open(path + "suggestions.json", "r") as f:
        suggestions = json.load(f)

    numStations = len(stations)
    print numStations, "actual stations"
    print len(suggestions), "suggested stations"
    updateEvery = numStations / 100
    stationsSoFar = 0

    allDists = {}

    for station in stations:
        stationsSoFar += 1
        if stationsSoFar % updateEvery == 0:
            sys.stdout.write(
                "Creating lengths structure: %d%%        \r" % (int(float(stationsSoFar) / numStations * 100))
            )
            sys.stdout.flush()

        alat = float(station["lat"])
        alon = float(station["lon"])
        # print actualStation["id"]

        for suggestion in suggestions:
            slat = float(suggestion["lat"])
            slon = float(suggestion["lon"])

            dist = getDist(alat, alon, slat, slon)

            if dist < 0.4:
                if not suggestion["id"] in allDists:
                    allDists[suggestion["id"]] = {}
                    allDists[suggestion["id"]]["votes"] = suggestion["votes"]
                    allDists[suggestion["id"]]["dists"] = {}
                allDists[suggestion["id"]]["dists"][station["id"]] = dist

    print

    end = clock()

    print "Took", end - start, "seconds"

    if not os.path.exists(outputPath):
        os.mkdir(outputPath)

    with open(outputPath + "lengthsStructure.json", "w") as f:
        json.dump(allDists, f)
Exemple #2
0
	east = -73.693398
elif city == "dc":
	north = 39.210975
	west = -77.454987
	south = 38.694085
	east = -76.811128

#from bottom-left to top-right
# spaceVert = (north-south)/vertInc
# spaceHoriz = (east-west)/horizInc

iterations = 40
spaceVert = (north-south)/2
vertChange = (north-south)/2
for i in range(iterations):
	dist = getDist(south, west, south+spaceVert, west)
	if dist > gridSize:
		spaceVert -= vertChange
	elif dist < gridSize:
		spaceVert += vertChange
	else:
		break
	vertChange /= 2
	
spaceHoriz = (east-west)/2
horizChange = (east-west)/2
for i in range(iterations):
	dist = getDist(south, west, south, west+spaceHoriz)
	if dist > gridSize:
		spaceHoriz -= horizChange
	elif dist < gridSize: