aboutsummaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/atlanta/cctv.json (renamed from dev/georgia/cctv.json)0
-rw-r--r--dev/atlanta/convert.py (renamed from dev/georgia/convert.py)10
-rw-r--r--dev/cluster.py40
-rw-r--r--dev/slc/UtahKML.xml (renamed from dev/utah/UtahKML.xml)0
-rw-r--r--dev/slc/cameras.json (renamed from dev/utah/cameras.json)0
-rw-r--r--dev/slc/convert.py (renamed from dev/utah/convert.py)15
6 files changed, 64 insertions, 1 deletions
diff --git a/dev/georgia/cctv.json b/dev/atlanta/cctv.json
index 8493f47..8493f47 100644
--- a/dev/georgia/cctv.json
+++ b/dev/atlanta/cctv.json
diff --git a/dev/georgia/convert.py b/dev/atlanta/convert.py
index 37a9e56..4d907b6 100644
--- a/dev/georgia/convert.py
+++ b/dev/atlanta/convert.py
@@ -1,6 +1,14 @@
import json
+import math
from pprint import pprint
+CENTER = [33.85, -84.43]
+
+
+def dist(a, b):
+ return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
+
+
with open('cctv.json', 'r') as f:
raw_data = json.load(f)
@@ -9,6 +17,8 @@ cameras = raw_data['features']
sources = []
for camera in cameras:
coord = [float(x) for x in reversed(camera['geometry']['coordinates'])]
+ if dist(coord, CENTER) > 0.4:
+ continue
cam = dict()
cam['id'] = camera['properties']['cctv_id']
if 'HLS' in camera['properties']:
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()
diff --git a/dev/utah/UtahKML.xml b/dev/slc/UtahKML.xml
index e407739..e407739 100644
--- a/dev/utah/UtahKML.xml
+++ b/dev/slc/UtahKML.xml
diff --git a/dev/utah/cameras.json b/dev/slc/cameras.json
index 852fdce..852fdce 100644
--- a/dev/utah/cameras.json
+++ b/dev/slc/cameras.json
diff --git a/dev/utah/convert.py b/dev/slc/convert.py
index 763bc39..30f5a8d 100644
--- a/dev/utah/convert.py
+++ b/dev/slc/convert.py
@@ -1,8 +1,15 @@
import json
-from collections import defaultdict
+import math
import xml.etree.ElementTree as ET
from pprint import pprint
+CENTER = [40.75, -111.89]
+
+
+def dist(a, b):
+ return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
+
+
info = dict()
for place in ET.parse('UtahKML.xml').findall('.//{*}Placemark'):
cam_id = place.attrib['id']
@@ -13,12 +20,18 @@ for place in ET.parse('UtahKML.xml').findall('.//{*}Placemark'):
sources = []
with open('cameras.json', 'r') as f:
places = json.load(f)
+ids_done = set()
for place in places:
cam_id = str(place['entityId'])
+ if cam_id in ids_done:
+ continue
url = place['url']
this_info = info[cam_id]
name = this_info['name']
coord = this_info['coord']
+ if dist(coord, CENTER) > 0.3:
+ continue
sources.append({'coord': coord, 'cams': [{'id': cam_id, 'url': url, 'name': name}]})
+ ids_done.add(cam_id)
with open('sources.json', 'w') as f:
json.dump(sources, f)