More seeds:
[ottawa-travel-planner.git] / analyzeStops.py
blobd21b259948016e00e882fc1cb24c5f26227cf294
1 #!/usr/bin/python
2 # vi: set softtabstop=4 shiftwidth=4 tabstop=8 expandtab:
4 """Thinky thinky"""
6 import pickle
7 import BusStopMashup
8 from LatLongTools import *
10 def analyze(stoplist):
11 home = [stop for stop in stoplist
12 if isinstance(stop, BusStopMashup.HomeLocation)][0]
14 westiest = min(stop.location.longitude for stop in stoplist)
15 eastiest = max(stop.location.longitude for stop in stoplist)
16 northiest = min(stop.location.latitude for stop in stoplist)
17 southiest = max(stop.location.latitude for stop in stoplist)
19 print "\twest-east distance: %f" % (eastiest - westiest)
20 print "\twest-east distance: %f km" % longdist(home.location.latitude,
21 eastiest, westiest)
22 print "\tnorth-south distance: %f" % (southiest - northiest)
23 print "\tnorth-south distance: %f km" % latdist(southiest, northiest)
25 maxdist = 0.0
26 for stop in stoplist:
27 dist = locdist(stop.location, home.location)
28 if dist > maxdist:
29 maxdist = dist
31 print "\tMax dist from home: %f km" % maxdist
33 print "\tDegree dist from home: %f N, %f S, %f W, %f E" % (
34 home.location.latitude - northiest,
35 southiest - home.location.latitude,
36 home.location.longitude - westiest,
37 eastiest - home.location.longitude)
39 if __name__ == '__main__':
40 filename = "grabs/stoplocations.pickle"
41 try:
42 datapoints = pickle.load(open(filename, "r"))
43 except IOError, e:
44 c = BusStopMashup.Client()
45 datapoints = {}
46 for k in ('41 antares', 'heron & data centre', 'kent & albert',
47 'carling & preston', 'bank & florence'):
48 datapoints[k] = list(c.findStops(k))
50 f = open(filename, "w")
51 pickle.dump(datapoints, f)
52 f.close()
53 for k in datapoints:
54 print k
55 analyze(datapoints[k])