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