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 | print(report) |
||
35 | |||
36 | #################################################################################################################### |
||
37 | # Step 2: Generate excel file from the report data |
||
38 | #################################################################################################################### |
||
39 | filename = generate_excel(report, |
||
40 | name, |
||
41 | base_period_start_datetime_local, |
||
42 | base_period_end_datetime_local, |
||
43 | reporting_start_datetime_local, |
||
44 | reporting_end_datetime_local, |
||
45 | period_type, |
||
46 | language) |
||
47 | #################################################################################################################### |
||
48 | # Step 3: Encode the excel file to Base64 |
||
49 | #################################################################################################################### |
||
50 | binary_file_data = b'' |
||
51 | try: |
||
52 | with open(filename, 'rb') as binary_file: |
||
53 | binary_file_data = binary_file.read() |
||
54 | except IOError as ex: |
||
55 | print(str(ex)) |
||
56 | |||
57 | # Base64 encode the bytes |
||
58 | base64_encoded_data = base64.b64encode(binary_file_data) |
||
59 | # get the Base64 encoded data using human-readable characters. |
||
60 | base64_message = base64_encoded_data.decode('utf-8') |
||
61 | # delete the file from server |
||
62 | try: |
||
63 | os.remove(filename) |
||
64 | except NotImplementedError as ex: |
||
65 | print(str(ex)) |
||
66 | return base64_message |
||
67 | |||
68 | |||
69 | View Code Duplication | def generate_excel(report, |
|
0 ignored issues
–
show
|
|||
70 | name, |
||
71 | base_period_start_datetime_local, |
||
72 | base_period_end_datetime_local, |
||
73 | reporting_start_datetime_local, |
||
74 | reporting_end_datetime_local, |
||
75 | period_type, |
||
76 | language): |
||
77 | trans = get_translation(language) |
||
78 | trans.install() |
||
79 | _ = trans.gettext |
||
80 | wb = Workbook() |
||
81 | |||
82 | # todo |
||
83 | ws = wb.active |
||
84 | ws.title = "SpaceLoad" |
||
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 | "timestamps" not in report['reporting_period'].keys() or len(report['reporting_period']['timestamps']) == 0: |
||
177 | filename = str(uuid.uuid4()) + '.xlsx' |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
178 | wb.save(filename) |
||
179 | |||
180 | return filename |
||
181 | |||
182 | #################################################################################################################### |
||
183 | current_row_number = 7 |
||
184 | if "names" not in report['reporting_period'].keys() or len(report['reporting_period']['names']) == 0: |
||
185 | pass |
||
186 | else: |
||
187 | reporting_period_data = report['reporting_period'] |
||
188 | category = reporting_period_data['names'] |
||
189 | ca_len = len(category) |
||
190 | |||
191 | ws['B' + str(current_row_number)].font = title_font |
||
192 | ws['B' + str(current_row_number)] = name + _('Reporting Period Average Load') |
||
193 | |||
194 | current_row_number += 1 |
||
195 | |||
196 | ws.row_dimensions[current_row_number].height = 60 |
||
197 | ws['B' + str(current_row_number)].fill = table_fill |
||
198 | ws['B' + str(current_row_number)].border = f_border |
||
199 | for i in range(0, ca_len): |
||
200 | col = chr(ord('C') + i) |
||
201 | ws[col + str(current_row_number)].fill = table_fill |
||
202 | ws[col + str(current_row_number)].font = name_font |
||
203 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
204 | ws[col + str(current_row_number)].border = f_border |
||
205 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
||
206 | " (" + reporting_period_data['units'][i] + "/H)" |
||
207 | |||
208 | current_row_number += 1 |
||
209 | |||
210 | ws['B' + str(current_row_number)].font = title_font |
||
211 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
212 | ws['B' + str(current_row_number)].border = f_border |
||
213 | ws['B' + str(current_row_number)] = _('Average Load') |
||
214 | |||
215 | for i in range(0, ca_len): |
||
216 | col = chr(ord('C') + i) |
||
217 | ws[col + str(current_row_number)].font = name_font |
||
218 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
219 | ws[col + str(current_row_number)].border = f_border |
||
220 | ws[col + str(current_row_number)] = round2(reporting_period_data['averages'][i], 2) \ |
||
221 | if reporting_period_data['averages'][i] is not None else 'N/A' |
||
222 | |||
223 | current_row_number += 1 |
||
224 | |||
225 | ws['B' + str(current_row_number)].font = title_font |
||
226 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
227 | ws['B' + str(current_row_number)].border = f_border |
||
228 | ws['B' + str(current_row_number)] = _('Per Unit Area') |
||
229 | |||
230 | for i in range(0, ca_len): |
||
231 | col = chr(ord('C') + i) |
||
232 | ws[col + str(current_row_number)].font = name_font |
||
233 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
234 | ws[col + str(current_row_number)].border = f_border |
||
235 | ws[col + str(current_row_number)] = round2(reporting_period_data['averages_per_unit_area'][i], 2) \ |
||
236 | if reporting_period_data['averages_per_unit_area'][i] is not None else 'N/A' |
||
237 | |||
238 | current_row_number += 1 |
||
239 | |||
240 | ws['B' + str(current_row_number)].font = title_font |
||
241 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
242 | ws['B' + str(current_row_number)].border = f_border |
||
243 | ws['B' + str(current_row_number)] = _('Increment Rate') |
||
244 | |||
245 | for i in range(0, ca_len): |
||
246 | col = chr(ord('C') + i) |
||
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)] = str( |
||
251 | round2(reporting_period_data['averages_increment_rate'][i] * 100, 2)) + "%" \ |
||
252 | if reporting_period_data['averages_increment_rate'][i] is not None else "-" |
||
253 | |||
254 | current_row_number += 2 |
||
255 | |||
256 | ws['B' + str(current_row_number)].font = title_font |
||
257 | ws['B' + str(current_row_number)] = name + _('Reporting Period Maximum Load') |
||
258 | |||
259 | current_row_number += 1 |
||
260 | |||
261 | ws.row_dimensions[current_row_number].height = 60 |
||
262 | ws['B' + str(current_row_number)].fill = table_fill |
||
263 | ws['B' + str(current_row_number)].border = f_border |
||
264 | for i in range(0, ca_len): |
||
265 | col = chr(ord('C') + i) |
||
266 | ws[col + str(current_row_number)].fill = table_fill |
||
267 | ws[col + str(current_row_number)].font = name_font |
||
268 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
269 | ws[col + str(current_row_number)].border = f_border |
||
270 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
||
271 | " (" + reporting_period_data['units'][i] + "/H)" |
||
272 | |||
273 | current_row_number += 1 |
||
274 | |||
275 | ws['B' + str(current_row_number)].font = title_font |
||
276 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
277 | ws['B' + str(current_row_number)].border = f_border |
||
278 | ws['B' + str(current_row_number)] = _('Maximum Load') |
||
279 | |||
280 | for i in range(0, ca_len): |
||
281 | col = chr(ord('C') + i) |
||
282 | ws[col + str(current_row_number)].font = name_font |
||
283 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
284 | ws[col + str(current_row_number)].border = f_border |
||
285 | ws[col + str(current_row_number)] = round2(reporting_period_data['maximums'][i], 2) \ |
||
286 | if reporting_period_data['maximums'][i] is not None else 'N/A' |
||
287 | |||
288 | current_row_number += 1 |
||
289 | |||
290 | ws['B' + str(current_row_number)].font = title_font |
||
291 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
292 | ws['B' + str(current_row_number)].border = f_border |
||
293 | ws['B' + str(current_row_number)] = _('Per Unit Area') |
||
294 | |||
295 | for i in range(0, ca_len): |
||
296 | col = chr(ord('C') + i) |
||
297 | ws[col + str(current_row_number)].font = name_font |
||
298 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
299 | ws[col + str(current_row_number)].border = f_border |
||
300 | ws[col + str(current_row_number)] = round2(reporting_period_data['maximums_per_unit_area'][i], 2) \ |
||
301 | if reporting_period_data['maximums_per_unit_area'][i] is not None else 'N/A' |
||
302 | |||
303 | current_row_number += 1 |
||
304 | |||
305 | ws['B' + str(current_row_number)].font = title_font |
||
306 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
307 | ws['B' + str(current_row_number)].border = f_border |
||
308 | ws['B' + str(current_row_number)] = _('Increment Rate') |
||
309 | |||
310 | for i in range(0, ca_len): |
||
311 | col = chr(ord('C') + i) |
||
312 | ws[col + str(current_row_number)].font = name_font |
||
313 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
314 | ws[col + str(current_row_number)].border = f_border |
||
315 | ws[col + str(current_row_number)] = str( |
||
316 | round2(reporting_period_data['maximums_increment_rate'][i] * 100, 2)) + "%" \ |
||
317 | if reporting_period_data['maximums_increment_rate'][i] is not None else "-" |
||
318 | |||
319 | current_row_number += 2 |
||
320 | |||
321 | ws['B' + str(current_row_number)].font = title_font |
||
322 | ws['B' + str(current_row_number)] = name + _('Reporting Period Load Factor') |
||
323 | |||
324 | current_row_number += 1 |
||
325 | |||
326 | ws.row_dimensions[current_row_number].height = 60 |
||
327 | ws['B' + str(current_row_number)].fill = table_fill |
||
328 | ws['B' + str(current_row_number)].border = f_border |
||
329 | for i in range(0, ca_len): |
||
330 | col = chr(ord('C') + i) |
||
331 | ws[col + str(current_row_number)].fill = table_fill |
||
332 | ws[col + str(current_row_number)].font = name_font |
||
333 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
334 | ws[col + str(current_row_number)].border = f_border |
||
335 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] |
||
336 | |||
337 | current_row_number += 1 |
||
338 | |||
339 | ws['B' + str(current_row_number)].font = title_font |
||
340 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
341 | ws['B' + str(current_row_number)].border = f_border |
||
342 | ws['B' + str(current_row_number)] = _('Load Factor') |
||
343 | |||
344 | for i in range(0, ca_len): |
||
345 | col = chr(ord('C') + i) |
||
346 | ws[col + str(current_row_number)].font = name_font |
||
347 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
348 | ws[col + str(current_row_number)].border = f_border |
||
349 | ws[col + str(current_row_number)] = round2(reporting_period_data['factors'][i], 2) \ |
||
350 | if reporting_period_data['factors'][i] is not None else '-' |
||
351 | |||
352 | current_row_number += 1 |
||
353 | |||
354 | ws['B' + str(current_row_number)].font = title_font |
||
355 | ws['B' + str(current_row_number)].alignment = c_c_alignment |
||
356 | ws['B' + str(current_row_number)].border = f_border |
||
357 | ws['B' + str(current_row_number)] = _('Increment Rate') |
||
358 | |||
359 | for i in range(0, ca_len): |
||
360 | col = chr(ord('C') + i) |
||
361 | ws[col + str(current_row_number)].font = name_font |
||
362 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
363 | ws[col + str(current_row_number)].border = f_border |
||
364 | ws[col + str(current_row_number)] = str( |
||
365 | round2(reporting_period_data['factors_increment_rate'][i] * 100, 2)) + "%" \ |
||
366 | if reporting_period_data['factors_increment_rate'][i] is not None else "-" |
||
367 | |||
368 | current_row_number += 2 |
||
369 | |||
370 | has_sub_averages_data_flag = True |
||
371 | has_sub_maximums_data_flag = True |
||
372 | |||
373 | if "sub_averages" not in report['reporting_period'].keys() or len(report['reporting_period']['sub_averages']) == 0: |
||
374 | has_sub_averages_data_flag = False |
||
375 | |||
376 | if "sub_maximums" not in report['reporting_period'].keys() or len(report['reporting_period']['sub_maximums']) == 0: |
||
377 | has_sub_maximums_data_flag = False |
||
378 | |||
379 | current_chart_row_number = current_row_number |
||
380 | |||
381 | if has_sub_averages_data_flag or has_sub_maximums_data_flag: |
||
382 | if not is_base_period_timestamp_exists_flag: |
||
383 | reporting_period_data = report['reporting_period'] |
||
384 | category = reporting_period_data['names'] |
||
385 | ca_len = len(category) |
||
386 | times = reporting_period_data['timestamps'] |
||
387 | time = times[0] |
||
388 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
||
389 | ws['B' + str(current_row_number)].font = title_font |
||
390 | ws['B' + str(current_row_number)] = name + _('Detailed Data') |
||
391 | |||
392 | current_row_number += 1 |
||
393 | chart_start_number = current_row_number |
||
394 | # 1: Stand for blank line 2: Stand for title |
||
395 | current_row_number += real_timestamps_len * 6 + 1 + 2 |
||
396 | if has_sub_averages_data_flag: |
||
397 | current_row_number = (current_row_number + ca_len * 6) |
||
398 | |||
399 | if has_sub_maximums_data_flag: |
||
400 | current_row_number = (current_row_number + ca_len * 6) |
||
401 | |||
402 | table_start_number = current_row_number |
||
403 | |||
404 | ws.row_dimensions[current_row_number].height = 60 |
||
405 | current_col_number = 2 |
||
406 | col = format_cell.get_column_letter(current_col_number) |
||
407 | ws[col + str(current_row_number)].fill = table_fill |
||
408 | ws[col + str(current_row_number)].font = title_font |
||
409 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
410 | ws[col + str(current_row_number)].border = f_border |
||
411 | ws[col + str(current_row_number)] = _('Datetime') |
||
412 | |||
413 | current_col_number = 3 |
||
414 | col = format_cell.get_column_letter(current_col_number) |
||
415 | |||
416 | for i in range(0, ca_len): |
||
417 | if has_sub_averages_data_flag: |
||
418 | ws[col + str(current_row_number)].fill = table_fill |
||
419 | ws[col + str(current_row_number)].font = title_font |
||
420 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
421 | ws[col + str(current_row_number)].border = f_border |
||
422 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
||
423 | " " + _('Average Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
424 | |||
425 | current_col_number += 1 |
||
426 | col = format_cell.get_column_letter(current_col_number) |
||
427 | |||
428 | if has_sub_maximums_data_flag: |
||
429 | ws[col + str(current_row_number)].fill = table_fill |
||
430 | ws[col + str(current_row_number)].font = title_font |
||
431 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
432 | ws[col + str(current_row_number)].border = f_border |
||
433 | ws[col + str(current_row_number)] = reporting_period_data['names'][i] + \ |
||
434 | " " + _('Maximum Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
435 | |||
436 | current_col_number += 1 |
||
437 | col = format_cell.get_column_letter(current_col_number) |
||
438 | |||
439 | current_row_number += 1 |
||
440 | |||
441 | for i in range(0, len(time)): |
||
442 | current_col_number = 2 |
||
443 | col = format_cell.get_column_letter(current_col_number) |
||
444 | ws[col + str(current_row_number)].font = title_font |
||
445 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
446 | ws[col + str(current_row_number)].border = f_border |
||
447 | ws[col + str(current_row_number)] = time[i] |
||
448 | |||
449 | current_col_number = 3 |
||
450 | col = format_cell.get_column_letter(current_col_number) |
||
451 | for j in range(0, ca_len): |
||
452 | |||
453 | if has_sub_averages_data_flag: |
||
454 | ws[col + str(current_row_number)].font = title_font |
||
455 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
456 | ws[col + str(current_row_number)].border = f_border |
||
457 | ws[col + str(current_row_number)] = round2(reporting_period_data['sub_averages'][j][i], 2) \ |
||
458 | if reporting_period_data['sub_averages'][j][i] is not None else None |
||
459 | current_col_number += 1 |
||
460 | col = format_cell.get_column_letter(current_col_number) |
||
461 | |||
462 | if has_sub_maximums_data_flag: |
||
463 | ws[col + str(current_row_number)].font = title_font |
||
464 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
465 | ws[col + str(current_row_number)].border = f_border |
||
466 | ws[col + str(current_row_number)] = round2(reporting_period_data['sub_maximums'][j][i], 2) \ |
||
467 | if reporting_period_data['sub_maximums'][j][i] is not None else None |
||
468 | current_col_number += 1 |
||
469 | col = format_cell.get_column_letter(current_col_number) |
||
470 | |||
471 | current_row_number += 1 |
||
472 | |||
473 | table_end_number = current_row_number - 1 |
||
474 | |||
475 | current_chart_col_number = 3 |
||
476 | current_chart_row_number = chart_start_number |
||
477 | |||
478 | for i in range(0, ca_len): |
||
479 | labels = Reference(ws, min_col=2, min_row=table_start_number + 1, max_row=table_end_number) |
||
480 | |||
481 | if has_sub_averages_data_flag: |
||
482 | line = LineChart() |
||
483 | line.title = _('Reporting Period Average Load') + ' - ' \ |
||
484 | + reporting_period_data['names'][i] + \ |
||
485 | " " + _('Average Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
486 | datas = Reference(ws, min_col=current_chart_col_number, min_row=table_start_number, |
||
487 | max_row=table_end_number) |
||
488 | line.add_data(datas, titles_from_data=True) |
||
489 | line.set_categories(labels) |
||
490 | line_data = line.series[0] |
||
491 | line_data.marker.symbol = "auto" |
||
492 | line_data.smooth = True |
||
493 | line.x_axis.crosses = 'min' |
||
494 | line.height = 8.25 |
||
495 | line.width = 24 |
||
496 | ws.add_chart(line, "B" + str(current_chart_row_number)) |
||
497 | current_chart_row_number += 6 |
||
498 | current_chart_col_number += 1 |
||
499 | |||
500 | if has_sub_maximums_data_flag: |
||
501 | line = LineChart() |
||
502 | line.title = _('Reporting Period Maximum Load') + ' - ' \ |
||
503 | + reporting_period_data['names'][i] + \ |
||
504 | " " + _('Maximum Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
505 | datas = Reference(ws, min_col=current_chart_col_number, min_row=table_start_number, |
||
506 | max_row=table_end_number) |
||
507 | line.add_data(datas, titles_from_data=True) |
||
508 | line.set_categories(labels) |
||
509 | line_data = line.series[0] |
||
510 | line_data.marker.symbol = "auto" |
||
511 | line_data.smooth = True |
||
512 | line.x_axis.crosses = 'min' |
||
513 | line.height = 8.25 |
||
514 | line.width = 24 |
||
515 | ws.add_chart(line, "B" + str(current_chart_row_number)) |
||
516 | current_chart_row_number += 6 |
||
517 | current_chart_col_number += 1 |
||
518 | else: |
||
519 | base_period_data = report['base_period'] |
||
520 | reporting_period_data = report['reporting_period'] |
||
521 | base_period_timestamps = base_period_data['timestamps'] |
||
522 | reporting_period_timestamps = reporting_period_data['timestamps'] |
||
523 | # Tip: |
||
524 | # base_period_data['names'] == reporting_period_data['names'] |
||
525 | # base_period_data['units'] == reporting_period_data['units'] |
||
526 | base_period_data_ca_len = len(base_period_data['names']) |
||
527 | reporting_period_data_ca_len = len(reporting_period_data['names']) |
||
528 | real_timestamps_len = timestamps_data_not_equal_0(report['parameters']['timestamps']) |
||
529 | ws['B' + str(current_row_number)].font = title_font |
||
530 | ws['B' + str(current_row_number)] = name + ' ' + _('Detailed Data') |
||
531 | |||
532 | current_row_number += 1 |
||
533 | chart_start_number = current_row_number |
||
534 | |||
535 | # 1: Stand for blank line 2: Stand for title |
||
536 | current_row_number += real_timestamps_len * 6 + 1 + 2 |
||
537 | |||
538 | if has_sub_averages_data_flag: |
||
539 | current_row_number = (current_row_number + reporting_period_data_ca_len * 6) |
||
540 | |||
541 | if has_sub_maximums_data_flag: |
||
542 | current_row_number = (current_row_number + reporting_period_data_ca_len * 6) |
||
543 | |||
544 | table_start_row_number = current_row_number |
||
545 | |||
546 | has_data = False |
||
547 | |||
548 | if len(base_period_timestamps[0]) or len(reporting_period_timestamps[0]) > 0: |
||
549 | has_data = True |
||
550 | |||
551 | if has_data: |
||
552 | ws.row_dimensions[current_row_number].height = 60 |
||
553 | current_col_number = 2 |
||
554 | col = format_cell.get_column_letter(current_col_number) |
||
555 | ws[col + str(current_row_number)].fill = table_fill |
||
556 | ws[col + str(current_row_number)].font = title_font |
||
557 | ws[col + str(current_row_number)].border = f_border |
||
558 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
559 | ws[col + str(current_row_number)] = _('Base Period') + " - " + _('Datetime') |
||
560 | |||
561 | for i in range(0, base_period_data_ca_len): |
||
562 | if has_sub_averages_data_flag: |
||
563 | current_col_number += 1 |
||
564 | col = format_cell.get_column_letter(current_col_number) |
||
565 | |||
566 | ws[col + str(current_row_number)].fill = table_fill |
||
567 | ws[col + str(current_row_number)].font = title_font |
||
568 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
569 | ws[col + str(current_row_number)] = _('Base Period') + " - " \ |
||
570 | + base_period_data['names'][i] + \ |
||
571 | " " + _('Average Load') + "(" + base_period_data['units'][i] + "/H)" |
||
572 | ws[col + str(current_row_number)].border = f_border |
||
573 | |||
574 | if has_sub_maximums_data_flag: |
||
575 | current_col_number += 1 |
||
576 | col = format_cell.get_column_letter(current_col_number) |
||
577 | |||
578 | ws[col + str(current_row_number)].fill = table_fill |
||
579 | ws[col + str(current_row_number)].font = title_font |
||
580 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
581 | ws[col + str(current_row_number)] = _('Base Period') + " - " \ |
||
582 | + base_period_data['names'][i] + \ |
||
583 | " " + _('Maximum Load') + "(" + base_period_data['units'][i] + "/H)" |
||
584 | ws[col + str(current_row_number)].border = f_border |
||
585 | |||
586 | current_col_number += 1 |
||
587 | col = format_cell.get_column_letter(current_col_number) |
||
588 | |||
589 | ws[col + str(current_row_number)].fill = table_fill |
||
590 | ws[col + str(current_row_number)].font = title_font |
||
591 | ws[col + str(current_row_number)].border = f_border |
||
592 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
593 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " + _('Datetime') |
||
594 | |||
595 | for i in range(0, reporting_period_data_ca_len): |
||
596 | if has_sub_averages_data_flag: |
||
597 | current_col_number += 1 |
||
598 | col = format_cell.get_column_letter(current_col_number) |
||
599 | ws[col + str(current_row_number)].fill = table_fill |
||
600 | ws[col + str(current_row_number)].font = title_font |
||
601 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
602 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " \ |
||
603 | + reporting_period_data['names'][i] + \ |
||
604 | " " + _('Average Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
605 | ws[col + str(current_row_number)].border = f_border |
||
606 | |||
607 | if has_sub_maximums_data_flag: |
||
608 | current_col_number += 1 |
||
609 | col = format_cell.get_column_letter(current_col_number) |
||
610 | ws[col + str(current_row_number)].fill = table_fill |
||
611 | ws[col + str(current_row_number)].font = title_font |
||
612 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
613 | ws[col + str(current_row_number)] = _('Reporting Period') + " - " \ |
||
614 | + reporting_period_data['names'][i] + \ |
||
615 | " " + _('Maximum Load') + "(" + \ |
||
616 | reporting_period_data['units'][i] + "/H)" |
||
617 | ws[col + str(current_row_number)].border = f_border |
||
618 | |||
619 | current_row_number += 1 |
||
620 | |||
621 | max_timestamps_len = len(base_period_timestamps[0]) \ |
||
622 | if len(base_period_timestamps[0]) >= len(reporting_period_timestamps[0]) \ |
||
623 | else len(reporting_period_timestamps[0]) |
||
624 | |||
625 | for i in range(0, max_timestamps_len): |
||
626 | current_col_number = 2 |
||
627 | col = format_cell.get_column_letter(current_col_number) |
||
628 | ws[col + str(current_row_number)].font = title_font |
||
629 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
630 | ws[col + str(current_row_number)] = base_period_timestamps[0][i] \ |
||
631 | if i < len(base_period_timestamps[0]) else None |
||
632 | ws[col + str(current_row_number)].border = f_border |
||
633 | |||
634 | for j in range(0, base_period_data_ca_len): |
||
635 | if has_sub_averages_data_flag: |
||
636 | current_col_number += 1 |
||
637 | col = format_cell.get_column_letter(current_col_number) |
||
638 | |||
639 | ws[col + str(current_row_number)].font = title_font |
||
640 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
641 | ws[col + str(current_row_number)] = round2(base_period_data['sub_averages'][j][i], 2) \ |
||
642 | if i < len(base_period_data['sub_averages'][j]) \ |
||
643 | and base_period_data['sub_averages'][j][i] is not None else None |
||
644 | ws[col + str(current_row_number)].border = f_border |
||
645 | |||
646 | if has_sub_maximums_data_flag: |
||
647 | current_col_number += 1 |
||
648 | col = format_cell.get_column_letter(current_col_number) |
||
649 | |||
650 | ws[col + str(current_row_number)].font = title_font |
||
651 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
652 | ws[col + str(current_row_number)] = round2(base_period_data['sub_maximums'][j][i], 2) \ |
||
653 | if i < len(base_period_data['sub_maximums'][j]) \ |
||
654 | and base_period_data['sub_averages'][j][i] is not None else None |
||
655 | ws[col + str(current_row_number)].border = f_border |
||
656 | |||
657 | current_col_number += 1 |
||
658 | col = format_cell.get_column_letter(current_col_number) |
||
659 | |||
660 | ws[col + str(current_row_number)].font = title_font |
||
661 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
662 | ws[col + str(current_row_number)] = reporting_period_timestamps[0][i] \ |
||
663 | if i < len(reporting_period_timestamps[0]) else None |
||
664 | ws[col + str(current_row_number)].border = f_border |
||
665 | |||
666 | for j in range(0, reporting_period_data_ca_len): |
||
667 | if has_sub_averages_data_flag: |
||
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)] = round2(reporting_period_data['sub_averages'][j][i], 2) \ |
||
674 | if i < len(reporting_period_data['sub_averages'][j]) \ |
||
675 | and reporting_period_data['sub_averages'][j][i] is not None else None |
||
676 | ws[col + str(current_row_number)].border = f_border |
||
677 | |||
678 | if has_sub_maximums_data_flag: |
||
679 | current_col_number += 1 |
||
680 | col = format_cell.get_column_letter(current_col_number) |
||
681 | |||
682 | ws[col + str(current_row_number)].font = title_font |
||
683 | ws[col + str(current_row_number)].alignment = c_c_alignment |
||
684 | ws[col + str(current_row_number)] = round2(reporting_period_data['sub_maximums'][j][i], 2) \ |
||
685 | if i < len(reporting_period_data['sub_maximums'][j]) \ |
||
686 | and reporting_period_data['sub_maximums'][j][i] is not None else None |
||
687 | ws[col + str(current_row_number)].border = f_border |
||
688 | |||
689 | current_row_number += 1 |
||
690 | |||
691 | current_chart_col_number = 3 |
||
692 | current_chart_row_number = chart_start_number |
||
693 | |||
694 | for i in range(0, reporting_period_data_ca_len): |
||
695 | labels = Reference(ws, min_col=2 + base_period_data_ca_len * 2 + 1, |
||
696 | min_row=table_start_row_number + 1, |
||
697 | max_row=table_start_row_number + len(reporting_period_timestamps[0])) |
||
698 | |||
699 | if has_sub_averages_data_flag: |
||
700 | # line |
||
701 | line = LineChart() |
||
702 | line.title = _('Base Period Average Load') + ' / ' \ |
||
703 | + _('Reporting Period Average Load') + ' - ' \ |
||
704 | + reporting_period_data['names'][i] + \ |
||
705 | " " + _('Average Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
706 | base_line_data = Reference(ws, |
||
707 | min_col=current_chart_col_number, |
||
708 | min_row=table_start_row_number, |
||
709 | max_row=table_start_row_number |
||
710 | + len(reporting_period_timestamps[0])) |
||
711 | |||
712 | data_distance = base_period_data_ca_len |
||
713 | if has_sub_maximums_data_flag: |
||
714 | data_distance *= 2 |
||
715 | |||
716 | reporting_line_data = Reference(ws, |
||
717 | min_col=current_chart_col_number + data_distance + 1, |
||
718 | min_row=table_start_row_number, |
||
719 | max_row=table_start_row_number |
||
720 | + len(reporting_period_timestamps[0])) |
||
721 | line.add_data(base_line_data, titles_from_data=True) |
||
722 | line.add_data(reporting_line_data, titles_from_data=True) |
||
723 | line.set_categories(labels) |
||
724 | for j in range(len(line.series)): |
||
725 | line.series[j].marker.symbol = "auto" |
||
726 | line.series[j].smooth = True |
||
727 | line.x_axis.crosses = 'min' |
||
728 | line.height = 8.25 |
||
729 | line.width = 24 |
||
730 | chart_col = 'B' |
||
731 | chart_cell = chart_col + str(current_chart_row_number) |
||
732 | ws.add_chart(line, chart_cell) |
||
733 | current_chart_row_number += 6 |
||
734 | current_chart_col_number += 1 |
||
735 | |||
736 | if has_sub_maximums_data_flag: |
||
737 | # line |
||
738 | line = LineChart() |
||
739 | line.title = _('Base Period Maximum Load') + ' / ' \ |
||
740 | + _('Reporting Period Maximum Load') + ' - ' \ |
||
741 | + reporting_period_data['names'][i] + \ |
||
742 | " " + _('Maximum Load') + "(" + reporting_period_data['units'][i] + "/H)" |
||
743 | base_line_data = Reference(ws, |
||
744 | min_col=current_chart_col_number, |
||
745 | min_row=table_start_row_number, |
||
746 | max_row=table_start_row_number |
||
747 | + len(reporting_period_timestamps[0])) |
||
748 | |||
749 | data_distance = base_period_data_ca_len |
||
750 | if has_sub_averages_data_flag: |
||
751 | data_distance *= 2 |
||
752 | |||
753 | reporting_line_data = Reference(ws, |
||
754 | min_col=current_chart_col_number + data_distance + 1, |
||
755 | min_row=table_start_row_number, |
||
756 | max_row=table_start_row_number |
||
757 | + len(reporting_period_timestamps[0])) |
||
758 | line.add_data(base_line_data, titles_from_data=True) |
||
759 | line.add_data(reporting_line_data, titles_from_data=True) |
||
760 | line.set_categories(labels) |
||
761 | for j in range(len(line.series)): |
||
762 | line.series[j].marker.symbol = "auto" |
||
763 | line.series[j].smooth = True |
||
764 | line.x_axis.crosses = 'min' |
||
765 | line.height = 8.25 |
||
766 | line.width = 24 |
||
767 | chart_col = 'B' |
||
768 | chart_cell = chart_col + str(current_chart_row_number) |
||
769 | ws.add_chart(line, chart_cell) |
||
770 | current_chart_row_number += 6 |
||
771 | current_chart_col_number += 1 |
||
772 | |||
773 | current_row_number += 2 |
||
774 | |||
775 | #################################################################################################################### |
||
776 | current_sheet_parameters_row_number = current_chart_row_number + 1 |
||
777 | if 'parameters' not in report.keys() or \ |
||
778 | report['parameters'] is None or \ |
||
779 | 'names' not in report['parameters'].keys() or \ |
||
780 | report['parameters']['names'] is None or \ |
||
781 | len(report['parameters']['names']) == 0 or \ |
||
782 | 'timestamps' not in report['parameters'].keys() or \ |
||
783 | report['parameters']['timestamps'] is None or \ |
||
784 | len(report['parameters']['timestamps']) == 0 or \ |
||
785 | 'values' not in report['parameters'].keys() or \ |
||
786 | report['parameters']['values'] is None or \ |
||
787 | len(report['parameters']['values']) == 0 or \ |
||
788 | timestamps_data_all_equal_0(report['parameters']['timestamps']): |
||
789 | pass |
||
790 | else: |
||
791 | ################################################################################################################ |
||
792 | # new worksheet |
||
793 | ################################################################################################################ |
||
794 | |||
795 | parameters_data = report['parameters'] |
||
796 | parameters_names_len = len(parameters_data['names']) |
||
797 | |||
798 | file_name = "Space" + re.sub(r'[^A-Z]', '', ws.title.strip('S')) + "_" |
||
799 | parameters_ws = wb.create_sheet(file_name + _('Parameters')) |
||
800 | |||
801 | parameters_timestamps_data_max_len = \ |
||
802 | get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps'])) |
||
803 | |||
804 | # Row height |
||
805 | parameters_ws.row_dimensions[1].height = 102 |
||
806 | for i in range(2, 7 + 1): |
||
807 | parameters_ws.row_dimensions[i].height = 42 |
||
808 | |||
809 | for i in range(8, parameters_timestamps_data_max_len + 10): |
||
810 | parameters_ws.row_dimensions[i].height = 60 |
||
811 | |||
812 | # Col width |
||
813 | parameters_ws.column_dimensions['A'].width = 1.5 |
||
814 | |||
815 | parameters_ws.column_dimensions['B'].width = 25.0 |
||
816 | |||
817 | for i in range(3, 12 + parameters_names_len * 3): |
||
818 | parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0 |
||
819 | |||
820 | # Img |
||
821 | img = Image("excelexporters/myems.png") |
||
822 | parameters_ws.add_image(img, 'A1') |
||
823 | |||
824 | # Title |
||
825 | parameters_ws['B3'].alignment = b_r_alignment |
||
826 | parameters_ws['B3'] = _('Name') + ':' |
||
827 | parameters_ws['C3'].border = b_border |
||
828 | parameters_ws['C3'].alignment = b_c_alignment |
||
829 | parameters_ws['C3'] = name |
||
830 | |||
831 | parameters_ws['D3'].alignment = b_r_alignment |
||
832 | parameters_ws['D3'] = _('Period Type') + ':' |
||
833 | parameters_ws['E3'].border = b_border |
||
834 | parameters_ws['E3'].alignment = b_c_alignment |
||
835 | parameters_ws['E3'] = period_type |
||
836 | |||
837 | parameters_ws['B4'].alignment = b_r_alignment |
||
838 | parameters_ws['B4'] = _('Reporting Start Datetime') + ':' |
||
839 | parameters_ws['C4'].border = b_border |
||
840 | parameters_ws['C4'].alignment = b_c_alignment |
||
841 | parameters_ws['C4'] = reporting_start_datetime_local |
||
842 | |||
843 | parameters_ws['D4'].alignment = b_r_alignment |
||
844 | parameters_ws['D4'] = _('Reporting End Datetime') + ':' |
||
845 | parameters_ws['E4'].border = b_border |
||
846 | parameters_ws['E4'].alignment = b_c_alignment |
||
847 | parameters_ws['E4'] = reporting_end_datetime_local |
||
848 | |||
849 | parameters_ws_current_row_number = 6 |
||
850 | |||
851 | parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font |
||
852 | parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' ' + _('Parameters') |
||
853 | |||
854 | parameters_ws_current_row_number += 1 |
||
855 | |||
856 | parameters_table_start_row_number = parameters_ws_current_row_number |
||
857 | |||
858 | parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80 |
||
859 | |||
860 | parameters_ws_current_row_number += 1 |
||
861 | |||
862 | table_current_col_number = 2 |
||
863 | |||
864 | for i in range(0, parameters_names_len): |
||
865 | |||
866 | if len(parameters_data['timestamps'][i]) == 0: |
||
867 | continue |
||
868 | |||
869 | col = format_cell.get_column_letter(table_current_col_number) |
||
870 | |||
871 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
||
872 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
||
873 | |||
874 | col = format_cell.get_column_letter(table_current_col_number + 1) |
||
875 | |||
876 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
||
877 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
||
878 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].font = name_font |
||
879 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].alignment = c_c_alignment |
||
880 | parameters_ws[col + str(parameters_ws_current_row_number - 1)] = parameters_data['names'][i] |
||
881 | |||
882 | table_current_row_number = parameters_ws_current_row_number |
||
883 | |||
884 | for j, value in enumerate(list(parameters_data['timestamps'][i])): |
||
885 | col = format_cell.get_column_letter(table_current_col_number) |
||
886 | |||
887 | parameters_ws[col + str(table_current_row_number)].border = f_border |
||
888 | parameters_ws[col + str(table_current_row_number)].font = title_font |
||
889 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
||
890 | parameters_ws[col + str(table_current_row_number)] = value |
||
891 | |||
892 | col = format_cell.get_column_letter(table_current_col_number + 1) |
||
893 | |||
894 | parameters_ws[col + str(table_current_row_number)].border = f_border |
||
895 | parameters_ws[col + str(table_current_row_number)].font = title_font |
||
896 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
||
897 | parameters_ws[col + str(table_current_row_number)] = round2(parameters_data['values'][i][j], 2) |
||
898 | |||
899 | table_current_row_number += 1 |
||
900 | |||
901 | table_current_col_number = table_current_col_number + 3 |
||
902 | |||
903 | ################################################################################################################ |
||
904 | # parameters chart and parameters table |
||
905 | ################################################################################################################ |
||
906 | |||
907 | ws['B' + str(current_sheet_parameters_row_number)].font = title_font |
||
908 | ws['B' + str(current_sheet_parameters_row_number)] = name + ' ' + _('Parameters') |
||
909 | |||
910 | current_sheet_parameters_row_number += 1 |
||
911 | |||
912 | chart_start_row_number = current_sheet_parameters_row_number |
||
913 | |||
914 | col_index = 0 |
||
915 | |||
916 | for i in range(0, parameters_names_len): |
||
917 | |||
918 | if len(parameters_data['timestamps'][i]) == 0: |
||
919 | continue |
||
920 | |||
921 | line = LineChart() |
||
922 | data_col = 3 + col_index * 3 |
||
923 | labels_col = 2 + col_index * 3 |
||
924 | col_index += 1 |
||
925 | line.title = _('Parameters') + ' - ' + \ |
||
926 | parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value |
||
927 | labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1, |
||
928 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
||
929 | line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number, |
||
930 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
||
931 | line.add_data(line_data, titles_from_data=True) |
||
932 | line.set_categories(labels) |
||
933 | line_data = line.series[0] |
||
934 | line_data.marker.symbol = "auto" |
||
935 | line_data.smooth = True |
||
936 | line.x_axis.crosses = 'min' |
||
937 | line.height = 8.25 |
||
938 | line.width = 24 |
||
939 | chart_col = 'B' |
||
940 | chart_cell = chart_col + str(chart_start_row_number) |
||
941 | chart_start_row_number += 6 |
||
942 | ws.add_chart(line, chart_cell) |
||
943 | |||
944 | current_sheet_parameters_row_number = chart_start_row_number |
||
945 | |||
946 | current_sheet_parameters_row_number += 1 |
||
947 | #################################################################################################################### |
||
948 | filename = str(uuid.uuid4()) + '.xlsx' |
||
949 | wb.save(filename) |
||
950 | |||
951 | return filename |
||
952 | |||
953 | |||
954 | def timestamps_data_all_equal_0(lists): |
||
955 | for i, value in enumerate(list(lists)): |
||
956 | if len(value) > 0: |
||
957 | return False |
||
958 | |||
959 | return True |
||
960 | |||
961 | |||
962 | def get_parameters_timestamps_lists_max_len(parameters_timestamps_lists): |
||
963 | max_len = 0 |
||
964 | for i, value in enumerate(list(parameters_timestamps_lists)): |
||
965 | if len(value) > max_len: |
||
966 | max_len = len(value) |
||
967 | |||
968 | return max_len |
||
969 | |||
970 | |||
971 | def timestamps_data_not_equal_0(lists): |
||
972 | number = 0 |
||
973 | for i, value in enumerate(list(lists)): |
||
974 | if len(value) > 0: |
||
975 | number += 1 |
||
976 | return number |
||
977 | |||
978 | |||
979 | View Code Duplication | def is_base_period_timestamp_exists(base_period_data): |
|
0 ignored issues
–
show
|
|||
980 | timestamps = base_period_data['timestamps'] |
||
981 | |||
982 | if len(timestamps) == 0: |
||
983 | return False |
||
984 | |||
985 | for timestamp in timestamps: |
||
986 | if len(timestamp) > 0: |
||
987 | return True |
||
988 | |||
989 | return False |
||
990 |