View the best links on the top

Sort links.csv by link quality
This commit is contained in:
Dominik Heidler 2016-03-10 13:56:06 +01:00
parent af2a80f5ee
commit 5d59a208bb
1 changed files with 7 additions and 1 deletions

View File

@ -32,6 +32,7 @@ def update_mapnik_csv():
with open(os.path.join(CONFIG["csv_dir"], "links.csv"), "w") as csv:
csv.write("WKT,quality\n")
links = []
for router in db.routers.find(
{
"position.coordinates": {"$exists": True},
@ -42,13 +43,15 @@ def update_mapnik_csv():
):
for neighbour in router["neighbours"]:
if "position" in neighbour:
csv.write("\"LINESTRING (%f %f,%f %f)\",%i\n" % (
links.append((
router["position"]["coordinates"][0],
router["position"]["coordinates"][1],
neighbour["position"]["coordinates"][0],
neighbour["position"]["coordinates"][1],
neighbour["quality"]
))
for link in sorted(links, key=lambda l: l[4]):
csv.write("\"LINESTRING (%f %f,%f %f)\",%i\n" % link)
with open(os.path.join(CONFIG["csv_dir"], "hood-points.csv"), "w", encoding="UTF-8") as csv:
csv.write("lng,lat,name\n")
@ -119,3 +122,6 @@ def update_mapnik_csv():
# touch mapnik XML files to trigger tilelite watcher
touch("/usr/share/ffmap/hoods.xml")
touch("/usr/share/ffmap/links_and_routers.xml")
if __name__ == '__main__':
update_mapnik_csv()