-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgps_plot.py
79 lines (69 loc) · 2.48 KB
/
gps_plot.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
from geopy.distance import vincenty
import ast
from iss4e.webike.trips.auxiliary import DateTime
from scipy import stats
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
def read (file_name):
with open(file_name, mode='r') as file:
return ast.literal_eval(file.read())
fgps = read("data/fgps")
mgps = read("data/mgps")
staffgps = read("data/staffgps")
studentsgps = read("data/studentsgps")
def get_average_speed(gps_by_trips):
speeds = []
for trip in gps_by_trips:
t_tot = 0
d_tot = 0
if(len(trip) <5):
continue
for i in range(len(trip) - 1):
t = (DateTime(trip[i + 1]["time"]) - DateTime(trip[i]["time"])).total_seconds()
if(t !=0):
d = vincenty((trip[i]["latitude"], trip[i]["longitude"]),
(trip[i + 1]["latitude"], trip[i + 1]["longitude"])).m
if(d/t*3.6 > 3 and d/t*3.6 < 60):
t_tot +=t
d_tot += d
if(trip and t_tot > 0):
speeds.append(d_tot/t_tot*3.6)
return speeds
fspeed = get_average_speed(fgps)
mspeed = get_average_speed(mgps)
staffspeed = get_average_speed(staffgps)
studentsspeed = get_average_speed(studentsgps)
bins = np.arange(0,61,2.5)
figsize=(4,2.5)
dpi=720
fig1 = plt.figure(figsize=figsize, dpi=dpi)
print(stats.ranksums(fspeed, mspeed))
plt.hist([fspeed,mspeed], bins=bins,normed=True, label=["female", "male"])
print("mean: {mean}".format(mean=np.mean(fspeed)))
print("mean: {mean}".format(mean=np.mean(mspeed)))
plt.xlabel("speed (kph)")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("speed_by_gender.png")
fig2 = plt.figure(figsize=figsize, dpi=dpi)
print(stats.ranksums(staffspeed, studentsspeed))
plt.hist([staffspeed, studentsspeed],bins=bins, normed=True, label=["staff/faculty","students"])
print("mean: {mean}".format(mean=np.mean(staffspeed)))
print("mean: {mean}".format(mean=np.mean(studentsspeed)))
plt.xlabel("speed (kph)")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("speed_by_occupation.png")
fig3 = plt.figure(figsize=figsize, dpi=dpi)
plt.hist(fspeed+mspeed, bins=bins, normed=True, rwidth=0.9, label="all participants")
plt.xlabel("speed (kph)")
plt.ylabel("probability density")
print("mean: {mean}".format(mean=np.mean(fspeed+mspeed)))
print("std: {std}".format(std=np.std(fspeed+mspeed)))
plt.legend()
plt.tight_layout()
plt.savefig("speed_all.png")