-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotter.py
executable file
·87 lines (70 loc) · 1.78 KB
/
dotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
# Dots, not lines. First thing I wrote, not very exciting so I don't
# think I'll work on it any further.
import collections
import operator
import sys
from geopy import distance
import plot1090
MUL=16
misc = {}
top = collections.defaultdict(lambda: 0)
for line in sys.stdin.xreadlines():
l = line.split(",")
try:
lat, lon = float(l[14]), float(l[15])
except (IndexError, ValueError):
continue
top[(int(lat*MUL+.5),int(lon*MUL+.5))] += 1
s = list(top.items())
s.sort(key=operator.itemgetter(1))
misc.update({
"center": {
"lat": float(s[-1][0][0]) / MUL,
"lng": float(s[-1][0][1]) / MUL,
},
"maxcount": s[-1][1],
})
# Number of meters for a dot at maxcount, which will be the approximate
# distance between centers of dots
hot = (misc["center"]["lat"], misc["center"]["lng"])
maxm = distance.distance(hot, (hot[0] + (1.0 / MUL), hot[1])).m / 2
misc.update({
"maxm": int(maxm),
"step": int(maxm / s[-1][1]),
})
#print "Lo %d Hi %d" % (s[0][1], s[-1][1])
#print len(s)
# Now sort it by position which I guess looks a little nicer.
#s = s[-100:]
s.sort()
spots = []
for block, count in s:
latlon = tuple((float(x) / MUL) for x in block)
spots.append({
"center": dict(zip(["lat", "lng"], latlon)),
"count": count,
})
plot1090.write_html({
"hotspots": spots,
"d": misc,
}, """
for (spot of hotspots) {
var radius = Math.min(spot.count*d.step*2.2, d.maxm);
var colour;
if (spot.count > (d.maxcount / 2)) {
var red = Math.round(Math.max(17, -102 + 357 * (spot.count / d.maxcount)));
var colour = '#' + red.toString(16) + '1111';
} else {
var colour = '#111111';
}
var circle = new google.maps.Circle({
strokeWeight: 0,
fillColor: colour,
fillOpacity: 0.35,
map: map,
center: spot.center,
radius: radius
});
}
""", "dot1090")