-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_plot.py
More file actions
120 lines (92 loc) · 3.48 KB
/
map_plot.py
File metadata and controls
120 lines (92 loc) · 3.48 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from gmplot import gmplot
import os
import numpy
import random
import math
def getPath():
pathToFolder = "DataMules/Lexington/50/1/Day1"
def findfiles(directory):
objects = os.listdir(directory) # find all objects in a dir
files = []
for i in objects: # check if very object in the folder ...
if isFile(directory + i): # ... is a file.
files.append(i) # if yes, append it.
return files
def isFile(object):
try:
os.listdir(object) # tries to get the objects inside of this object
return False # if it worked, it's a folder
except Exception: # if not, it's a file
return True
def readFile(fileName):
currPath = []
with open(fileName) as f:
listOfLines = f.readlines()[1:]
count = 0
for line in listOfLines:
lineStr = line.strip()
lineStr = lineStr.split()
# if count%2 == 0:
# print(lineStr[3])
# if(float(lineStr[0]) >= 840) and float(lineStr[0]) <= 1020:
if (float(lineStr[0]) >= 660) and float(lineStr[0]) <= 840:
# if (float(lineStr[0]) >= 0):
currPath.append((float(lineStr[2]), float(lineStr[3])))
count += 1
# with open("UMASS/" + busName + ".txt", "a") as fw:
# newStr = lineStr[1] + " , " + lineStr[2]
# fw.write( newStr + "\n")
# count = count + 1
# fw.close()
f.close()
return currPath
allPaths = []
#NOTE: RUN THIS ONE TIME
directory = "DataMules/UMass/2007-11-06/1/"
#generateData(directory)
#
# folders = findfiles(directory)
# folders.sort()
#
# folderLen = len(folders)
#print("All folders: " + str(folders))
# curr = os.getcwd()
# if ".DS_Store" not in folders:
# print("Current Folder " + folders[ind])
# print("Folder is: " + str(folders[ind]))
currFiles = findfiles(directory)
currFiles.sort()
print(currFiles)
# For all days
allPaths = []
numOfFiles = len(currFiles)
#For each day
for fInd in range(0, numOfFiles):
filePath = directory + "/" + currFiles[fInd]
if currFiles[fInd] not in ["0.txt", "1.txt", "2.txt", "3.txt", "4.txt", "5.txt", "6.txt", "7.txt", "8.txt"]:
# if currFiles[fInd] in ["16.txt"]:
currPath = readFile(filePath)
allPaths.append(currPath)
# import pygmaps
# Place map
gmap = gmplot.GoogleMapPlotter(42.393658, -72.53295, 12)
# gmap = pygmaps.maps(42.340382, -72.496819, 15)
# 0 1 2 3 4 5 6 7 8 9 10
#Lime Gold Dark Red Deep Pink Forest Green Blue Black Chocolate Magneta Royal blue Brown
colors = ['#00FF00', '#FFD700', '#8B0000', '#FF1493', '#228B22', '#0000FF', '#000000', '#A52A2A', '#FF0000', '#00008B', '#4169E1','#00008B', '#4169E1'] #, '#8B008B', '#4169E1','#FF0000' ]
count = 0
if not os.path.exists("HTML"):
os.makedirs("HTML")
os.chdir("HTML")
for pInd in range(len(allPaths)):
# gmap = gmplot.GoogleMapPlotter(42.393658, -72.53295, 12)
# if pInd == 1 or pInd == 4 or pInd == 6 : #or pInd == 6 or pInd > 0
# print(str(pInd) + " " + str(len(allPaths[pInd])) + " " + str(allPaths[pInd]))
path_lats, path_lons = zip(* allPaths[pInd])
colorInd = int(pInd)
# print ("index: ", colorInd)
gmap.scatter(path_lats, path_lons, colors[colorInd], size=60, marker=False)
# Draw
# gmap.draw(str(pInd) + "_" + "round1.html")
# os.chdir(curr)
gmap.draw("test.html")