-
Notifications
You must be signed in to change notification settings - Fork 0
/
charging_plots.py
135 lines (112 loc) · 5.33 KB
/
charging_plots.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import ast
from scipy import stats
import matplotlib
import webike.data.SoC as soc
from iss4e.webike.trips.auxiliary import DateTime
import trip_plots
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from pytz import timezone
eastern = timezone('Canada/Eastern')
def to_datetime(time):
return DateTime(time)._datetime.replace(tzinfo=timezone('UTC')).astimezone(eastern)
with open("data/fstaff_charging", mode='r') as file:
fstaff = [ast.literal_eval(line) for line in file.read().splitlines()]
for line in fstaff:
line["time"] = to_datetime(line["time"])
with open("data/mstaff_charging", mode='r') as file:
mstaff = [ast.literal_eval(line) for line in file.read().splitlines()]
for line in mstaff:
line["time"] = to_datetime(line["time"])
with open("data/fstuds_charging", mode='r') as file:
fstuds = [ast.literal_eval(line) for line in file.read().splitlines()]
for line in fstuds:
line["time"] = to_datetime(line["time"])
with open("data/mstuds_charging", mode='r') as file:
mstuds = [ast.literal_eval(line) for line in file.read().splitlines()]
for line in mstuds:
line["time"] = to_datetime(line["time"])
fcharge = fstuds + fstaff
mcharge = mstuds + mstaff
staff = fstaff + mstaff
students = fstuds + mstuds
print("no. charges: {charge}".format(charge=str(len(staff + students))))
print("no. charges male: {charge}".format(charge=str(len(mcharge))))
print("no. charges female: {charge}".format(charge=str(len(fcharge))))
print("no. charges staff: {charge}".format(charge=str(len(staff))))
print("no. charges students: {charge}".format(charge=str(len(students))))
print("avg no. charges: {charge}".format(charge=str(
len(staff + students) / (
len(trip_plots.male_staff) + len(trip_plots.male_students) + len(trip_plots.female_staff) + len(
trip_plots.female_students)))))
print("avg no. charges male: {charge}".format(
charge=str(len(mcharge) / (len(trip_plots.male_staff) + len(trip_plots.male_students)))))
print("avg no. charges female: {charge}".format(
charge=str(len(fcharge) / (len(trip_plots.female_staff) + len(trip_plots.female_students)))))
print("avg no. charges staff: {charge}".format(
charge=str(len(staff) / (len(trip_plots.female_staff) + len(trip_plots.male_staff)))))
print("avg no. charges students: {charge}".format(
charge=str(len(students) / (len(trip_plots.male_students) + len(trip_plots.female_students)))))
print("no. trips per charge: {charge}".format(
charge=str(len(trip_plots.staff + trip_plots.students) / len(staff + students))))
print("no. trips per charge male: {charge}".format(charge=str(len(trip_plots.mtrips) / len(mcharge))))
print("no. trips per charge female: {charge}".format(charge=str(len(trip_plots.ftrips) / len(fcharge))))
print("no. trips per charge staff: {charge}".format(charge=str(len(trip_plots.staff) / len(staff))))
print("no. trips per charge students: {charge}".format(charge=str(len(trip_plots.students) / len(students))))
figsize = (4,2.5)
dpi=720
fig1 = plt.figure(figsize=figsize, dpi=dpi)
data = [[entry["time"].hour for entry in fcharge], [entry["time"].hour for entry in mcharge]]
print(stats.ranksums(data[0], data[1]))
plt.hist(data, bins=range(0, 25), normed=True, label=["female", "male"])
plt.xticks(range(0, 24, 2))
plt.xlabel("hour of day")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_by_gender.png")
fig2 = plt.figure(figsize=figsize, dpi=dpi)
data = [[entry["time"].hour for entry in staff], [entry["time"].hour for entry in students]]
print(stats.ranksums(data[0], data[1]))
plt.hist(data, bins=range(0, 25), normed=True, label=["staff/faculty", "students"])
plt.xticks(range(0, 24, 2))
plt.xlabel("hour of day")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_by_occupation.png")
fig3 = plt.figure(figsize=figsize, dpi=dpi)
plt.hist([entry["time"].hour for entry in fcharge + mcharge], bins=range(0,25), normed=True, rwidth=0.9, label=["all participants"])
plt.xticks(range(0, 24, 2))
plt.xlabel("hour of day")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_all.png")
def calc_soc_data(l):
return [soc.calc_soc(soc.choose_temp(entry["temp"]), entry["voltage"]) for entry in l if
entry["voltage"] is not None and entry["temp"] is not None]
bins = 20
fig4 = plt.figure(figsize=figsize, dpi=dpi)
plt.hist(calc_soc_data(fcharge + mcharge), bins, rwidth=0.9, zorder=2, label = "all aprticipants")
plt.hist(calc_soc_data(fcharge + mcharge), bins, rwidth=0.9, cumulative=True,label = "all participants (cum.)",
zorder=1)
plt.xlabel("state of charge (percentage)")
plt.ylabel("frequency")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_by_soc.png")
fig5 = plt.figure(figsize=figsize, dpi=dpi)
plt.hist([calc_soc_data(fcharge), calc_soc_data(mcharge)], bins, normed=True, label=["female", "male"])
plt.xlabel("state of charge (percentage)")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_by_soc_by_gender.png")
fig6 = plt.figure(figsize=figsize, dpi=dpi)
plt.hist([calc_soc_data(staff), calc_soc_data(students)], bins, normed=True,label=["staff/faculty", "students"])
plt.xlabel("state of charge (percentage)")
plt.ylabel("probability density")
plt.legend()
plt.tight_layout()
plt.savefig("charge_start_by_soc_by_occupation.png")