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