-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.py
executable file
·57 lines (50 loc) · 1.96 KB
/
map.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
'''
Traveling Baseball Fan Problem
Author: Sertalp B. Cay
This file plots the route to the html using folium package and Leaflet
javascript library. The same code is also used in Jupyter notebook.
'''
import os, glob
import folium
import datetime
def plot_tbf(route, name='latest'):
# Start map centered in US
tbfmap = folium.Map(location=[39.82, -98.58], zoom_start=4, tiles="OpenStreetMap")
# Define the popup markers
for node in route:
print(node)
dt = datetime.datetime.strptime(node[5], '%Y-%m-%d %H:%M:%S')
dt_text = dt.strftime("%A, %B %d, %Y - %I:%M %p") + ' (ET)'
popup_text = '''<div>
Game {}: {} @ {}<br>
{}, {}<br>
{}</div>
'''.format(node[0], node[2], node[3], node[1], node[4],
dt_text)
popup_html = folium.Popup(popup_text, min_width=200, max_width=250)
folium.Marker(location=[float(node[7]), float(node[6])], popup=popup_html,
icon=folium.DivIcon(html='<i class="fa fa-map-pin fa-stack-2x"></i><strong style="text-align: center; color: white; font-family: Trebuchet MS;" class="fa-stack-1x">{}</strong>'.format(node[0]))
).add_to(tbfmap)
# Add the lines between stadiums
lines = folium.PolyLine(locations=[(float(i[7]), float(i[6])) for i in route])
lines.add_to(tbfmap)
# Print maps to html
tbfmap.save("maps/{}.html".format(name))
def read_schedule(f):
schd = []
resfile = open(f, 'r')
for line in resfile:
if 'schd' in line:
for visit in resfile:
if ']' not in visit:
items = visit.split(',')
items = [i.replace('\n', '') for i in items]
schd.append(items)
resfile.close()
return schd
if __name__ == '__main__':
files = glob.glob("results/*.txt")
files.sort(key=os.path.getmtime)
for i, f in enumerate(files):
schd = read_schedule(f)
plot_tbf(schd, i+1)