-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
149 lines (130 loc) · 4.8 KB
/
utils.py
File metadata and controls
149 lines (130 loc) · 4.8 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
def stringFromSeconds(seconds):
if seconds < 0:
return seconds, " seconds. You missed it, better luck next year."
else:
days = seconds / 60 / 60 / 24
fracDays = days - int(days)
hours = fracDays * 24
fracHours = hours - int(hours)
minutes = fracHours * 60
fracMinutes = minutes - int(minutes)
seconds = fracMinutes * 60
return "%d days, %d hours, %d minutes, %d seconds" % (days, minutes, hours, seconds)
def generate_trending_bargraph(people_counts):
labels = list(people_counts.keys())
first_names = [whole_name.split(" ")[0] for whole_name in people_counts.keys()]
values = [people_counts[x] for x in labels]
values, first_names = (list(t) for t in zip(*sorted(zip(values, first_names))))
x = np.arange(len(first_names))
width = 0.5
fig, ax = plt.subplots()
rects1 = ax.bar(x, values, width)
ax.set_ylabel('Number of Workouts')
ax.set_title('Workouts In The Last Month')
ax.set_xticks(x)
ax.set_xticklabels(first_names)
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right', fontsize='x-small')
plt.plot()
file_name = "plot.png"
plt.savefig(file_name)
return file_name
def generate_bargraph(labels, values, title, x_label, y_label):
x = np.arange(len(labels))
width = 0.5
fig, ax = plt.subplots()
rects1 = ax.bar(x, values, width)
ax.set_ylabel(y_label)
ax.set_xlabel(x_label)
ax.set_title(title)
ax.set_xticks(x)
ax.set_xticklabels(labels)
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right', fontsize='x-small')
plt.plot()
file_name = "plot.png"
plt.savefig(file_name)
return file_name
def generate_feedback_bargraph(labels, values, title, x_label, y_label):
width = 0.35 # the width of the bars: can also be len(x) sequence
true_values = []
true_lables = []
for i in range(len(values)):
if len(values[i]) == 5 and np.sum(np.array(values[i][0:4])) > 0:
print(values[i])
true_lables.append(labels[i])
true_values.append(values[i])
labels = true_lables
values = np.squeeze(np.array(true_values))
# max_tick = np.max(values)
max_tick = 4
N = len(labels)
ind = np.arange(N) # the x locations for the groups
fig, ax = plt.subplots()
excellent = values[:, 0]
good = values[:, 1]
average = values[:, 2]
low = values[:, 3]
totals = excellent + good + average + low
matrix = np.vstack((excellent, good, average, low))
weights = np.array([4, 3, 2, 1])
sums = np.sum(matrix, axis=0)
result = weights.dot(matrix)
true_avg = result / sums
print("True Average: ", true_avg)
low = low / totals
average = average / totals
good = good / totals
excellent = excellent / totals
p1 = ax.plot(ind, low, label='low')
p2 = ax.plot(ind, average, label='average')
p3 = ax.plot(ind, good, label='good')
p4 = ax.plot(ind, excellent, label='excellent')
p5 = ax.plot(ind, true_avg, label='average score')
plt.ylabel(y_label)
plt.xlabel(x_label)
plt.title(title)
plt.xticks(ind, labels)
plt.yticks(np.arange(0, max_tick, 1))
plt.legend((p5[0], p4[0], p3[0], p2[0], p1[0]), ('Average score', 'Excellent', 'Good', 'Average', 'Low'), loc='upper right')
plt.setp(ax.get_xticklabels(), rotation=30, horizontalalignment='right', fontsize='x-small')
ax.yaxis.grid(True)
ax.xaxis.grid(True)
plt.plot()
file_name = "feedback_plot.png"
plt.savefig(file_name)
return file_name
def get_average_intensity_score(labels, values):
true_values = []
true_lables = []
for i in range(len(values)):
if len(values[i]) == 5:
true_lables.append(labels[i])
true_values.append(values[i])
labels = true_lables
values = np.squeeze(np.array(true_values))
print(values)
excellent = values[:, 0]
good = values[:, 1]
average = values[:, 2]
low = values[:, 3]
total = 4 * np.sum(excellent) + 3 * np.sum(good) + 2 * np.sum(average) + np.sum(low)
total = total / (np.sum(excellent) + np.sum(good) + np.sum(average) + np.sum(low))
matrix = np.vstack((excellent, good, average, low))
weights = np.array([4, 3, 2, 1])
sums = np.sum(matrix, axis=0)
result = weights.dot(matrix)
return total, result / sums, labels
# def main():
# values = [[[0], [0], [0], [0], [0], [34]], [[1], [13], [6], [0], [0], [15]], [[5], [8], [2], [1], [18]],
# [[4], [11], [8], [0], [11]]]
# labels = ['01/14/2020', '01/15/2020', '01/16/2020', '01/21/2020']
# total, per_day, labels = get_average_intensity_score(labels, values)
# print(per_day)
# print(total)
# print(labels)
#
#
# if __name__ == '__main__':
# main()