-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.py
More file actions
49 lines (44 loc) · 1.57 KB
/
Copy pathdraw.py
File metadata and controls
49 lines (44 loc) · 1.57 KB
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
import gmplot
import csv
import ast
def draw_trip(timeseries, name):
longs = []
lats = []
for point in timeseries:
longs.append(float(point[1]))
lats.append(float(point[2]))
gmap = gmplot.GoogleMapPlotter(lats[0], longs[0], 12)
gmap.plot(lats, longs, 'cornflowerblue', edge_width=6)
gmap.draw('maps/map_' + str(name) + '.html')
def draw_overlapping_trips(timeseries1, timeseries2, name):
longs1 = []
lats1 = []
for point in timeseries1:
longs1.append(float(point[1]))
lats1.append(float(point[2]))
longs2 = []
lats2 = []
for point in timeseries2:
longs2.append(float(point[1]))
lats2.append(float(point[2]))
gmap = gmplot.GoogleMapPlotter(lats1[0], longs1[0], 12)
gmap.plot(lats1, longs1, 'green', edge_width=6)
gmap.plot(lats2, longs2, 'red', edge_width=3)
gmap.draw('maps/overlap_' + str(name) + '.html')
def draw_n_trips(N):
with open('datasets/tripsClean.csv', 'r') as inputFile:
next(inputFile) # skip header
dataReader = csv.reader(inputFile, delimiter=';')
i = 0
journeyPatternIDdict = {}
for row in dataReader:
journeyPatternID = row[1]
# if trip exists, choose another one
if journeyPatternID in journeyPatternIDdict:
continue
if i >= N: # if already drawn N trips, break
break
journeyPatternIDdict[journeyPatternID] = 1
timeseries = ast.literal_eval(row[2])
draw_trip(timeseries, journeyPatternID)
i += 1