@@ 70-1012 (lines=943) @@ | ||
67 | return base64_message |
|
68 | ||
69 | ||
70 | def generate_excel(report, |
|
71 | name, |
|
72 | base_period_start_datetime_local, |
|
73 | base_period_end_datetime_local, |
|
74 | reporting_start_datetime_local, |
|
75 | reporting_end_datetime_local, |
|
76 | period_type, |
|
77 | language): |
|
78 | trans = get_translation(language) |
|
79 | trans.install() |
|
80 | _ = trans.gettext |
|
81 | wb = Workbook() |
|
82 | ws = wb.active |
|
83 | ws.title = "SpaceSaving" |
|
84 | ||
85 | # Row height |
|
86 | ws.row_dimensions[1].height = 102 |
|
87 | for i in range(2, 2000 + 1): |
|
88 | ws.row_dimensions[i].height = 42 |
|
89 | ||
90 | # Col width |
|
91 | ws.column_dimensions['A'].width = 1.5 |
|
92 | ||
93 | ws.column_dimensions['B'].width = 25.0 |
|
94 | ||
95 | for i in range(ord('C'), ord('Z')): |
|
96 | ws.column_dimensions[chr(i)].width = 15.0 |
|
97 | ||
98 | # Font |
|
99 | name_font = Font(name='Arial', size=15, bold=True) |
|
100 | title_font = Font(name='Arial', size=15, bold=True) |
|
101 | ||
102 | table_fill = PatternFill(fill_type='solid', fgColor='90ee90') |
|
103 | f_border = Border(left=Side(border_style='medium'), |
|
104 | right=Side(border_style='medium'), |
|
105 | bottom=Side(border_style='medium'), |
|
106 | top=Side(border_style='medium') |
|
107 | ) |
|
108 | b_border = Border( |
|
109 | bottom=Side(border_style='medium'), |
|
110 | ) |
|
111 | ||
112 | b_c_alignment = Alignment(vertical='bottom', |
|
113 | horizontal='center', |
|
114 | text_rotation=0, |
|
115 | wrap_text=True, |
|
116 | shrink_to_fit=False, |
|
117 | indent=0) |
|
118 | c_c_alignment = Alignment(vertical='center', |
|
119 | horizontal='center', |
|
120 | text_rotation=0, |
|
121 | wrap_text=True, |
|
122 | shrink_to_fit=False, |
|
123 | indent=0) |
|
124 | b_r_alignment = Alignment(vertical='bottom', |
|
125 | horizontal='right', |
|
126 | text_rotation=0, |
|
127 | wrap_text=True, |
|
128 | shrink_to_fit=False, |
|
129 | indent=0) |
|
130 | ||
131 | # Img |
|
132 | img = Image("excelexporters/myems.png") |
|
133 | ws.add_image(img, 'A1') |
|
134 | ||
135 | # Title |
|
136 | ws['B3'].alignment = b_r_alignment |
|
137 | ws['B3'] = _('Name') + ':' |
|
138 | ws['C3'].border = b_border |
|
139 | ws['C3'].alignment = b_c_alignment |
|
140 | ws['C3'] = name |
|
141 | ||
142 | ws['D3'].alignment = b_r_alignment |
|
143 | ws['D3'] = _('Period Type') + ':' |
|
144 | ws['E3'].border = b_border |
|
145 | ws['E3'].alignment = b_c_alignment |
|
146 | ws['E3'] = period_type |
|
147 | ||
148 | ws['B4'].alignment = b_r_alignment |
|
149 | ws['B4'] = _('Reporting Start Datetime') + ':' |
|
150 | ws['C4'].border = b_border |
|
151 | ws['C4'].alignment = b_c_alignment |
|
152 | ws['C4'] = reporting_start_datetime_local |
|
153 | ||
154 | ws['D4'].alignment = b_r_alignment |
|
155 | ws['D4'] = _('Reporting End Datetime') + ':' |
|
156 | ws['E4'].border = b_border |
|
157 | ws['E4'].alignment = b_c_alignment |
|
158 | ws['E4'] = reporting_end_datetime_local |
|
159 | ||
160 | is_base_period_timestamp_exists_flag = is_base_period_timestamp_exists(report['base_period']) |
|
161 | ||
162 | if is_base_period_timestamp_exists_flag: |
|
163 | ws['B5'].alignment = b_r_alignment |
|
164 | ws['B5'] = _('Base Period Start Datetime') + ':' |
|
165 | ws['C5'].border = b_border |
|
166 | ws['C5'].alignment = b_c_alignment |
|
167 | ws['C5'] = base_period_start_datetime_local |
|
168 | ||
169 | ws['D5'].alignment = b_r_alignment |
|
170 | ws['D5'] = _('Base Period End Datetime') + ':' |
|
171 | ws['E5'].border = b_border |
|
172 | ws['E5'].alignment = b_c_alignment |
|
173 | ws['E5'] = base_period_end_datetime_local |
|
174 | ||
175 | if "reporting_period" not in report.keys() or \ |
|
176 | "names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0: |
|
177 | filename = str(uuid.uuid4()) + '.xlsx' |
|
178 | wb.save(filename) |
|
179 | ||
180 | return filename |
|
181 | ||
182 | #################################################################################################################### |
|
183 | current_row_number = 7 |
|
184 | reporting_period_data = report['reporting_period'] |
|
185 | if "names" not in reporting_period_data.keys() or \ |
|
186 | reporting_period_data['names'] is None or \ |
|
187 | len(reporting_period_data['names']) == 0: |
|
188 | pass |
|
189 | else: |
|
190 | ws['B' + str(current_row_number)].font = title_font |
|
191 | ws['B' + str(current_row_number)] = name + ' ' + _('Reporting Period Saving') |
|
192 | ||
193 | current_row_number += 1 |
|
194 | ||
195 | category = reporting_period_data['names'] |
|
196 | ca_len = len(category) |
|
197 | ||
198 | ws.row_dimensions[current_row_number].height = 75 |
|
199 | ws['B' + str(current_row_number)].fill = table_fill |
|
200 | ws['B' + str(current_row_number)].border = f_border |
|
201 | ||
202 | col = 'C' |
|
203 | ||
204 | for i in range(0, ca_len): |
|
205 | ws[col + str(current_row_number)].fill = table_fill |
|
206 | ws[col + str(current_row_number)].font = name_font |
|
207 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
208 | ws[col + str(current_row_number)].border = f_border |
|
209 | ws[col + str(current_row_number)] = \ |
|
210 | reporting_period_data['names'][i] + " (" + _('Baseline') + ' - ' \ |
|
211 | + _('Actual') + ")(" + reporting_period_data['units'][i] + ")" |
|
212 | ||
213 | col = chr(ord(col) + 1) |
|
214 | ||
215 | ws[col + str(current_row_number)].fill = table_fill |
|
216 | ws[col + str(current_row_number)].font = name_font |
|
217 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
218 | ws[col + str(current_row_number)].border = f_border |
|
219 | ws[col + str(current_row_number)] = _('Ton of Standard Coal') + ' (' \ |
|
220 | + _('Baseline') + ' - ' + _('Actual') + ') (TCE)' |
|
221 | ||
222 | col = chr(ord(col) + 1) |
|
223 | ||
224 | ws[col + str(current_row_number)].fill = table_fill |
|
225 | ws[col + str(current_row_number)].font = name_font |
|
226 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
227 | ws[col + str(current_row_number)].border = f_border |
|
228 | ws[col + str(current_row_number)] = _('Ton of Carbon Dioxide Emissions') \ |
|
229 | + ' (' + _('Baseline') + ' - ' + _('Actual') + ') (TCO2E)' |
|
230 | ||
231 | current_row_number += 1 |
|
232 | ||
233 | ws['B' + str(current_row_number)].font = title_font |
|
234 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
235 | ws['B' + str(current_row_number)].border = f_border |
|
236 | ws['B' + str(current_row_number)] = _('Saving') |
|
237 | ||
238 | col = 'C' |
|
239 | ||
240 | for i in range(0, ca_len): |
|
241 | ws[col + str(current_row_number)].font = name_font |
|
242 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
243 | ws[col + str(current_row_number)].border = f_border |
|
244 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
245 | ||
246 | col = chr(ord(col) + 1) |
|
247 | ||
248 | ws[col + str(current_row_number)].font = name_font |
|
249 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
250 | ws[col + str(current_row_number)].border = f_border |
|
251 | ws[col + str(current_row_number)] = round2(reporting_period_data['total_in_kgce_saving'] / 1000, 2) |
|
252 | ||
253 | col = chr(ord(col) + 1) |
|
254 | ||
255 | ws[col + str(current_row_number)].font = name_font |
|
256 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
257 | ws[col + str(current_row_number)].border = f_border |
|
258 | ws[col + str(current_row_number)] = round2(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2) |
|
259 | ||
260 | current_row_number += 1 |
|
261 | ||
262 | ws['B' + str(current_row_number)].font = title_font |
|
263 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
264 | ws['B' + str(current_row_number)].border = f_border |
|
265 | ws['B' + str(current_row_number)] = _('Per Unit Area') |
|
266 | ||
267 | col = 'C' |
|
268 | ||
269 | for i in range(0, ca_len): |
|
270 | ws[col + str(current_row_number)].font = name_font |
|
271 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
272 | ws[col + str(current_row_number)].border = f_border |
|
273 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_per_unit_area_saving'][i], 2) \ |
|
274 | if reporting_period_data['subtotals_per_unit_area_saving'][i] is not None else '' |
|
275 | ||
276 | col = chr(ord(col) + 1) |
|
277 | ||
278 | ws[col + str(current_row_number)].font = name_font |
|
279 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
280 | ws[col + str(current_row_number)].border = f_border |
|
281 | ws[col + str(current_row_number)] = \ |
|
282 | round2(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2) \ |
|
283 | if reporting_period_data['total_in_kgce_per_unit_area_saving'] is not None else '' |
|
284 | ||
285 | col = chr(ord(col) + 1) |
|
286 | ||
287 | ws[col + str(current_row_number)].font = name_font |
|
288 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
289 | ws[col + str(current_row_number)].border = f_border |
|
290 | ws[col + str(current_row_number)] = \ |
|
291 | round2(reporting_period_data['total_in_kgco2e_per_unit_area_saving'] / 1000, 2) \ |
|
292 | if reporting_period_data['total_in_kgco2e_per_unit_area_saving'] is not None else '' |
|
293 | ||
294 | current_row_number += 1 |
|
295 | ||
296 | ws['B' + str(current_row_number)].font = title_font |
|
297 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
298 | ws['B' + str(current_row_number)].border = f_border |
|
299 | ws['B' + str(current_row_number)] = _('Increment Rate') |
|
300 | ||
301 | col = 'C' |
|
302 | ||
303 | for i in range(0, ca_len): |
|
304 | ws[col + str(current_row_number)].font = name_font |
|
305 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
306 | ws[col + str(current_row_number)].border = f_border |
|
307 | ws[col + str(current_row_number)] = str( |
|
308 | round2(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \ |
|
309 | if reporting_period_data['increment_rates_saving'][i] is not None else '-' |
|
310 | ||
311 | col = chr(ord(col) + 1) |
|
312 | ||
313 | ws[col + str(current_row_number)].font = name_font |
|
314 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
315 | ws[col + str(current_row_number)].border = f_border |
|
316 | ws[col + str(current_row_number)] = str( |
|
317 | round2(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \ |
|
318 | if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-' |
|
319 | ||
320 | col = chr(ord(col) + 1) |
|
321 | ||
322 | ws[col + str(current_row_number)].font = name_font |
|
323 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
324 | ws[col + str(current_row_number)].border = f_border |
|
325 | ws[col + str(current_row_number)] = str( |
|
326 | round2(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \ |
|
327 | if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-' |
|
328 | ||
329 | current_row_number += 2 |
|
330 | ||
331 | ws['B' + str(current_row_number)].font = title_font |
|
332 | ws['B' + str(current_row_number)] = name + ' ' + _('Ton of Standard Coal(TCE) by Energy Category') |
|
333 | ||
334 | current_row_number += 1 |
|
335 | table_start_row_number = current_row_number |
|
336 | chart_start_row_number = current_row_number |
|
337 | ||
338 | ws.row_dimensions[current_row_number].height = 60 |
|
339 | ws['B' + str(current_row_number)].fill = table_fill |
|
340 | ws['B' + str(current_row_number)].border = f_border |
|
341 | ||
342 | ws['C' + str(current_row_number)].fill = table_fill |
|
343 | ws['C' + str(current_row_number)].font = name_font |
|
344 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
345 | ws['C' + str(current_row_number)].border = f_border |
|
346 | ws['C' + str(current_row_number)] = _('Saving') |
|
347 | ||
348 | ws['D' + str(current_row_number)].fill = table_fill |
|
349 | ws['D' + str(current_row_number)].font = name_font |
|
350 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
351 | ws['D' + str(current_row_number)].border = f_border |
|
352 | ws['D' + str(current_row_number)] = _('Ton of Standard Coal(TCE) by Energy Category') |
|
353 | ||
354 | current_row_number += 1 |
|
355 | ||
356 | subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving']) |
|
357 | ||
358 | for i in range(0, ca_len): |
|
359 | ws['B' + str(current_row_number)].font = title_font |
|
360 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
361 | ws['B' + str(current_row_number)].border = f_border |
|
362 | ws['B' + str(current_row_number)] = reporting_period_data['names'][i] |
|
363 | ||
364 | ws['C' + str(current_row_number)].font = name_font |
|
365 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
366 | ws['C' + str(current_row_number)].border = f_border |
|
367 | ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3) |
|
368 | ||
369 | ws['D' + str(current_row_number)].font = name_font |
|
370 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
371 | ws['D' + str(current_row_number)].border = f_border |
|
372 | ws['D' + str(current_row_number)] = str(round2(reporting_period_data['subtotals_in_kgce_saving'][i] / |
|
373 | subtotals_in_kgce_saving_sum * 100, 2)) + '%'\ |
|
374 | if abs(subtotals_in_kgce_saving_sum) > 0 else '-' |
|
375 | ||
376 | current_row_number += 1 |
|
377 | ||
378 | table_end_row_number = current_row_number - 1 |
|
379 | ||
380 | if ca_len < 4: |
|
381 | current_row_number = current_row_number - ca_len + 4 |
|
382 | ||
383 | current_row_number += 1 |
|
384 | ||
385 | pie = PieChart() |
|
386 | pie.title = name + ' ' + _('Ton of Standard Coal(TCE) by Energy Category') |
|
387 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
388 | pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number) |
|
389 | pie.add_data(pie_data, titles_from_data=True) |
|
390 | pie.set_categories(labels) |
|
391 | pie.height = 7.25 |
|
392 | pie.width = 9 |
|
393 | s1 = pie.series[0] |
|
394 | s1.dLbls = DataLabelList() |
|
395 | s1.dLbls.showCatName = False |
|
396 | s1.dLbls.showVal = False |
|
397 | s1.dLbls.showPercent = True |
|
398 | ws.add_chart(pie, 'E' + str(chart_start_row_number)) |
|
399 | ||
400 | ws['B' + str(current_row_number)].font = title_font |
|
401 | ws['B' + str(current_row_number)] = name + ' ' + _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
402 | ||
403 | current_row_number += 1 |
|
404 | table_start_row_number = current_row_number |
|
405 | chart_start_row_number = current_row_number |
|
406 | ||
407 | ws.row_dimensions[current_row_number].height = 60 |
|
408 | ws['B' + str(current_row_number)].fill = table_fill |
|
409 | ws['B' + str(current_row_number)].border = f_border |
|
410 | ||
411 | ws['C' + str(current_row_number)].fill = table_fill |
|
412 | ws['C' + str(current_row_number)].font = name_font |
|
413 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
414 | ws['C' + str(current_row_number)].border = f_border |
|
415 | ws['C' + str(current_row_number)] = _('Saving') |
|
416 | ||
417 | ws['D' + str(current_row_number)].fill = table_fill |
|
418 | ws['D' + str(current_row_number)].font = name_font |
|
419 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
420 | ws['D' + str(current_row_number)].border = f_border |
|
421 | ws['D' + str(current_row_number)] = _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
422 | ||
423 | current_row_number += 1 |
|
424 | ||
425 | subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving']) |
|
426 | ||
427 | for i in range(0, ca_len): |
|
428 | ws['B' + str(current_row_number)].font = title_font |
|
429 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
430 | ws['B' + str(current_row_number)].border = f_border |
|
431 | ws['B' + str(current_row_number)] = reporting_period_data['names'][i] |
|
432 | ||
433 | ws['C' + str(current_row_number)].font = name_font |
|
434 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
435 | ws['C' + str(current_row_number)].border = f_border |
|
436 | ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3) |
|
437 | ||
438 | ws['D' + str(current_row_number)].font = name_font |
|
439 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
440 | ws['D' + str(current_row_number)].border = f_border |
|
441 | ws['D' + str(current_row_number)] = str(round2(reporting_period_data['subtotals_in_kgco2e_saving'][i] / |
|
442 | subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\ |
|
443 | if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-' |
|
444 | ||
445 | current_row_number += 1 |
|
446 | ||
447 | table_end_row_number = current_row_number - 1 |
|
448 | ||
449 | if ca_len < 4: |
|
450 | current_row_number = current_row_number - ca_len + 4 |
|
451 | ||
452 | current_row_number += 1 |
|
453 | ||
454 | pie = PieChart() |
|
455 | pie.title = name + ' ' + _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
456 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
457 | pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number) |
|
458 | pie.add_data(pie_data, titles_from_data=True) |
|
459 | pie.set_categories(labels) |
|
460 | pie.height = 7.25 |
|
461 | pie.width = 9 |
|
462 | s1 = pie.series[0] |
|
463 | s1.dLbls = DataLabelList() |
|
464 | s1.dLbls.showCatName = False |
|
465 | s1.dLbls.showVal = False |
|
466 | s1.dLbls.showPercent = True |
|
467 | ws.add_chart(pie, 'E' + str(chart_start_row_number)) |
|
468 | ||
469 | #################################################################################################################### |
|
470 | table_start_draw_flag = current_row_number + 1 |
|
471 | ||
472 | if 'values_saving' not in reporting_period_data.keys() or \ |
|
473 | reporting_period_data['values_saving'] is None or \ |
|
474 | len(reporting_period_data['values_saving']) == 0 or \ |
|
475 | 'timestamps' not in reporting_period_data.keys() or \ |
|
476 | reporting_period_data['timestamps'] is None or \ |
|
477 | len(reporting_period_data['timestamps']) == 0 or \ |
|
478 | len(reporting_period_data['timestamps'][0]) == 0: |
|
479 | pass |
|
480 | else: |
|
481 | if not is_base_period_timestamp_exists_flag: |
|
482 | reporting_period_data = report['reporting_period'] |
|
483 | times = reporting_period_data['timestamps'] |
|
484 | ca_len = len(report['reporting_period']['names']) |
|
485 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
|
486 | ws['B' + str(current_row_number)].font = title_font |
|
487 | ws['B' + str(current_row_number)] = name + ' ' + _('Detailed Data') |
|
488 | ||
489 | current_row_number += 1 |
|
490 | # 1: Stand for blank line 2: Stand for title |
|
491 | current_row_number += ca_len * 6 + real_timestamps_len * 6 + 1 + 2 |
|
492 | table_start_row_number = current_row_number |
|
493 | ||
494 | time = times[0] |
|
495 | has_data = False |
|
496 | ||
497 | if len(time) > 0: |
|
498 | has_data = True |
|
499 | ||
500 | if has_data: |
|
501 | ||
502 | ws.row_dimensions[current_row_number].height = 60 |
|
503 | current_col_number = 2 |
|
504 | col = format_cell.get_column_letter(current_col_number) |
|
505 | ws[col + str(current_row_number)].fill = table_fill |
|
506 | ws[col + str(current_row_number)].font = title_font |
|
507 | ws[col + str(current_row_number)].border = f_border |
|
508 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
509 | ws[col + str(current_row_number)] = _('Datetime') |
|
510 | ||
511 | for i in range(0, ca_len): |
|
512 | current_col_number += 1 |
|
513 | col = format_cell.get_column_letter(current_col_number) |
|
514 | ||
515 | ws[col + str(current_row_number)].fill = table_fill |
|
516 | ws[col + str(current_row_number)].font = title_font |
|
517 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
518 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
|
519 | " (" + reporting_period_data['units'][i] + ")" |
|
520 | ws[col + str(current_row_number)].border = f_border |
|
521 | ||
522 | current_row_number += 1 |
|
523 | ||
524 | for i in range(0, len(time)): |
|
525 | current_col_number = 2 |
|
526 | col = format_cell.get_column_letter(current_col_number) |
|
527 | ws[col + str(current_row_number)].font = title_font |
|
528 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
529 | ws[col + str(current_row_number)] = time[i] |
|
530 | ws[col + str(current_row_number)].border = f_border |
|
531 | ||
532 | for j in range(0, ca_len): |
|
533 | current_col_number += 1 |
|
534 | col = format_cell.get_column_letter(current_col_number) |
|
535 | ||
536 | ws[col + str(current_row_number)].font = title_font |
|
537 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
538 | ws[col + str(current_row_number)] = round2(reporting_period_data['values_saving'][j][i], 2) |
|
539 | ws[col + str(current_row_number)].border = f_border |
|
540 | ||
541 | current_row_number += 1 |
|
542 | ||
543 | table_end_row_number = current_row_number - 1 |
|
544 | ||
545 | current_col_number = 2 |
|
546 | col = format_cell.get_column_letter(current_col_number) |
|
547 | ws[col + str(current_row_number)].font = title_font |
|
548 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
549 | ws[col + str(current_row_number)] = _('Subtotal') |
|
550 | ws[col + str(current_row_number)].border = f_border |
|
551 | ||
552 | for i in range(0, ca_len): |
|
553 | current_col_number += 1 |
|
554 | col = format_cell.get_column_letter(current_col_number) |
|
555 | ||
556 | ws[col + str(current_row_number)].font = title_font |
|
557 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
558 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
559 | ws[col + str(current_row_number)].border = f_border |
|
560 | ||
561 | # line |
|
562 | line = LineChart() |
|
563 | line.title = _('Reporting Period Saving') + ' - ' \ |
|
564 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
565 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
566 | line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, |
|
567 | max_row=table_end_row_number) |
|
568 | line.add_data(line_data, titles_from_data=True) |
|
569 | line.set_categories(labels) |
|
570 | line_data = line.series[0] |
|
571 | line_data.marker.symbol = "auto" |
|
572 | line_data.smooth = True |
|
573 | line.x_axis.crosses = 'min' |
|
574 | line.height = 8.25 |
|
575 | line.width = 24 |
|
576 | chart_col = 'B' |
|
577 | chart_cell = chart_col + str(table_start_draw_flag + 6 * i) |
|
578 | ws.add_chart(line, chart_cell) |
|
579 | ||
580 | current_row_number += 2 |
|
581 | else: |
|
582 | base_period_data = report['base_period'] |
|
583 | reporting_period_data = report['reporting_period'] |
|
584 | base_period_timestamps = base_period_data['timestamps'] |
|
585 | reporting_period_timestamps = reporting_period_data['timestamps'] |
|
586 | # Tip: |
|
587 | # base_period_data['names'] == reporting_period_data['names'] |
|
588 | # base_period_data['units'] == reporting_period_data['units'] |
|
589 | base_period_data_ca_len = len(base_period_data['names']) |
|
590 | reporting_period_data_ca_len = len(reporting_period_data['names']) |
|
591 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
|
592 | ws['B' + str(current_row_number)].font = title_font |
|
593 | ws['B' + str(current_row_number)] = name + ' ' + _('Detailed Data') |
|
594 | ||
595 | current_row_number += 1 |
|
596 | # 1: Stand for blank line 2: Stand for title |
|
597 | current_row_number += reporting_period_data_ca_len * 6 + real_timestamps_len * 6 + 1 + 2 |
|
598 | table_start_row_number = current_row_number |
|
599 | ||
600 | has_data = False |
|
601 | ||
602 | if len(base_period_timestamps[0]) or len(reporting_period_timestamps[0]) > 0: |
|
603 | has_data = True |
|
604 | ||
605 | if has_data: |
|
606 | ws.row_dimensions[current_row_number].height = 60 |
|
607 | current_col_number = 2 |
|
608 | col = format_cell.get_column_letter(current_col_number) |
|
609 | ws[col + str(current_row_number)].fill = table_fill |
|
610 | ws[col + str(current_row_number)].font = title_font |
|
611 | ws[col + str(current_row_number)].border = f_border |
|
612 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
613 | ws[col + str(current_row_number)] = _('Base Period') + " - " + _('Datetime') |
|
614 | ||
615 | for i in range(0, base_period_data_ca_len): |
|
616 | current_col_number += 1 |
|
617 | col = format_cell.get_column_letter(current_col_number) |
|
618 | ||
619 | ws[col + str(current_row_number)].fill = table_fill |
|
620 | ws[col + str(current_row_number)].font = title_font |
|
621 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
622 | ws[col + str(current_row_number)] = _('Base Period') + " - " + base_period_data['names'][i] + \ |
|
623 | " (" + base_period_data['units'][i] + ")" |
|
624 | ws[col + str(current_row_number)].border = f_border |
|
625 | current_col_number += 1 |
|
626 | col = format_cell.get_column_letter(current_col_number) |
|
627 | ||
628 | ws[col + str(current_row_number)].fill = table_fill |
|
629 | ws[col + str(current_row_number)].font = title_font |
|
630 | ws[col + str(current_row_number)].border = f_border |
|
631 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
632 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " + _('Datetime') |
|
633 | ||
634 | for i in range(0, reporting_period_data_ca_len): |
|
635 | current_col_number += 1 |
|
636 | col = format_cell.get_column_letter(current_col_number) |
|
637 | ws[col + str(current_row_number)].fill = table_fill |
|
638 | ws[col + str(current_row_number)].font = title_font |
|
639 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
640 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " \ |
|
641 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
642 | ws[col + str(current_row_number)].border = f_border |
|
643 | ||
644 | current_row_number += 1 |
|
645 | ||
646 | max_timestamps_len = len(base_period_timestamps[0]) \ |
|
647 | if len(base_period_timestamps[0]) >= len(reporting_period_timestamps[0]) \ |
|
648 | else len(reporting_period_timestamps[0]) |
|
649 | ||
650 | for i in range(0, max_timestamps_len): |
|
651 | current_col_number = 2 |
|
652 | col = format_cell.get_column_letter(current_col_number) |
|
653 | ws[col + str(current_row_number)].font = title_font |
|
654 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
655 | ws[col + str(current_row_number)] = base_period_timestamps[0][i] \ |
|
656 | if i < len(base_period_timestamps[0]) else None |
|
657 | ws[col + str(current_row_number)].border = f_border |
|
658 | ||
659 | for j in range(0, base_period_data_ca_len): |
|
660 | current_col_number += 1 |
|
661 | col = format_cell.get_column_letter(current_col_number) |
|
662 | ||
663 | ws[col + str(current_row_number)].font = title_font |
|
664 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
665 | ws[col + str(current_row_number)] = round2(base_period_data['values_saving'][j][i], 2) \ |
|
666 | if i < len(base_period_data['values_saving'][j]) else None |
|
667 | ws[col + str(current_row_number)].border = f_border |
|
668 | current_col_number += 1 |
|
669 | col = format_cell.get_column_letter(current_col_number) |
|
670 | ||
671 | ws[col + str(current_row_number)].font = title_font |
|
672 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
673 | ws[col + str(current_row_number)] = reporting_period_timestamps[0][i] \ |
|
674 | if i < len(reporting_period_timestamps[0]) else None |
|
675 | ws[col + str(current_row_number)].border = f_border |
|
676 | ||
677 | for j in range(0, reporting_period_data_ca_len): |
|
678 | current_col_number += 1 |
|
679 | col = format_cell.get_column_letter(current_col_number) |
|
680 | ||
681 | ws[col + str(current_row_number)].font = title_font |
|
682 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
683 | ws[col + str(current_row_number)] = round2(reporting_period_data['values_saving'][j][i], 2) \ |
|
684 | if i < len(reporting_period_data['values_saving'][j]) else None |
|
685 | ws[col + str(current_row_number)].border = f_border |
|
686 | ||
687 | current_row_number += 1 |
|
688 | ||
689 | current_col_number = 2 |
|
690 | col = format_cell.get_column_letter(current_col_number) |
|
691 | ws[col + str(current_row_number)].font = title_font |
|
692 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
693 | ws[col + str(current_row_number)] = _('Subtotal') |
|
694 | ws[col + str(current_row_number)].border = f_border |
|
695 | ||
696 | for i in range(0, base_period_data_ca_len): |
|
697 | current_col_number += 1 |
|
698 | col = format_cell.get_column_letter(current_col_number) |
|
699 | ws[col + str(current_row_number)].font = title_font |
|
700 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
701 | ws[col + str(current_row_number)] = round2(base_period_data['subtotals_saving'][i], 2) |
|
702 | ws[col + str(current_row_number)].border = f_border |
|
703 | ||
704 | current_col_number += 1 |
|
705 | col = format_cell.get_column_letter(current_col_number) |
|
706 | ||
707 | ws[col + str(current_row_number)].font = title_font |
|
708 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
709 | ws[col + str(current_row_number)] = _('Subtotal') |
|
710 | ws[col + str(current_row_number)].border = f_border |
|
711 | ||
712 | for i in range(0, reporting_period_data_ca_len): |
|
713 | current_col_number += 1 |
|
714 | col = format_cell.get_column_letter(current_col_number) |
|
715 | ws[col + str(current_row_number)].font = title_font |
|
716 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
717 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
718 | ws[col + str(current_row_number)].border = f_border |
|
719 | ||
720 | for i in range(0, reporting_period_data_ca_len): |
|
721 | # line |
|
722 | line = LineChart() |
|
723 | line.title = _('Base Period Saving') + ' / ' \ |
|
724 | + _('Reporting Period Saving') + ' - ' \ |
|
725 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
726 | labels = Reference(ws, min_col=2 + base_period_data_ca_len + 1, |
|
727 | min_row=table_start_row_number + 1, |
|
728 | max_row=table_start_row_number + len(reporting_period_timestamps[0])) |
|
729 | base_line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, |
|
730 | max_row=table_start_row_number + len(reporting_period_timestamps[0])) |
|
731 | reporting_line_data = Reference(ws, min_col=3 + base_period_data_ca_len + 1 + i, |
|
732 | min_row=table_start_row_number, |
|
733 | max_row=table_start_row_number |
|
734 | + len(reporting_period_timestamps[0])) |
|
735 | line.add_data(base_line_data, titles_from_data=True) |
|
736 | line.add_data(reporting_line_data, titles_from_data=True) |
|
737 | line.set_categories(labels) |
|
738 | for j in range(len(line.series)): |
|
739 | line.series[j].marker.symbol = "auto" |
|
740 | line.series[j].smooth = True |
|
741 | line.x_axis.crosses = 'min' |
|
742 | line.height = 8.25 |
|
743 | line.width = 24 |
|
744 | chart_col = 'B' |
|
745 | chart_cell = chart_col + str(table_start_draw_flag + 6 * i) |
|
746 | ws.add_chart(line, chart_cell) |
|
747 | ||
748 | current_row_number += 2 |
|
749 | ||
750 | #################################################################################################################### |
|
751 | if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \ |
|
752 | len(report['child_space']["energy_category_names"]) == 0 \ |
|
753 | or 'child_space_names_array' not in report['child_space'].keys() \ |
|
754 | or report['child_space']['energy_category_names'] is None \ |
|
755 | or len(report['child_space']['child_space_names_array']) == 0 \ |
|
756 | or len(report['child_space']['child_space_names_array'][0]) == 0: |
|
757 | pass |
|
758 | else: |
|
759 | child_space_data = report['child_space'] |
|
760 | ca_len = len(child_space_data['energy_category_names']) |
|
761 | ||
762 | ws['B' + str(current_row_number)].font = title_font |
|
763 | ws['B' + str(current_row_number)] = name + ' ' + _('Child Spaces Data') |
|
764 | ||
765 | current_row_number += 1 |
|
766 | table_start_row_number = current_row_number |
|
767 | ||
768 | ws.row_dimensions[current_row_number].height = 60 |
|
769 | ws['B' + str(current_row_number)].fill = table_fill |
|
770 | ws['B' + str(current_row_number)].font = name_font |
|
771 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
772 | ws['B' + str(current_row_number)].border = f_border |
|
773 | ws['B' + str(current_row_number)] = _('Child Space') |
|
774 | ||
775 | col = 'C' |
|
776 | ||
777 | for i in range(0, ca_len): |
|
778 | ws[col + str(current_row_number)].fill = table_fill |
|
779 | ws[col + str(current_row_number)].font = name_font |
|
780 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
781 | ws[col + str(current_row_number)].border = f_border |
|
782 | ws[col + str(current_row_number)] = \ |
|
783 | child_space_data['energy_category_names'][i] + " (" + child_space_data['units'][i] + ")" |
|
784 | col = chr(ord(col) + 1) |
|
785 | ||
786 | current_row_number += 1 |
|
787 | ca_child_len = len(child_space_data['child_space_names_array'][0]) |
|
788 | ||
789 | for i in range(0, ca_child_len): |
|
790 | ws['B' + str(current_row_number)].font = title_font |
|
791 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
792 | ws['B' + str(current_row_number)].border = f_border |
|
793 | ws['B' + str(current_row_number)] = child_space_data['child_space_names_array'][0][i] |
|
794 | current_row_number += 1 |
|
795 | ||
796 | current_row_number -= ca_child_len |
|
797 | ||
798 | for i in range(0, ca_child_len): |
|
799 | col = 'C' |
|
800 | for j in range(0, ca_len): |
|
801 | ws[col + str(current_row_number)].font = name_font |
|
802 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
803 | ws[col + str(current_row_number)].border = f_border |
|
804 | ws[col + str(current_row_number)] = round2(child_space_data['subtotals_saving_array'][j][i], 2) |
|
805 | col = chr(ord(col) + 1) |
|
806 | ||
807 | current_row_number += 1 |
|
808 | ||
809 | table_end_row_number = current_row_number - 1 |
|
810 | ||
811 | for i in range(0, ca_len): |
|
812 | pie = PieChart() |
|
813 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
814 | pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number) |
|
815 | pie.add_data(pie_data, titles_from_data=True) |
|
816 | pie.set_categories(labels) |
|
817 | pie.title = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
818 | pie.height = 6.6 |
|
819 | pie.width = 9 |
|
820 | s1 = pie.series[0] |
|
821 | s1.dLbls = DataLabelList() |
|
822 | s1.dLbls.showCatName = False |
|
823 | s1.dLbls.showVal = False |
|
824 | s1.dLbls.showPercent = True |
|
825 | if i % 2 == 0: |
|
826 | chart_cell = 'B' + str(current_row_number) |
|
827 | else: |
|
828 | chart_cell = 'E' + str(current_row_number) |
|
829 | current_row_number += 5 |
|
830 | ws.add_chart(pie, chart_cell) |
|
831 | ||
832 | if ca_len % 2 == 1: |
|
833 | current_row_number += 5 |
|
834 | ||
835 | current_row_number += 1 |
|
836 | #################################################################################################################### |
|
837 | current_sheet_parameters_row_number = table_start_draw_flag + len(reporting_period_data['names']) * 6 + 1 |
|
838 | if 'parameters' not in report.keys() or \ |
|
839 | report['parameters'] is None or \ |
|
840 | 'names' not in report['parameters'].keys() or \ |
|
841 | report['parameters']['names'] is None or \ |
|
842 | len(report['parameters']['names']) == 0 or \ |
|
843 | 'timestamps' not in report['parameters'].keys() or \ |
|
844 | report['parameters']['timestamps'] is None or \ |
|
845 | len(report['parameters']['timestamps']) == 0 or \ |
|
846 | 'values' not in report['parameters'].keys() or \ |
|
847 | report['parameters']['values'] is None or \ |
|
848 | len(report['parameters']['values']) == 0 or \ |
|
849 | timestamps_data_all_equal_0(report['parameters']['timestamps']): |
|
850 | pass |
|
851 | else: |
|
852 | ################################################################################################################ |
|
853 | # new worksheet |
|
854 | ################################################################################################################ |
|
855 | ||
856 | parameters_data = report['parameters'] |
|
857 | parameters_names_len = len(parameters_data['names']) |
|
858 | ||
859 | file_name = ws.title |
|
860 | parameters_ws = wb.create_sheet(file_name + _('Parameters')) |
|
861 | ||
862 | parameters_timestamps_data_max_len = \ |
|
863 | get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps'])) |
|
864 | ||
865 | # Row height |
|
866 | parameters_ws.row_dimensions[1].height = 102 |
|
867 | for i in range(2, 7 + 1): |
|
868 | parameters_ws.row_dimensions[i].height = 42 |
|
869 | ||
870 | for i in range(8, parameters_timestamps_data_max_len + 10): |
|
871 | parameters_ws.row_dimensions[i].height = 60 |
|
872 | ||
873 | # Col width |
|
874 | parameters_ws.column_dimensions['A'].width = 1.5 |
|
875 | ||
876 | parameters_ws.column_dimensions['B'].width = 25.0 |
|
877 | ||
878 | for i in range(3, 12 + parameters_names_len * 3): |
|
879 | parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0 |
|
880 | ||
881 | # Img |
|
882 | img = Image("excelexporters/myems.png") |
|
883 | parameters_ws.add_image(img, 'A1') |
|
884 | ||
885 | # Title |
|
886 | parameters_ws['B3'].alignment = b_r_alignment |
|
887 | parameters_ws['B3'] = _('Name') + ':' |
|
888 | parameters_ws['C3'].border = b_border |
|
889 | parameters_ws['C3'].alignment = b_c_alignment |
|
890 | parameters_ws['C3'] = name |
|
891 | ||
892 | parameters_ws['D3'].alignment = b_r_alignment |
|
893 | parameters_ws['D3'] = _('Period Type') + ':' |
|
894 | parameters_ws['E3'].border = b_border |
|
895 | parameters_ws['E3'].alignment = b_c_alignment |
|
896 | parameters_ws['E3'] = period_type |
|
897 | ||
898 | parameters_ws['B4'].alignment = b_r_alignment |
|
899 | parameters_ws['B4'] = _('Reporting Start Datetime') + ':' |
|
900 | parameters_ws['C4'].border = b_border |
|
901 | parameters_ws['C4'].alignment = b_c_alignment |
|
902 | parameters_ws['C4'] = reporting_start_datetime_local |
|
903 | ||
904 | parameters_ws['D4'].alignment = b_r_alignment |
|
905 | parameters_ws['D4'] = _('Reporting End Datetime') + ':' |
|
906 | parameters_ws['E4'].border = b_border |
|
907 | parameters_ws['E4'].alignment = b_c_alignment |
|
908 | parameters_ws['E4'] = reporting_end_datetime_local |
|
909 | ||
910 | parameters_ws_current_row_number = 6 |
|
911 | ||
912 | parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font |
|
913 | parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' ' + _('Parameters') |
|
914 | ||
915 | parameters_ws_current_row_number += 1 |
|
916 | ||
917 | parameters_table_start_row_number = parameters_ws_current_row_number |
|
918 | ||
919 | parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80 |
|
920 | ||
921 | parameters_ws_current_row_number += 1 |
|
922 | ||
923 | table_current_col_number = 2 |
|
924 | ||
925 | for i in range(0, parameters_names_len): |
|
926 | ||
927 | if len(parameters_data['timestamps'][i]) == 0: |
|
928 | continue |
|
929 | ||
930 | col = format_cell.get_column_letter(table_current_col_number) |
|
931 | ||
932 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
|
933 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
|
934 | ||
935 | col = format_cell.get_column_letter(table_current_col_number + 1) |
|
936 | ||
937 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
|
938 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
|
939 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].font = name_font |
|
940 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].alignment = c_c_alignment |
|
941 | parameters_ws[col + str(parameters_ws_current_row_number - 1)] = parameters_data['names'][i] |
|
942 | ||
943 | table_current_row_number = parameters_ws_current_row_number |
|
944 | ||
945 | for j, value in enumerate(list(parameters_data['timestamps'][i])): |
|
946 | col = format_cell.get_column_letter(table_current_col_number) |
|
947 | ||
948 | parameters_ws[col + str(table_current_row_number)].border = f_border |
|
949 | parameters_ws[col + str(table_current_row_number)].font = title_font |
|
950 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
|
951 | parameters_ws[col + str(table_current_row_number)] = value |
|
952 | ||
953 | col = format_cell.get_column_letter(table_current_col_number + 1) |
|
954 | ||
955 | parameters_ws[col + str(table_current_row_number)].border = f_border |
|
956 | parameters_ws[col + str(table_current_row_number)].font = title_font |
|
957 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
|
958 | parameters_ws[col + str(table_current_row_number)] = round2(parameters_data['values'][i][j], 2) |
|
959 | ||
960 | table_current_row_number += 1 |
|
961 | ||
962 | table_current_col_number = table_current_col_number + 3 |
|
963 | ||
964 | ################################################################################################################ |
|
965 | # parameters chart and parameters table |
|
966 | ################################################################################################################ |
|
967 | ||
968 | ws['B' + str(current_sheet_parameters_row_number)].font = title_font |
|
969 | ws['B' + str(current_sheet_parameters_row_number)] = name + ' ' + _('Parameters') |
|
970 | ||
971 | current_sheet_parameters_row_number += 1 |
|
972 | ||
973 | chart_start_row_number = current_sheet_parameters_row_number |
|
974 | ||
975 | col_index = 0 |
|
976 | ||
977 | for i in range(0, parameters_names_len): |
|
978 | ||
979 | if len(parameters_data['timestamps'][i]) == 0: |
|
980 | continue |
|
981 | ||
982 | line = LineChart() |
|
983 | data_col = 3 + col_index * 3 |
|
984 | labels_col = 2 + col_index * 3 |
|
985 | col_index += 1 |
|
986 | line.title = _('Parameters') + ' - ' + \ |
|
987 | parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value |
|
988 | labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1, |
|
989 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
|
990 | line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number, |
|
991 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
|
992 | line.add_data(line_data, titles_from_data=True) |
|
993 | line.set_categories(labels) |
|
994 | line_data = line.series[0] |
|
995 | line_data.marker.symbol = "auto" |
|
996 | line_data.smooth = True |
|
997 | line.x_axis.crosses = 'min' |
|
998 | line.height = 8.25 |
|
999 | line.width = 24 |
|
1000 | chart_col = 'B' |
|
1001 | chart_cell = chart_col + str(chart_start_row_number) |
|
1002 | chart_start_row_number += 6 |
|
1003 | ws.add_chart(line, chart_cell) |
|
1004 | ||
1005 | current_sheet_parameters_row_number = chart_start_row_number |
|
1006 | ||
1007 | current_sheet_parameters_row_number += 1 |
|
1008 | #################################################################################################################### |
|
1009 | filename = str(uuid.uuid4()) + '.xlsx' |
|
1010 | wb.save(filename) |
|
1011 | ||
1012 | return filename |
|
1013 | ||
1014 | ||
1015 | def sum_list(lists): |
@@ 70-1012 (lines=943) @@ | ||
67 | return base64_message |
|
68 | ||
69 | ||
70 | def generate_excel(report, |
|
71 | name, |
|
72 | base_period_start_datetime_local, |
|
73 | base_period_end_datetime_local, |
|
74 | reporting_start_datetime_local, |
|
75 | reporting_end_datetime_local, |
|
76 | period_type, |
|
77 | language): |
|
78 | trans = get_translation(language) |
|
79 | trans.install() |
|
80 | _ = trans.gettext |
|
81 | wb = Workbook() |
|
82 | ws = wb.active |
|
83 | ws.title = "SpacePlan" |
|
84 | ||
85 | # Row height |
|
86 | ws.row_dimensions[1].height = 102 |
|
87 | for i in range(2, 2000 + 1): |
|
88 | ws.row_dimensions[i].height = 42 |
|
89 | ||
90 | # Col width |
|
91 | ws.column_dimensions['A'].width = 1.5 |
|
92 | ||
93 | ws.column_dimensions['B'].width = 25.0 |
|
94 | ||
95 | for i in range(ord('C'), ord('Z')): |
|
96 | ws.column_dimensions[chr(i)].width = 15.0 |
|
97 | ||
98 | # Font |
|
99 | name_font = Font(name='Arial', size=15, bold=True) |
|
100 | title_font = Font(name='Arial', size=15, bold=True) |
|
101 | ||
102 | table_fill = PatternFill(fill_type='solid', fgColor='90ee90') |
|
103 | f_border = Border(left=Side(border_style='medium'), |
|
104 | right=Side(border_style='medium'), |
|
105 | bottom=Side(border_style='medium'), |
|
106 | top=Side(border_style='medium') |
|
107 | ) |
|
108 | b_border = Border( |
|
109 | bottom=Side(border_style='medium'), |
|
110 | ) |
|
111 | ||
112 | b_c_alignment = Alignment(vertical='bottom', |
|
113 | horizontal='center', |
|
114 | text_rotation=0, |
|
115 | wrap_text=True, |
|
116 | shrink_to_fit=False, |
|
117 | indent=0) |
|
118 | c_c_alignment = Alignment(vertical='center', |
|
119 | horizontal='center', |
|
120 | text_rotation=0, |
|
121 | wrap_text=True, |
|
122 | shrink_to_fit=False, |
|
123 | indent=0) |
|
124 | b_r_alignment = Alignment(vertical='bottom', |
|
125 | horizontal='right', |
|
126 | text_rotation=0, |
|
127 | wrap_text=True, |
|
128 | shrink_to_fit=False, |
|
129 | indent=0) |
|
130 | ||
131 | # Img |
|
132 | img = Image("excelexporters/myems.png") |
|
133 | ws.add_image(img, 'A1') |
|
134 | ||
135 | # Title |
|
136 | ws['B3'].alignment = b_r_alignment |
|
137 | ws['B3'] = _('Name') + ':' |
|
138 | ws['C3'].border = b_border |
|
139 | ws['C3'].alignment = b_c_alignment |
|
140 | ws['C3'] = name |
|
141 | ||
142 | ws['D3'].alignment = b_r_alignment |
|
143 | ws['D3'] = _('Period Type') + ':' |
|
144 | ws['E3'].border = b_border |
|
145 | ws['E3'].alignment = b_c_alignment |
|
146 | ws['E3'] = period_type |
|
147 | ||
148 | ws['B4'].alignment = b_r_alignment |
|
149 | ws['B4'] = _('Reporting Start Datetime') + ':' |
|
150 | ws['C4'].border = b_border |
|
151 | ws['C4'].alignment = b_c_alignment |
|
152 | ws['C4'] = reporting_start_datetime_local |
|
153 | ||
154 | ws['D4'].alignment = b_r_alignment |
|
155 | ws['D4'] = _('Reporting End Datetime') + ':' |
|
156 | ws['E4'].border = b_border |
|
157 | ws['E4'].alignment = b_c_alignment |
|
158 | ws['E4'] = reporting_end_datetime_local |
|
159 | ||
160 | is_base_period_timestamp_exists_flag = is_base_period_timestamp_exists(report['base_period']) |
|
161 | ||
162 | if is_base_period_timestamp_exists_flag: |
|
163 | ws['B5'].alignment = b_r_alignment |
|
164 | ws['B5'] = _('Base Period Start Datetime') + ':' |
|
165 | ws['C5'].border = b_border |
|
166 | ws['C5'].alignment = b_c_alignment |
|
167 | ws['C5'] = base_period_start_datetime_local |
|
168 | ||
169 | ws['D5'].alignment = b_r_alignment |
|
170 | ws['D5'] = _('Base Period End Datetime') + ':' |
|
171 | ws['E5'].border = b_border |
|
172 | ws['E5'].alignment = b_c_alignment |
|
173 | ws['E5'] = base_period_end_datetime_local |
|
174 | ||
175 | if "reporting_period" not in report.keys() or \ |
|
176 | "names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0: |
|
177 | filename = str(uuid.uuid4()) + '.xlsx' |
|
178 | wb.save(filename) |
|
179 | ||
180 | return filename |
|
181 | ||
182 | #################################################################################################################### |
|
183 | current_row_number = 7 |
|
184 | reporting_period_data = report['reporting_period'] |
|
185 | if "names" not in reporting_period_data.keys() or \ |
|
186 | reporting_period_data['names'] is None or \ |
|
187 | len(reporting_period_data['names']) == 0: |
|
188 | pass |
|
189 | else: |
|
190 | ws['B' + str(current_row_number)].font = title_font |
|
191 | ws['B' + str(current_row_number)] = name + ' ' + _('Reporting Period Plan') |
|
192 | ||
193 | current_row_number += 1 |
|
194 | ||
195 | category = reporting_period_data['names'] |
|
196 | ca_len = len(category) |
|
197 | ||
198 | ws.row_dimensions[current_row_number].height = 75 |
|
199 | ws['B' + str(current_row_number)].fill = table_fill |
|
200 | ws['B' + str(current_row_number)].border = f_border |
|
201 | ||
202 | col = 'C' |
|
203 | ||
204 | for i in range(0, ca_len): |
|
205 | ws[col + str(current_row_number)].fill = table_fill |
|
206 | ws[col + str(current_row_number)].font = name_font |
|
207 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
208 | ws[col + str(current_row_number)].border = f_border |
|
209 | ws[col + str(current_row_number)] = \ |
|
210 | reporting_period_data['names'][i] + " (" + _('Baseline') + ' - ' \ |
|
211 | + _('Actual') + ")(" + reporting_period_data['units'][i] + ")" |
|
212 | ||
213 | col = chr(ord(col) + 1) |
|
214 | ||
215 | ws[col + str(current_row_number)].fill = table_fill |
|
216 | ws[col + str(current_row_number)].font = name_font |
|
217 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
218 | ws[col + str(current_row_number)].border = f_border |
|
219 | ws[col + str(current_row_number)] = _('Ton of Standard Coal') + ' (' \ |
|
220 | + _('Baseline') + ' - ' + _('Actual') + ') (TCE)' |
|
221 | ||
222 | col = chr(ord(col) + 1) |
|
223 | ||
224 | ws[col + str(current_row_number)].fill = table_fill |
|
225 | ws[col + str(current_row_number)].font = name_font |
|
226 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
227 | ws[col + str(current_row_number)].border = f_border |
|
228 | ws[col + str(current_row_number)] = _('Ton of Carbon Dioxide Emissions') \ |
|
229 | + ' (' + _('Baseline') + ' - ' + _('Actual') + ') (TCO2E)' |
|
230 | ||
231 | current_row_number += 1 |
|
232 | ||
233 | ws['B' + str(current_row_number)].font = title_font |
|
234 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
235 | ws['B' + str(current_row_number)].border = f_border |
|
236 | ws['B' + str(current_row_number)] = _('Plan') |
|
237 | ||
238 | col = 'C' |
|
239 | ||
240 | for i in range(0, ca_len): |
|
241 | ws[col + str(current_row_number)].font = name_font |
|
242 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
243 | ws[col + str(current_row_number)].border = f_border |
|
244 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
245 | ||
246 | col = chr(ord(col) + 1) |
|
247 | ||
248 | ws[col + str(current_row_number)].font = name_font |
|
249 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
250 | ws[col + str(current_row_number)].border = f_border |
|
251 | ws[col + str(current_row_number)] = round2(reporting_period_data['total_in_kgce_saving'] / 1000, 2) |
|
252 | ||
253 | col = chr(ord(col) + 1) |
|
254 | ||
255 | ws[col + str(current_row_number)].font = name_font |
|
256 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
257 | ws[col + str(current_row_number)].border = f_border |
|
258 | ws[col + str(current_row_number)] = round2(reporting_period_data['total_in_kgco2e_saving'] / 1000, 2) |
|
259 | ||
260 | current_row_number += 1 |
|
261 | ||
262 | ws['B' + str(current_row_number)].font = title_font |
|
263 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
264 | ws['B' + str(current_row_number)].border = f_border |
|
265 | ws['B' + str(current_row_number)] = _('Per Unit Area') |
|
266 | ||
267 | col = 'C' |
|
268 | ||
269 | for i in range(0, ca_len): |
|
270 | ws[col + str(current_row_number)].font = name_font |
|
271 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
272 | ws[col + str(current_row_number)].border = f_border |
|
273 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_per_unit_area_saving'][i], 2) \ |
|
274 | if reporting_period_data['subtotals_per_unit_area_saving'][i] is not None else '' |
|
275 | ||
276 | col = chr(ord(col) + 1) |
|
277 | ||
278 | ws[col + str(current_row_number)].font = name_font |
|
279 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
280 | ws[col + str(current_row_number)].border = f_border |
|
281 | ws[col + str(current_row_number)] = \ |
|
282 | round2(reporting_period_data['total_in_kgce_per_unit_area_saving'] / 1000, 2) \ |
|
283 | if reporting_period_data['total_in_kgce_per_unit_area_saving'] is not None else '' |
|
284 | ||
285 | col = chr(ord(col) + 1) |
|
286 | ||
287 | ws[col + str(current_row_number)].font = name_font |
|
288 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
289 | ws[col + str(current_row_number)].border = f_border |
|
290 | ws[col + str(current_row_number)] = \ |
|
291 | round2(reporting_period_data['total_in_kgco2e_per_unit_area_saving'] / 1000, 2) \ |
|
292 | if reporting_period_data['total_in_kgco2e_per_unit_area_saving'] is not None else '' |
|
293 | ||
294 | current_row_number += 1 |
|
295 | ||
296 | ws['B' + str(current_row_number)].font = title_font |
|
297 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
298 | ws['B' + str(current_row_number)].border = f_border |
|
299 | ws['B' + str(current_row_number)] = _('Increment Rate') |
|
300 | ||
301 | col = 'C' |
|
302 | ||
303 | for i in range(0, ca_len): |
|
304 | ws[col + str(current_row_number)].font = name_font |
|
305 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
306 | ws[col + str(current_row_number)].border = f_border |
|
307 | ws[col + str(current_row_number)] = str( |
|
308 | round2(reporting_period_data['increment_rates_saving'][i] * 100, 2)) + '%' \ |
|
309 | if reporting_period_data['increment_rates_saving'][i] is not None else '-' |
|
310 | ||
311 | col = chr(ord(col) + 1) |
|
312 | ||
313 | ws[col + str(current_row_number)].font = name_font |
|
314 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
315 | ws[col + str(current_row_number)].border = f_border |
|
316 | ws[col + str(current_row_number)] = str( |
|
317 | round2(reporting_period_data['increment_rate_in_kgce_saving'] * 100, 2)) + '%' \ |
|
318 | if reporting_period_data['increment_rate_in_kgce_saving'] is not None else '-' |
|
319 | ||
320 | col = chr(ord(col) + 1) |
|
321 | ||
322 | ws[col + str(current_row_number)].font = name_font |
|
323 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
324 | ws[col + str(current_row_number)].border = f_border |
|
325 | ws[col + str(current_row_number)] = str( |
|
326 | round2(reporting_period_data['increment_rate_in_kgco2e_saving'] * 100, 2)) + '%' \ |
|
327 | if reporting_period_data['increment_rate_in_kgco2e_saving'] is not None else '-' |
|
328 | ||
329 | current_row_number += 2 |
|
330 | ||
331 | ws['B' + str(current_row_number)].font = title_font |
|
332 | ws['B' + str(current_row_number)] = name + ' ' + _('Ton of Standard Coal(TCE) by Energy Category') |
|
333 | ||
334 | current_row_number += 1 |
|
335 | table_start_row_number = current_row_number |
|
336 | chart_start_row_number = current_row_number |
|
337 | ||
338 | ws.row_dimensions[current_row_number].height = 60 |
|
339 | ws['B' + str(current_row_number)].fill = table_fill |
|
340 | ws['B' + str(current_row_number)].border = f_border |
|
341 | ||
342 | ws['C' + str(current_row_number)].fill = table_fill |
|
343 | ws['C' + str(current_row_number)].font = name_font |
|
344 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
345 | ws['C' + str(current_row_number)].border = f_border |
|
346 | ws['C' + str(current_row_number)] = _('Plan') |
|
347 | ||
348 | ws['D' + str(current_row_number)].fill = table_fill |
|
349 | ws['D' + str(current_row_number)].font = name_font |
|
350 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
351 | ws['D' + str(current_row_number)].border = f_border |
|
352 | ws['D' + str(current_row_number)] = _('Ton of Standard Coal(TCE) by Energy Category') |
|
353 | ||
354 | current_row_number += 1 |
|
355 | ||
356 | subtotals_in_kgce_saving_sum = sum_list(reporting_period_data['subtotals_in_kgce_saving']) |
|
357 | ||
358 | for i in range(0, ca_len): |
|
359 | ws['B' + str(current_row_number)].font = title_font |
|
360 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
361 | ws['B' + str(current_row_number)].border = f_border |
|
362 | ws['B' + str(current_row_number)] = reporting_period_data['names'][i] |
|
363 | ||
364 | ws['C' + str(current_row_number)].font = name_font |
|
365 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
366 | ws['C' + str(current_row_number)].border = f_border |
|
367 | ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals_in_kgce_saving'][i] / 1000, 3) |
|
368 | ||
369 | ws['D' + str(current_row_number)].font = name_font |
|
370 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
371 | ws['D' + str(current_row_number)].border = f_border |
|
372 | ws['D' + str(current_row_number)] = str(round2(reporting_period_data['subtotals_in_kgce_saving'][i] / |
|
373 | subtotals_in_kgce_saving_sum * 100, 2)) + '%'\ |
|
374 | if abs(subtotals_in_kgce_saving_sum) > 0 else '-' |
|
375 | ||
376 | current_row_number += 1 |
|
377 | ||
378 | table_end_row_number = current_row_number - 1 |
|
379 | ||
380 | if ca_len < 4: |
|
381 | current_row_number = current_row_number - ca_len + 4 |
|
382 | ||
383 | current_row_number += 1 |
|
384 | ||
385 | pie = PieChart() |
|
386 | pie.title = name + ' ' + _('Ton of Standard Coal(TCE) by Energy Category') |
|
387 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
388 | pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number) |
|
389 | pie.add_data(pie_data, titles_from_data=True) |
|
390 | pie.set_categories(labels) |
|
391 | pie.height = 7.25 |
|
392 | pie.width = 9 |
|
393 | s1 = pie.series[0] |
|
394 | s1.dLbls = DataLabelList() |
|
395 | s1.dLbls.showCatName = False |
|
396 | s1.dLbls.showVal = False |
|
397 | s1.dLbls.showPercent = True |
|
398 | ws.add_chart(pie, 'E' + str(chart_start_row_number)) |
|
399 | ||
400 | ws['B' + str(current_row_number)].font = title_font |
|
401 | ws['B' + str(current_row_number)] = name + ' ' + _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
402 | ||
403 | current_row_number += 1 |
|
404 | table_start_row_number = current_row_number |
|
405 | chart_start_row_number = current_row_number |
|
406 | ||
407 | ws.row_dimensions[current_row_number].height = 60 |
|
408 | ws['B' + str(current_row_number)].fill = table_fill |
|
409 | ws['B' + str(current_row_number)].border = f_border |
|
410 | ||
411 | ws['C' + str(current_row_number)].fill = table_fill |
|
412 | ws['C' + str(current_row_number)].font = name_font |
|
413 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
414 | ws['C' + str(current_row_number)].border = f_border |
|
415 | ws['C' + str(current_row_number)] = _('Plan') |
|
416 | ||
417 | ws['D' + str(current_row_number)].fill = table_fill |
|
418 | ws['D' + str(current_row_number)].font = name_font |
|
419 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
420 | ws['D' + str(current_row_number)].border = f_border |
|
421 | ws['D' + str(current_row_number)] = _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
422 | ||
423 | current_row_number += 1 |
|
424 | ||
425 | subtotals_in_kgco2e_saving_sum = sum_list(reporting_period_data['subtotals_in_kgco2e_saving']) |
|
426 | ||
427 | for i in range(0, ca_len): |
|
428 | ws['B' + str(current_row_number)].font = title_font |
|
429 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
430 | ws['B' + str(current_row_number)].border = f_border |
|
431 | ws['B' + str(current_row_number)] = reporting_period_data['names'][i] |
|
432 | ||
433 | ws['C' + str(current_row_number)].font = name_font |
|
434 | ws['C' + str(current_row_number)].alignment = c_c_alignment |
|
435 | ws['C' + str(current_row_number)].border = f_border |
|
436 | ws['C' + str(current_row_number)] = round2(reporting_period_data['subtotals_in_kgco2e_saving'][i] / 1000, 3) |
|
437 | ||
438 | ws['D' + str(current_row_number)].font = name_font |
|
439 | ws['D' + str(current_row_number)].alignment = c_c_alignment |
|
440 | ws['D' + str(current_row_number)].border = f_border |
|
441 | ws['D' + str(current_row_number)] = str(round2(reporting_period_data['subtotals_in_kgco2e_saving'][i] / |
|
442 | subtotals_in_kgco2e_saving_sum * 100, 2)) + '%'\ |
|
443 | if abs(subtotals_in_kgco2e_saving_sum) > 0 else '-' |
|
444 | ||
445 | current_row_number += 1 |
|
446 | ||
447 | table_end_row_number = current_row_number - 1 |
|
448 | ||
449 | if ca_len < 4: |
|
450 | current_row_number = current_row_number - ca_len + 4 |
|
451 | ||
452 | current_row_number += 1 |
|
453 | ||
454 | pie = PieChart() |
|
455 | pie.title = name + ' ' + _('Ton of Carbon Dioxide Emissions(TCO2E) by Energy Category') |
|
456 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
457 | pie_data = Reference(ws, min_col=3, min_row=table_start_row_number, max_row=table_end_row_number) |
|
458 | pie.add_data(pie_data, titles_from_data=True) |
|
459 | pie.set_categories(labels) |
|
460 | pie.height = 7.25 |
|
461 | pie.width = 9 |
|
462 | s1 = pie.series[0] |
|
463 | s1.dLbls = DataLabelList() |
|
464 | s1.dLbls.showCatName = False |
|
465 | s1.dLbls.showVal = False |
|
466 | s1.dLbls.showPercent = True |
|
467 | ws.add_chart(pie, 'E' + str(chart_start_row_number)) |
|
468 | ||
469 | #################################################################################################################### |
|
470 | table_start_draw_flag = current_row_number + 1 |
|
471 | ||
472 | if 'values_saving' not in reporting_period_data.keys() or \ |
|
473 | reporting_period_data['values_saving'] is None or \ |
|
474 | len(reporting_period_data['values_saving']) == 0 or \ |
|
475 | 'timestamps' not in reporting_period_data.keys() or \ |
|
476 | reporting_period_data['timestamps'] is None or \ |
|
477 | len(reporting_period_data['timestamps']) == 0 or \ |
|
478 | len(reporting_period_data['timestamps'][0]) == 0: |
|
479 | pass |
|
480 | else: |
|
481 | if not is_base_period_timestamp_exists_flag: |
|
482 | reporting_period_data = report['reporting_period'] |
|
483 | times = reporting_period_data['timestamps'] |
|
484 | ca_len = len(report['reporting_period']['names']) |
|
485 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
|
486 | ws['B' + str(current_row_number)].font = title_font |
|
487 | ws['B' + str(current_row_number)] = name + ' ' + _('Detailed Data') |
|
488 | ||
489 | current_row_number += 1 |
|
490 | # 1: Stand for blank line 2: Stand for title |
|
491 | current_row_number += ca_len * 6 + real_timestamps_len * 6 + 1 + 2 |
|
492 | table_start_row_number = current_row_number |
|
493 | ||
494 | time = times[0] |
|
495 | has_data = False |
|
496 | ||
497 | if len(time) > 0: |
|
498 | has_data = True |
|
499 | ||
500 | if has_data: |
|
501 | ||
502 | ws.row_dimensions[current_row_number].height = 60 |
|
503 | current_col_number = 2 |
|
504 | col = format_cell.get_column_letter(current_col_number) |
|
505 | ws[col + str(current_row_number)].fill = table_fill |
|
506 | ws[col + str(current_row_number)].font = title_font |
|
507 | ws[col + str(current_row_number)].border = f_border |
|
508 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
509 | ws[col + str(current_row_number)] = _('Datetime') |
|
510 | ||
511 | for i in range(0, ca_len): |
|
512 | current_col_number += 1 |
|
513 | col = format_cell.get_column_letter(current_col_number) |
|
514 | ||
515 | ws[col + str(current_row_number)].fill = table_fill |
|
516 | ws[col + str(current_row_number)].font = title_font |
|
517 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
518 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
|
519 | " (" + reporting_period_data['units'][i] + ")" |
|
520 | ws[col + str(current_row_number)].border = f_border |
|
521 | ||
522 | current_row_number += 1 |
|
523 | ||
524 | for i in range(0, len(time)): |
|
525 | current_col_number = 2 |
|
526 | col = format_cell.get_column_letter(current_col_number) |
|
527 | ws[col + str(current_row_number)].font = title_font |
|
528 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
529 | ws[col + str(current_row_number)] = time[i] |
|
530 | ws[col + str(current_row_number)].border = f_border |
|
531 | ||
532 | for j in range(0, ca_len): |
|
533 | current_col_number += 1 |
|
534 | col = format_cell.get_column_letter(current_col_number) |
|
535 | ||
536 | ws[col + str(current_row_number)].font = title_font |
|
537 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
538 | ws[col + str(current_row_number)] = round2(reporting_period_data['values_saving'][j][i], 2) |
|
539 | ws[col + str(current_row_number)].border = f_border |
|
540 | ||
541 | current_row_number += 1 |
|
542 | ||
543 | table_end_row_number = current_row_number - 1 |
|
544 | ||
545 | current_col_number = 2 |
|
546 | col = format_cell.get_column_letter(current_col_number) |
|
547 | ws[col + str(current_row_number)].font = title_font |
|
548 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
549 | ws[col + str(current_row_number)] = _('Subtotal') |
|
550 | ws[col + str(current_row_number)].border = f_border |
|
551 | ||
552 | for i in range(0, ca_len): |
|
553 | current_col_number += 1 |
|
554 | col = format_cell.get_column_letter(current_col_number) |
|
555 | ||
556 | ws[col + str(current_row_number)].font = title_font |
|
557 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
558 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
559 | ws[col + str(current_row_number)].border = f_border |
|
560 | ||
561 | # line |
|
562 | line = LineChart() |
|
563 | line.title = _('Reporting Period Plan') + ' - ' \ |
|
564 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
565 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
566 | line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, |
|
567 | max_row=table_end_row_number) |
|
568 | line.add_data(line_data, titles_from_data=True) |
|
569 | line.set_categories(labels) |
|
570 | line_data = line.series[0] |
|
571 | line_data.marker.symbol = "auto" |
|
572 | line_data.smooth = True |
|
573 | line.x_axis.crosses = 'min' |
|
574 | line.height = 8.25 |
|
575 | line.width = 24 |
|
576 | chart_col = 'B' |
|
577 | chart_cell = chart_col + str(table_start_draw_flag + 6 * i) |
|
578 | ws.add_chart(line, chart_cell) |
|
579 | ||
580 | current_row_number += 2 |
|
581 | else: |
|
582 | base_period_data = report['base_period'] |
|
583 | reporting_period_data = report['reporting_period'] |
|
584 | base_period_timestamps = base_period_data['timestamps'] |
|
585 | reporting_period_timestamps = reporting_period_data['timestamps'] |
|
586 | # Tip: |
|
587 | # base_period_data['names'] == reporting_period_data['names'] |
|
588 | # base_period_data['units'] == reporting_period_data['units'] |
|
589 | base_period_data_ca_len = len(base_period_data['names']) |
|
590 | reporting_period_data_ca_len = len(reporting_period_data['names']) |
|
591 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
|
592 | ws['B' + str(current_row_number)].font = title_font |
|
593 | ws['B' + str(current_row_number)] = name + ' ' + _('Detailed Data') |
|
594 | ||
595 | current_row_number += 1 |
|
596 | # 1: Stand for blank line 2: Stand for title |
|
597 | current_row_number += reporting_period_data_ca_len * 6 + real_timestamps_len * 6 + 1 + 2 |
|
598 | table_start_row_number = current_row_number |
|
599 | ||
600 | has_data = False |
|
601 | ||
602 | if len(base_period_timestamps[0]) or len(reporting_period_timestamps[0]) > 0: |
|
603 | has_data = True |
|
604 | ||
605 | if has_data: |
|
606 | ws.row_dimensions[current_row_number].height = 60 |
|
607 | current_col_number = 2 |
|
608 | col = format_cell.get_column_letter(current_col_number) |
|
609 | ws[col + str(current_row_number)].fill = table_fill |
|
610 | ws[col + str(current_row_number)].font = title_font |
|
611 | ws[col + str(current_row_number)].border = f_border |
|
612 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
613 | ws[col + str(current_row_number)] = _('Base Period') + " - " + _('Datetime') |
|
614 | ||
615 | for i in range(0, base_period_data_ca_len): |
|
616 | current_col_number += 1 |
|
617 | col = format_cell.get_column_letter(current_col_number) |
|
618 | ||
619 | ws[col + str(current_row_number)].fill = table_fill |
|
620 | ws[col + str(current_row_number)].font = title_font |
|
621 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
622 | ws[col + str(current_row_number)] = _('Base Period') + " - " + base_period_data['names'][i] + \ |
|
623 | " (" + base_period_data['units'][i] + ")" |
|
624 | ws[col + str(current_row_number)].border = f_border |
|
625 | current_col_number += 1 |
|
626 | col = format_cell.get_column_letter(current_col_number) |
|
627 | ||
628 | ws[col + str(current_row_number)].fill = table_fill |
|
629 | ws[col + str(current_row_number)].font = title_font |
|
630 | ws[col + str(current_row_number)].border = f_border |
|
631 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
632 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " + _('Datetime') |
|
633 | ||
634 | for i in range(0, reporting_period_data_ca_len): |
|
635 | current_col_number += 1 |
|
636 | col = format_cell.get_column_letter(current_col_number) |
|
637 | ws[col + str(current_row_number)].fill = table_fill |
|
638 | ws[col + str(current_row_number)].font = title_font |
|
639 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
640 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " \ |
|
641 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
642 | ws[col + str(current_row_number)].border = f_border |
|
643 | ||
644 | current_row_number += 1 |
|
645 | ||
646 | max_timestamps_len = len(base_period_timestamps[0]) \ |
|
647 | if len(base_period_timestamps[0]) >= len(reporting_period_timestamps[0]) \ |
|
648 | else len(reporting_period_timestamps[0]) |
|
649 | ||
650 | for i in range(0, max_timestamps_len): |
|
651 | current_col_number = 2 |
|
652 | col = format_cell.get_column_letter(current_col_number) |
|
653 | ws[col + str(current_row_number)].font = title_font |
|
654 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
655 | ws[col + str(current_row_number)] = base_period_timestamps[0][i] \ |
|
656 | if i < len(base_period_timestamps[0]) else None |
|
657 | ws[col + str(current_row_number)].border = f_border |
|
658 | ||
659 | for j in range(0, base_period_data_ca_len): |
|
660 | current_col_number += 1 |
|
661 | col = format_cell.get_column_letter(current_col_number) |
|
662 | ||
663 | ws[col + str(current_row_number)].font = title_font |
|
664 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
665 | ws[col + str(current_row_number)] = round2(base_period_data['values_saving'][j][i], 2) \ |
|
666 | if i < len(base_period_data['values_saving'][j]) else None |
|
667 | ws[col + str(current_row_number)].border = f_border |
|
668 | current_col_number += 1 |
|
669 | col = format_cell.get_column_letter(current_col_number) |
|
670 | ||
671 | ws[col + str(current_row_number)].font = title_font |
|
672 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
673 | ws[col + str(current_row_number)] = reporting_period_timestamps[0][i] \ |
|
674 | if i < len(reporting_period_timestamps[0]) else None |
|
675 | ws[col + str(current_row_number)].border = f_border |
|
676 | ||
677 | for j in range(0, reporting_period_data_ca_len): |
|
678 | current_col_number += 1 |
|
679 | col = format_cell.get_column_letter(current_col_number) |
|
680 | ||
681 | ws[col + str(current_row_number)].font = title_font |
|
682 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
683 | ws[col + str(current_row_number)] = round2(reporting_period_data['values_saving'][j][i], 2) \ |
|
684 | if i < len(reporting_period_data['values_saving'][j]) else None |
|
685 | ws[col + str(current_row_number)].border = f_border |
|
686 | ||
687 | current_row_number += 1 |
|
688 | ||
689 | current_col_number = 2 |
|
690 | col = format_cell.get_column_letter(current_col_number) |
|
691 | ws[col + str(current_row_number)].font = title_font |
|
692 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
693 | ws[col + str(current_row_number)] = _('Subtotal') |
|
694 | ws[col + str(current_row_number)].border = f_border |
|
695 | ||
696 | for i in range(0, base_period_data_ca_len): |
|
697 | current_col_number += 1 |
|
698 | col = format_cell.get_column_letter(current_col_number) |
|
699 | ws[col + str(current_row_number)].font = title_font |
|
700 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
701 | ws[col + str(current_row_number)] = round2(base_period_data['subtotals_saving'][i], 2) |
|
702 | ws[col + str(current_row_number)].border = f_border |
|
703 | ||
704 | current_col_number += 1 |
|
705 | col = format_cell.get_column_letter(current_col_number) |
|
706 | ||
707 | ws[col + str(current_row_number)].font = title_font |
|
708 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
709 | ws[col + str(current_row_number)] = _('Subtotal') |
|
710 | ws[col + str(current_row_number)].border = f_border |
|
711 | ||
712 | for i in range(0, reporting_period_data_ca_len): |
|
713 | current_col_number += 1 |
|
714 | col = format_cell.get_column_letter(current_col_number) |
|
715 | ws[col + str(current_row_number)].font = title_font |
|
716 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
717 | ws[col + str(current_row_number)] = round2(reporting_period_data['subtotals_saving'][i], 2) |
|
718 | ws[col + str(current_row_number)].border = f_border |
|
719 | ||
720 | for i in range(0, reporting_period_data_ca_len): |
|
721 | # line |
|
722 | line = LineChart() |
|
723 | line.title = _('Base Period Plan') + ' / ' \ |
|
724 | + _('Reporting Period Plan') + ' - ' \ |
|
725 | + reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
726 | labels = Reference(ws, min_col=2 + base_period_data_ca_len + 1, |
|
727 | min_row=table_start_row_number + 1, |
|
728 | max_row=table_start_row_number + len(reporting_period_timestamps[0])) |
|
729 | base_line_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, |
|
730 | max_row=table_start_row_number + len(reporting_period_timestamps[0])) |
|
731 | reporting_line_data = Reference(ws, min_col=3 + base_period_data_ca_len + 1 + i, |
|
732 | min_row=table_start_row_number, |
|
733 | max_row=table_start_row_number |
|
734 | + len(reporting_period_timestamps[0])) |
|
735 | line.add_data(base_line_data, titles_from_data=True) |
|
736 | line.add_data(reporting_line_data, titles_from_data=True) |
|
737 | line.set_categories(labels) |
|
738 | for j in range(len(line.series)): |
|
739 | line.series[j].marker.symbol = "auto" |
|
740 | line.series[j].smooth = True |
|
741 | line.x_axis.crosses = 'min' |
|
742 | line.height = 8.25 |
|
743 | line.width = 24 |
|
744 | chart_col = 'B' |
|
745 | chart_cell = chart_col + str(table_start_draw_flag + 6 * i) |
|
746 | ws.add_chart(line, chart_cell) |
|
747 | ||
748 | current_row_number += 2 |
|
749 | ||
750 | #################################################################################################################### |
|
751 | if "child_space" not in report.keys() or "energy_category_names" not in report['child_space'].keys() or \ |
|
752 | len(report['child_space']["energy_category_names"]) == 0 \ |
|
753 | or 'child_space_names_array' not in report['child_space'].keys() \ |
|
754 | or report['child_space']['energy_category_names'] is None \ |
|
755 | or len(report['child_space']['child_space_names_array']) == 0 \ |
|
756 | or len(report['child_space']['child_space_names_array'][0]) == 0: |
|
757 | pass |
|
758 | else: |
|
759 | child_space_data = report['child_space'] |
|
760 | ca_len = len(child_space_data['energy_category_names']) |
|
761 | ||
762 | ws['B' + str(current_row_number)].font = title_font |
|
763 | ws['B' + str(current_row_number)] = name + ' ' + _('Child Spaces Data') |
|
764 | ||
765 | current_row_number += 1 |
|
766 | table_start_row_number = current_row_number |
|
767 | ||
768 | ws.row_dimensions[current_row_number].height = 60 |
|
769 | ws['B' + str(current_row_number)].fill = table_fill |
|
770 | ws['B' + str(current_row_number)].font = name_font |
|
771 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
772 | ws['B' + str(current_row_number)].border = f_border |
|
773 | ws['B' + str(current_row_number)] = _('Child Space') |
|
774 | ||
775 | col = 'C' |
|
776 | ||
777 | for i in range(0, ca_len): |
|
778 | ws[col + str(current_row_number)].fill = table_fill |
|
779 | ws[col + str(current_row_number)].font = name_font |
|
780 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
781 | ws[col + str(current_row_number)].border = f_border |
|
782 | ws[col + str(current_row_number)] = \ |
|
783 | child_space_data['energy_category_names'][i] + " (" + child_space_data['units'][i] + ")" |
|
784 | col = chr(ord(col) + 1) |
|
785 | ||
786 | current_row_number += 1 |
|
787 | ca_child_len = len(child_space_data['child_space_names_array'][0]) |
|
788 | ||
789 | for i in range(0, ca_child_len): |
|
790 | ws['B' + str(current_row_number)].font = title_font |
|
791 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
|
792 | ws['B' + str(current_row_number)].border = f_border |
|
793 | ws['B' + str(current_row_number)] = child_space_data['child_space_names_array'][0][i] |
|
794 | current_row_number += 1 |
|
795 | ||
796 | current_row_number -= ca_child_len |
|
797 | ||
798 | for i in range(0, ca_child_len): |
|
799 | col = 'C' |
|
800 | for j in range(0, ca_len): |
|
801 | ws[col + str(current_row_number)].font = name_font |
|
802 | ws[col + str(current_row_number)].alignment = c_c_alignment |
|
803 | ws[col + str(current_row_number)].border = f_border |
|
804 | ws[col + str(current_row_number)] = round2(child_space_data['subtotals_saving_array'][j][i], 2) |
|
805 | col = chr(ord(col) + 1) |
|
806 | ||
807 | current_row_number += 1 |
|
808 | ||
809 | table_end_row_number = current_row_number - 1 |
|
810 | ||
811 | for i in range(0, ca_len): |
|
812 | pie = PieChart() |
|
813 | labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number) |
|
814 | pie_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number) |
|
815 | pie.add_data(pie_data, titles_from_data=True) |
|
816 | pie.set_categories(labels) |
|
817 | pie.title = reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")" |
|
818 | pie.height = 6.6 |
|
819 | pie.width = 9 |
|
820 | s1 = pie.series[0] |
|
821 | s1.dLbls = DataLabelList() |
|
822 | s1.dLbls.showCatName = False |
|
823 | s1.dLbls.showVal = False |
|
824 | s1.dLbls.showPercent = True |
|
825 | if i % 2 == 0: |
|
826 | chart_cell = 'B' + str(current_row_number) |
|
827 | else: |
|
828 | chart_cell = 'E' + str(current_row_number) |
|
829 | current_row_number += 5 |
|
830 | ws.add_chart(pie, chart_cell) |
|
831 | ||
832 | if ca_len % 2 == 1: |
|
833 | current_row_number += 5 |
|
834 | ||
835 | current_row_number += 1 |
|
836 | #################################################################################################################### |
|
837 | current_sheet_parameters_row_number = table_start_draw_flag + len(reporting_period_data['names']) * 6 + 1 |
|
838 | if 'parameters' not in report.keys() or \ |
|
839 | report['parameters'] is None or \ |
|
840 | 'names' not in report['parameters'].keys() or \ |
|
841 | report['parameters']['names'] is None or \ |
|
842 | len(report['parameters']['names']) == 0 or \ |
|
843 | 'timestamps' not in report['parameters'].keys() or \ |
|
844 | report['parameters']['timestamps'] is None or \ |
|
845 | len(report['parameters']['timestamps']) == 0 or \ |
|
846 | 'values' not in report['parameters'].keys() or \ |
|
847 | report['parameters']['values'] is None or \ |
|
848 | len(report['parameters']['values']) == 0 or \ |
|
849 | timestamps_data_all_equal_0(report['parameters']['timestamps']): |
|
850 | pass |
|
851 | else: |
|
852 | ################################################################################################################ |
|
853 | # new worksheet |
|
854 | ################################################################################################################ |
|
855 | ||
856 | parameters_data = report['parameters'] |
|
857 | parameters_names_len = len(parameters_data['names']) |
|
858 | ||
859 | file_name = ws.title |
|
860 | parameters_ws = wb.create_sheet(file_name + _('Parameters')) |
|
861 | ||
862 | parameters_timestamps_data_max_len = \ |
|
863 | get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps'])) |
|
864 | ||
865 | # Row height |
|
866 | parameters_ws.row_dimensions[1].height = 102 |
|
867 | for i in range(2, 7 + 1): |
|
868 | parameters_ws.row_dimensions[i].height = 42 |
|
869 | ||
870 | for i in range(8, parameters_timestamps_data_max_len + 10): |
|
871 | parameters_ws.row_dimensions[i].height = 60 |
|
872 | ||
873 | # Col width |
|
874 | parameters_ws.column_dimensions['A'].width = 1.5 |
|
875 | ||
876 | parameters_ws.column_dimensions['B'].width = 25.0 |
|
877 | ||
878 | for i in range(3, 12 + parameters_names_len * 3): |
|
879 | parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0 |
|
880 | ||
881 | # Img |
|
882 | img = Image("excelexporters/myems.png") |
|
883 | parameters_ws.add_image(img, 'A1') |
|
884 | ||
885 | # Title |
|
886 | parameters_ws['B3'].alignment = b_r_alignment |
|
887 | parameters_ws['B3'] = _('Name') + ':' |
|
888 | parameters_ws['C3'].border = b_border |
|
889 | parameters_ws['C3'].alignment = b_c_alignment |
|
890 | parameters_ws['C3'] = name |
|
891 | ||
892 | parameters_ws['D3'].alignment = b_r_alignment |
|
893 | parameters_ws['D3'] = _('Period Type') + ':' |
|
894 | parameters_ws['E3'].border = b_border |
|
895 | parameters_ws['E3'].alignment = b_c_alignment |
|
896 | parameters_ws['E3'] = period_type |
|
897 | ||
898 | parameters_ws['B4'].alignment = b_r_alignment |
|
899 | parameters_ws['B4'] = _('Reporting Start Datetime') + ':' |
|
900 | parameters_ws['C4'].border = b_border |
|
901 | parameters_ws['C4'].alignment = b_c_alignment |
|
902 | parameters_ws['C4'] = reporting_start_datetime_local |
|
903 | ||
904 | parameters_ws['D4'].alignment = b_r_alignment |
|
905 | parameters_ws['D4'] = _('Reporting End Datetime') + ':' |
|
906 | parameters_ws['E4'].border = b_border |
|
907 | parameters_ws['E4'].alignment = b_c_alignment |
|
908 | parameters_ws['E4'] = reporting_end_datetime_local |
|
909 | ||
910 | parameters_ws_current_row_number = 6 |
|
911 | ||
912 | parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font |
|
913 | parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' ' + _('Parameters') |
|
914 | ||
915 | parameters_ws_current_row_number += 1 |
|
916 | ||
917 | parameters_table_start_row_number = parameters_ws_current_row_number |
|
918 | ||
919 | parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80 |
|
920 | ||
921 | parameters_ws_current_row_number += 1 |
|
922 | ||
923 | table_current_col_number = 2 |
|
924 | ||
925 | for i in range(0, parameters_names_len): |
|
926 | ||
927 | if len(parameters_data['timestamps'][i]) == 0: |
|
928 | continue |
|
929 | ||
930 | col = format_cell.get_column_letter(table_current_col_number) |
|
931 | ||
932 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
|
933 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
|
934 | ||
935 | col = format_cell.get_column_letter(table_current_col_number + 1) |
|
936 | ||
937 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
|
938 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
|
939 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].font = name_font |
|
940 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].alignment = c_c_alignment |
|
941 | parameters_ws[col + str(parameters_ws_current_row_number - 1)] = parameters_data['names'][i] |
|
942 | ||
943 | table_current_row_number = parameters_ws_current_row_number |
|
944 | ||
945 | for j, value in enumerate(list(parameters_data['timestamps'][i])): |
|
946 | col = format_cell.get_column_letter(table_current_col_number) |
|
947 | ||
948 | parameters_ws[col + str(table_current_row_number)].border = f_border |
|
949 | parameters_ws[col + str(table_current_row_number)].font = title_font |
|
950 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
|
951 | parameters_ws[col + str(table_current_row_number)] = value |
|
952 | ||
953 | col = format_cell.get_column_letter(table_current_col_number + 1) |
|
954 | ||
955 | parameters_ws[col + str(table_current_row_number)].border = f_border |
|
956 | parameters_ws[col + str(table_current_row_number)].font = title_font |
|
957 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
|
958 | parameters_ws[col + str(table_current_row_number)] = round2(parameters_data['values'][i][j], 2) |
|
959 | ||
960 | table_current_row_number += 1 |
|
961 | ||
962 | table_current_col_number = table_current_col_number + 3 |
|
963 | ||
964 | ################################################################################################################ |
|
965 | # parameters chart and parameters table |
|
966 | ################################################################################################################ |
|
967 | ||
968 | ws['B' + str(current_sheet_parameters_row_number)].font = title_font |
|
969 | ws['B' + str(current_sheet_parameters_row_number)] = name + ' ' + _('Parameters') |
|
970 | ||
971 | current_sheet_parameters_row_number += 1 |
|
972 | ||
973 | chart_start_row_number = current_sheet_parameters_row_number |
|
974 | ||
975 | col_index = 0 |
|
976 | ||
977 | for i in range(0, parameters_names_len): |
|
978 | ||
979 | if len(parameters_data['timestamps'][i]) == 0: |
|
980 | continue |
|
981 | ||
982 | line = LineChart() |
|
983 | data_col = 3 + col_index * 3 |
|
984 | labels_col = 2 + col_index * 3 |
|
985 | col_index += 1 |
|
986 | line.title = _('Parameters') + ' - ' + \ |
|
987 | parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value |
|
988 | labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1, |
|
989 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
|
990 | line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number, |
|
991 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
|
992 | line.add_data(line_data, titles_from_data=True) |
|
993 | line.set_categories(labels) |
|
994 | line_data = line.series[0] |
|
995 | line_data.marker.symbol = "auto" |
|
996 | line_data.smooth = True |
|
997 | line.x_axis.crosses = 'min' |
|
998 | line.height = 8.25 |
|
999 | line.width = 24 |
|
1000 | chart_col = 'B' |
|
1001 | chart_cell = chart_col + str(chart_start_row_number) |
|
1002 | chart_start_row_number += 6 |
|
1003 | ws.add_chart(line, chart_cell) |
|
1004 | ||
1005 | current_sheet_parameters_row_number = chart_start_row_number |
|
1006 | ||
1007 | current_sheet_parameters_row_number += 1 |
|
1008 | #################################################################################################################### |
|
1009 | filename = str(uuid.uuid4()) + '.xlsx' |
|
1010 | wb.save(filename) |
|
1011 | ||
1012 | return filename |
|
1013 | ||
1014 | ||
1015 | def sum_list(lists): |