|
@@ -59,43 +59,77 @@ plt.ioff()
|
59
|
59
|
fig, ax = plt.subplots()
|
60
|
60
|
|
61
|
61
|
for i in range(len(ids)):
|
|
62
|
+ cumulative = []
|
|
63
|
+ for j in range(len(durations[i])):
|
|
64
|
+ if j == 0:
|
|
65
|
+ cumulative.append(durations[i][j])
|
|
66
|
+ else:
|
|
67
|
+ cumulative.append(cumulative[j - 1] + durations[i][j])
|
|
68
|
+
|
62
|
69
|
dates = matplotlib.dates.date2num(times[i])
|
63
|
|
- ax.plot_date(dates, durations[i], '-', label='id ' + ids[i])
|
|
70
|
+ ax.plot_date(dates, cumulative, '-', label='id ' + ids[i])
|
64
|
71
|
|
65
|
72
|
ax.set_xlabel('Time')
|
66
|
73
|
ax.set_ylabel('Duration')
|
67
|
|
- ax.set_title('Watering Durations')
|
|
74
|
+ ax.set_title('Cumulative Watering Durations')
|
68
|
75
|
ax.legend()
|
69
|
76
|
|
70
|
77
|
# ---------------------------
|
71
|
78
|
|
72
|
|
-fig, ax = plt.subplots()
|
73
|
|
-
|
74
|
|
-for i in range(len(ids)):
|
75
|
|
- values = []
|
76
|
|
- for j in range(len(times[i])):
|
77
|
|
- if j == 0:
|
78
|
|
- continue
|
79
|
|
- delta = times[i][j] - times[i][j - 1]
|
80
|
|
- values.append(delta.days)
|
81
|
|
-
|
82
|
|
- ax.plot(range(len(values)), values, '-', label='id ' + ids[i])
|
83
|
|
-
|
84
|
|
- ax.set_xlabel('Watering No.')
|
85
|
|
- ax.set_ylabel('Time Difference')
|
86
|
|
- ax.set_title('Time between Waterings')
|
87
|
|
- ax.legend()
|
88
|
|
-
|
89
|
|
-# ---------------------------
|
|
79
|
+smoothing_value = 3.0
|
90
|
80
|
|
91
|
81
|
fig, ax = plt.subplots()
|
92
|
82
|
|
93
|
83
|
for i in range(len(ids)):
|
94
|
|
- ax.plot(range(len(durations[i])), durations[i], '-', label='id ' + ids[i])
|
|
84
|
+ cumulative = []
|
|
85
|
+ for j in range(len(durations[i])):
|
|
86
|
+ if j == 0:
|
|
87
|
+ cumulative.append(durations[i][j])
|
|
88
|
+ else:
|
|
89
|
+ cumulative.append(cumulative[j - 1] + durations[i][j])
|
|
90
|
+
|
|
91
|
+ cumulative_clean = []
|
|
92
|
+ time_clean = []
|
|
93
|
+ xr = iter(range(len(durations[i]) - 1))
|
|
94
|
+ try:
|
|
95
|
+ for j in xr:
|
|
96
|
+ dx_dt = (times[i][j + 1] - times[i][j])
|
|
97
|
+ dx = dx_dt.seconds / 24 / 60 / 60 + dx_dt.days
|
|
98
|
+ if dx <= smoothing_value:
|
|
99
|
+ #print("combining diff=" + str(dx))
|
|
100
|
+ time_clean.append(times[i][j + 1])
|
|
101
|
+ cumulative_clean.append(cumulative[j + 1])
|
|
102
|
+ next(xr)
|
|
103
|
+ else:
|
|
104
|
+ time_clean.append(times[i][j])
|
|
105
|
+ cumulative_clean.append(cumulative[j])
|
|
106
|
+ except:
|
|
107
|
+ pass
|
|
108
|
+
|
|
109
|
+ cumulative_clean_2 = []
|
|
110
|
+ time_clean_2 = []
|
|
111
|
+ xr = iter(range(len(cumulative_clean) - 1))
|
|
112
|
+ try:
|
|
113
|
+ for j in xr:
|
|
114
|
+ dx_dt = (time_clean[j + 1] - time_clean[j])
|
|
115
|
+ dx = dx_dt.seconds / 24 / 60 / 60 + dx_dt.days
|
|
116
|
+ if dx <= smoothing_value:
|
|
117
|
+ #print("combining diff=" + str(dx))
|
|
118
|
+ time_clean_2.append(time_clean[j + 1])
|
|
119
|
+ cumulative_clean_2.append(cumulative_clean[j + 1])
|
|
120
|
+ next(xr)
|
|
121
|
+ else:
|
|
122
|
+ time_clean_2.append(time_clean[j])
|
|
123
|
+ cumulative_clean_2.append(cumulative_clean[j])
|
|
124
|
+ except:
|
|
125
|
+ pass
|
|
126
|
+
|
|
127
|
+ dates = matplotlib.dates.date2num(time_clean_2)
|
|
128
|
+ ax.plot_date(dates, cumulative_clean_2, '-', label='id ' + ids[i])
|
95
|
129
|
|
96
|
|
- ax.set_xlabel('Watering No.')
|
|
130
|
+ ax.set_xlabel('Time')
|
97
|
131
|
ax.set_ylabel('Duration')
|
98
|
|
- ax.set_title('Duration per Watering')
|
|
132
|
+ ax.set_title('Smoothed Cumulative Watering Durations')
|
99
|
133
|
ax.legend()
|
100
|
134
|
|
101
|
135
|
# ---------------------------
|
|
@@ -103,29 +137,65 @@ for i in range(len(ids)):
|
103
|
137
|
fig, ax = plt.subplots()
|
104
|
138
|
|
105
|
139
|
for i in range(len(ids)):
|
106
|
|
- values = []
|
107
|
|
- s = 0
|
108
|
|
- for j in range(len(times[i]) - 1):
|
109
|
|
- t_delta = times[i][j + 1] - times[i][j]
|
110
|
|
- dur = (durations[i][j] + durations[i][j + 1]) / 2.0
|
111
|
|
- #dur = durations[i][j + 1]
|
112
|
|
- #dur = durations[i][j]
|
113
|
|
- avg_per_sec = dur / t_delta.total_seconds()
|
114
|
|
- #if i == 2:
|
115
|
|
- # print()
|
116
|
|
- # print(dur)
|
117
|
|
- # print(t_delta.total_seconds())
|
118
|
|
- # print(avg_per_sec)
|
119
|
|
- avg_per_day = avg_per_sec * 60.0 * 60.0 * 24.0
|
120
|
|
- values.append(avg_per_day)
|
121
|
|
- s += avg_per_sec
|
122
|
|
- #print(s / (len(times[i]) - 1))
|
123
|
|
-
|
124
|
|
- ax.plot(range(len(values)), values, '-', label='id ' + ids[i])
|
125
|
|
-
|
126
|
|
- ax.set_xlabel('Watering No.')
|
127
|
|
- ax.set_ylabel('Duration per Day')
|
128
|
|
- ax.set_title('Watering Duration per Day')
|
|
140
|
+ cumulative = []
|
|
141
|
+ for j in range(len(durations[i])):
|
|
142
|
+ if j == 0:
|
|
143
|
+ cumulative.append(durations[i][j])
|
|
144
|
+ else:
|
|
145
|
+ cumulative.append(cumulative[j - 1] + durations[i][j])
|
|
146
|
+
|
|
147
|
+ cumulative_clean = []
|
|
148
|
+ time_clean = []
|
|
149
|
+ xr = iter(range(len(durations[i]) - 1))
|
|
150
|
+ try:
|
|
151
|
+ for j in xr:
|
|
152
|
+ dx_dt = (times[i][j + 1] - times[i][j])
|
|
153
|
+ dx = dx_dt.seconds / 24 / 60 / 60 + dx_dt.days
|
|
154
|
+ if dx <= smoothing_value:
|
|
155
|
+ #print("combining diff=" + str(dx))
|
|
156
|
+ time_clean.append(times[i][j + 1])
|
|
157
|
+ cumulative_clean.append(cumulative[j + 1])
|
|
158
|
+ next(xr)
|
|
159
|
+ else:
|
|
160
|
+ time_clean.append(times[i][j])
|
|
161
|
+ cumulative_clean.append(cumulative[j])
|
|
162
|
+ except:
|
|
163
|
+ pass
|
|
164
|
+
|
|
165
|
+ cumulative_clean_2 = []
|
|
166
|
+ time_clean_2 = []
|
|
167
|
+ xr = iter(range(len(cumulative_clean) - 1))
|
|
168
|
+ try:
|
|
169
|
+ for j in xr:
|
|
170
|
+ dx_dt = (time_clean[j + 1] - time_clean[j])
|
|
171
|
+ dx = dx_dt.seconds / 24 / 60 / 60 + dx_dt.days
|
|
172
|
+ if dx <= smoothing_value:
|
|
173
|
+ #print("combining diff=" + str(dx))
|
|
174
|
+ time_clean_2.append(time_clean[j + 1])
|
|
175
|
+ cumulative_clean_2.append(cumulative_clean[j + 1])
|
|
176
|
+ next(xr)
|
|
177
|
+ else:
|
|
178
|
+ time_clean_2.append(time_clean[j])
|
|
179
|
+ cumulative_clean_2.append(cumulative_clean[j])
|
|
180
|
+ except:
|
|
181
|
+ pass
|
|
182
|
+
|
|
183
|
+ rate_of_change = []
|
|
184
|
+ for j in range(len(cumulative_clean_2)):
|
|
185
|
+ if j < len(cumulative_clean_2) - 1:
|
|
186
|
+ dy = cumulative_clean_2[j + 1] - cumulative_clean_2[j]
|
|
187
|
+ dx_dt = (time_clean_2[j + 1] - time_clean_2[j])
|
|
188
|
+ dx = dx_dt.seconds / 24 / 60 / 60 + dx_dt.days
|
|
189
|
+ roc = dy / dx
|
|
190
|
+ #print(str(time_clean_2[j]) + " " + str(dy) + " / " + str(dx) + " = " + str(roc))
|
|
191
|
+ rate_of_change.append(roc)
|
|
192
|
+
|
|
193
|
+ dates = matplotlib.dates.date2num(time_clean_2)
|
|
194
|
+ ax.plot_date(dates[:-1], rate_of_change, '-', label='id ' + ids[i])
|
|
195
|
+
|
|
196
|
+ ax.set_xlabel('Time')
|
|
197
|
+ ax.set_ylabel('Rate of Change')
|
|
198
|
+ ax.set_title('RoC of Cumulative Watering Durations')
|
129
|
199
|
ax.legend()
|
130
|
200
|
|
131
|
201
|
# ---------------------------
|