aboutsummaryrefslogtreecommitdiff
path: root/dev/cluster.py
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-06-06 12:44:37 -0600
committerMelody Horn <melody@boringcactus.com>2020-06-06 12:44:37 -0600
commit48ebef95cfc26aae3fcef1174f4eaeb71ca491fe (patch)
tree4a8817fcfda72182b607d184ef192ca8ceef5a36 /dev/cluster.py
parent4127ae91822f9abeffeb614e95b6f9d832ecf7c6 (diff)
downloadpig.observer-48ebef95cfc26aae3fcef1174f4eaeb71ca491fe.tar.gz
pig.observer-48ebef95cfc26aae3fcef1174f4eaeb71ca491fe.zip
make a whole pile of things more good
Diffstat (limited to 'dev/cluster.py')
-rw-r--r--dev/cluster.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/dev/cluster.py b/dev/cluster.py
new file mode 100644
index 0000000..b43e63c
--- /dev/null
+++ b/dev/cluster.py
@@ -0,0 +1,40 @@
+import sys
+import math
+import json
+
+with open(sys.argv[1], 'r') as f:
+ input_data = json.load(f)
+
+
+def dist(a, b):
+ return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
+
+
+def do_merge():
+ threshold = 0.003
+
+ for a in range(len(input_data) - 1):
+ if len(input_data[a]['cams']) == 0:
+ continue
+ for b in range(a + 1, len(input_data)):
+ if len(input_data[b]['cams']) == 0:
+ continue
+ a_loc = input_data[a]['coord']
+ b_loc = input_data[b]['coord']
+ if dist(a_loc, b_loc) < threshold:
+ input_data[a]['cams'].extend(input_data[b]['cams'])
+ input_data[b]['cams'] = []
+
+ output_data = [x for x in input_data if len(x['cams']) > 0]
+
+ with open(sys.argv[1], 'w') as f:
+ json.dump(output_data, f)
+
+
+def find_closest():
+ closest_dist = min(dist(input_data[a]['coord'], input_data[b]['coord'])
+ for a in range(len(input_data) - 1) for b in range(a + 1, len(input_data)))
+ print(closest_dist)
+
+
+do_merge()