From 4130b90e4e52626024f557978e62f9811fff65b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20M=C3=BCnch?= Date: Sun, 26 Jan 2020 23:30:03 +0100 Subject: [PATCH] joa stuff ne --- germany.svg | 77 ++++++++++++++++++++++++++++++++++++++++++++ get_coordinates.py | 59 +++++++++++++++++++++++++++------ svgwrite-example.svg | 2 +- 3 files changed, 127 insertions(+), 11 deletions(-) create mode 100644 germany.svg diff --git a/germany.svg b/germany.svg new file mode 100644 index 0000000..e109b03 --- /dev/null +++ b/germany.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/get_coordinates.py b/get_coordinates.py index 186c30e..e63184b 100755 --- a/get_coordinates.py +++ b/get_coordinates.py @@ -1,14 +1,38 @@ #!/usr/bin/python -import requests, json, pickle, os.path, svgwrite +import requests, json, pickle, os.path, svgwrite, math URL = "https://directory.spaceapi.io/" NORTHERNMOST = 55.05 EASTERNMOST = 15.033333 SOUTHERNMOST = 47.270108 WESTERNMOST = 5.866667 +threshold = 0.10 YSPAN = NORTHERNMOST - SOUTHERNMOST XSPAN = EASTERNMOST - WESTERNMOST locations = {} +blacklist = ["Chaostreff Salzburg", "DevLoL", "CCC Basel", "Chaostreff Zürich", "ChaosStuff"] + +def dist(n1, n2): + y = n1[0] - n2[0] + x = n1[1] - n2[1] + return math.sqrt(math.pow(x, 2) + math.pow(y, 2)) + +def conflict(targetlist, node): + returner = None + for element in targetlist: + if dist(node, targetlist[element]) < threshold: + returner = element + continue + return returner + +def merge(n1, n2): + lat = (n1[0] + n2[0]) / 2 + lon = (n1[1] + n2[1]) / 2 + returner = [] + returner.append(lat) + returner.append(lon) + return returner + if os.path.isfile('locations.bin'): print ("using offline data...") with open("locations.bin", "rb") as f: @@ -42,22 +66,37 @@ german_locations = locations.copy() for space in locations: if locations[space][0] > NORTHERNMOST: del german_locations[space] - print ("kicked " + space + " too far north") elif locations[space][0] < SOUTHERNMOST: del german_locations[space] - print ("kicked " + space + " too far south") elif locations[space][1] < WESTERNMOST: del german_locations[space] - print ("kicked " + space + " too far west") elif locations[space][1] > EASTERNMOST: del german_locations[space] - print ("kicked " + space + " too far east") +for space in blacklist: + del german_locations[space] + + +finallist = {} +while german_locations: + n1 = next(iter(german_locations)) + conflictnode = conflict(finallist, german_locations[n1]) + if conflictnode == None: + finallist.update({n1 : german_locations[n1]}) + del german_locations[n1] + else: + mergenode = merge(german_locations[n1], finallist[conflictnode]) + del german_locations[n1] + del finallist[conflictnode] + german_locations.update({"MERGED: " + n1 + " " + conflictnode : mergenode}) + +for space in finallist: + print(space + " " + str(finallist[space][0]) + " " + str(finallist[space][1])) dwg = svgwrite.Drawing('svgwrite-example.svg', profile='tiny') -dwg.add(svgwrite.image.Image(href="Karte_Deutschland.svg", size=(572,770))) +#dwg.add(svgwrite.image.Image(href="Karte_Deutschland.svg", size=(586, 793))) dwg.add(dwg.circle(center=(0,0), r=3, fill='black')) -for space in german_locations: - ypoint = (770 - (((german_locations[space][0] - SOUTHERNMOST) / YSPAN)* 770)) - dwg.add(dwg.circle(center=(((locations[space][1] - WESTERNMOST) / XSPAN) * - 572, ypoint), r=1, fill='black')) +for space in finallist: + ypoint = (793 - (((finallist[space][0] - SOUTHERNMOST) / YSPAN)* 793)) + dwg.add(dwg.circle(center=(((finallist[space][1] - WESTERNMOST) / XSPAN) * + 586, ypoint), r=5, fill='green')) dwg.save() diff --git a/svgwrite-example.svg b/svgwrite-example.svg index 9687f50..e3e1c2e 100644 --- a/svgwrite-example.svg +++ b/svgwrite-example.svg @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file