5
5
import matplotlib .pyplot as plt
6
6
from scipy import stats
7
7
from scipy import interpolate
8
- import pandas as pd
9
8
10
9
from .models import *
11
10
@@ -100,14 +99,24 @@ def __init__(self, num_stud, **kwargs):
100
99
}
101
100
self .debug_figures = {}
102
101
102
+ self .min_stud_online = None
103
+ self .min_stud_offline = None
104
+ self .min_stud_online_notransp = None
105
+ self .min_stud_offline_notransp = None
106
+
107
+ self .res_cons = None
108
+ self .res_cons_err = None
109
+ self .res_cons_notransp = None
110
+ self .res_cons_err_notransp = None
111
+
103
112
return
104
113
105
114
def get_hybrid_figure (self , grid , cons , cons_std , interp_grid ):
106
115
if "notransport" in self .options :
107
116
notrans = 0
108
117
notrans_std = 0
109
118
110
- fig = plt .figure (figsize = [7.5 , 4.8 ])
119
+ fig = plt .figure (figsize = [6.4 , 4.8 ])
111
120
p = max (grid )
112
121
113
122
def online (x ):
@@ -175,7 +184,7 @@ def onsite(x):
175
184
)
176
185
177
186
# Put a legend to the right of the current axis
178
- plt . gca (). legend (loc = "center left " , bbox_to_anchor = (1.05 , 0.3 ))
187
+ fig . legend (loc = "upper center " , ncol = 2 , bbox_to_anchor = (0.5 , 0 ))
179
188
180
189
if "logplot" in self .options :
181
190
plt .ylabel ("log(Consumption per lecture) (kWh)" )
@@ -196,52 +205,35 @@ def onsite(x):
196
205
197
206
plt .tight_layout ()
198
207
199
- # these are matplotlib.patch.Patch properties
200
- props = dict (boxstyle = "round" , alpha = 0.5 )
201
-
208
+ # Set values for result cards
209
+ self .min_stud_online = grid [minind ]
210
+ self .min_stud_offline = max (grid ) - grid [minind ]
211
+ self .res_cons = min_cons
212
+ self .res_cons_err = min_std
202
213
if "notransport" in self .options :
203
214
min_ind_nt = np .where (notrans == min (notrans ))
204
215
min_cons_nt = notrans [min_ind_nt ]
205
216
min_std_nt = np .sqrt (notrans_std [min_ind_nt ])
206
- textstr = "Optimal mode:\n - %d students online\n - %d students on-site\n - Total consumption: %.2f $\pm$ %.2f$\,$kWh\n \n " % (
207
- grid [minind ],
208
- max (grid ) - grid [minind ],
209
- min_cons ,
210
- min_std ,
211
- ) + "Without transportation:\n - %d students online\n - %d students on-site\n - Consumption: %.2f $\pm$ %.2f$\,$kWh" % (
212
- grid [min_ind_nt ],
213
- max (grid ) - grid [min_ind_nt ],
214
- min_cons_nt ,
215
- min_std_nt ,
216
- )
217
- else :
218
- textstr = (
219
- "Optimal mode:\n - %d students online\n - %d students on-site\n - Total consumption: %.2f $\pm$ %.2f$\,$kWh"
220
- % (grid [minind ], max (grid ) - grid [minind ], min_cons , min_std )
221
- )
222
-
223
- # place a text box in upper left in axes coords
224
- txt = plt .gca ().text (
225
- 1.05 ,
226
- 1.15 ,
227
- textstr ,
228
- transform = plt .gca ().transAxes ,
229
- fontsize = 14 ,
230
- verticalalignment = "top" ,
231
- bbox = props ,
232
- )
217
+ self .min_stud_online_notransp = grid [min_ind_nt ]
218
+ self .min_stud_offline_notransp = max (grid ) - grid [min_ind_nt ]
219
+ self .res_cons_notransp = min_cons_nt
220
+ self .res_cons_err_notransp = min_std_nt
233
221
234
222
imgdata = io .StringIO ()
235
223
fig .savefig (
236
224
imgdata ,
237
225
format = "svg" ,
238
226
bbox_inches = "tight" ,
239
- bbox_extra_artists = (txt ,),
240
227
dpi = 600 ,
241
228
)
242
229
imgdata .seek (0 )
243
230
244
231
data = imgdata .getvalue ()
232
+
233
+ # TODO Remove hardcoded string in favour for regex
234
+ data = data .replace ('width="452.799029pt"' , 'width="100%"' )
235
+ data = data .replace ('height="415.189062pt"' , 'height="100%"' )
236
+
245
237
return data
246
238
247
239
def get_random_living_consumption (
@@ -447,8 +439,6 @@ def get_consumption(
447
439
448
440
if mode == "online-streaming" or mode == "online-vod" :
449
441
# Calculation of the consumption for an online lecture
450
- # TODO Make sure that the calculation makes sense
451
-
452
442
# Streaming service
453
443
if mode == "online-streaming" :
454
444
if self .streaming is None :
@@ -525,6 +515,12 @@ def get_consumption(
525
515
consumption += c
526
516
stat_uncertainty += s ** 2
527
517
518
+ self .res_cons = consumption
519
+ self .res_cons_err = np .sqrt (stat_uncertainty )
520
+
521
+ self .res_cons_notransp = consumption - self .contribs ["Transportation" ][0 ]
522
+ self .res_cons_err_notransp = np .sqrt (stat_uncertainty - self .contribs_std ["Transportation" ][0 ] ** 2 )
523
+
528
524
return consumption , np .sqrt (stat_uncertainty )
529
525
530
526
if mode == "offline" :
@@ -615,6 +611,12 @@ def get_consumption(
615
611
616
612
self .num_stud = num_stud_bak
617
613
614
+ self .res_cons = consumption
615
+ self .res_cons_err = np .sqrt (stat_uncertainty )
616
+
617
+ self .res_cons_notransp = consumption - self .contribs ["Transportation" ][0 ]
618
+ self .res_cons_err_notransp = np .sqrt (stat_uncertainty - self .contribs_std ["Transportation" ][0 ] ** 2 )
619
+
618
620
return consumption , np .sqrt (stat_uncertainty )
619
621
620
622
if mode == "hybrid-streaming" or mode == "hybrid-vod" :
@@ -709,10 +711,6 @@ def get_consumption(
709
711
# Reset number of studenst
710
712
self .num_stud = num_stud_bak
711
713
712
- # Find optimal hybrid fraction
713
- cons = np .array (cons )
714
- cons_std = np .array (cons_std )
715
-
716
714
# Interpolate consumption values
717
715
x = np .arange (self .num_stud + 1 )
718
716
func = interpolate .interp1d (grid , cons )
0 commit comments