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