| Conditions | 46 |
| Total Lines | 473 |
| Code Lines | 345 |
| Lines | 473 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like excelexporters.metercarbon.generate_excel() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import base64 |
||
| 60 | View Code Duplication | def generate_excel(report, name, reporting_start_datetime_local, reporting_end_datetime_local, period_type): |
|
| 61 | wb = Workbook() |
||
| 62 | |||
| 63 | # todo |
||
| 64 | ws = wb.active |
||
| 65 | ws.title = "MeterCarbon" |
||
| 66 | # Row height |
||
| 67 | ws.row_dimensions[1].height = 102 |
||
| 68 | for i in range(2, 2000 + 1): |
||
| 69 | ws.row_dimensions[i].height = 42 |
||
| 70 | |||
| 71 | # Col width |
||
| 72 | ws.column_dimensions['A'].width = 1.5 |
||
| 73 | |||
| 74 | ws.column_dimensions['B'].width = 25.0 |
||
| 75 | |||
| 76 | for i in range(ord('C'), ord('L')): |
||
| 77 | ws.column_dimensions[chr(i)].width = 15.0 |
||
| 78 | |||
| 79 | # Font |
||
| 80 | name_font = Font(name='Arial', size=15, bold=True) |
||
| 81 | title_font = Font(name='Arial', size=15, bold=True) |
||
| 82 | |||
| 83 | table_fill = PatternFill(fill_type='solid', fgColor='1F497D') |
||
| 84 | f_border = Border(left=Side(border_style='medium', color='00000000'), |
||
| 85 | right=Side(border_style='medium', color='00000000'), |
||
| 86 | bottom=Side(border_style='medium', color='00000000'), |
||
| 87 | top=Side(border_style='medium', color='00000000') |
||
| 88 | ) |
||
| 89 | b_border = Border( |
||
| 90 | bottom=Side(border_style='medium', color='00000000'), |
||
| 91 | ) |
||
| 92 | |||
| 93 | b_c_alignment = Alignment(vertical='bottom', |
||
| 94 | horizontal='center', |
||
| 95 | text_rotation=0, |
||
| 96 | wrap_text=True, |
||
| 97 | shrink_to_fit=False, |
||
| 98 | indent=0) |
||
| 99 | c_c_alignment = Alignment(vertical='center', |
||
| 100 | horizontal='center', |
||
| 101 | text_rotation=0, |
||
| 102 | wrap_text=True, |
||
| 103 | shrink_to_fit=False, |
||
| 104 | indent=0) |
||
| 105 | b_r_alignment = Alignment(vertical='bottom', |
||
| 106 | horizontal='right', |
||
| 107 | text_rotation=0, |
||
| 108 | wrap_text=True, |
||
| 109 | shrink_to_fit=False, |
||
| 110 | indent=0) |
||
| 111 | |||
| 112 | # Img |
||
| 113 | img = Image("excelexporters/myems.png") |
||
| 114 | ws.add_image(img, 'A1') |
||
| 115 | |||
| 116 | # Title |
||
| 117 | ws['B3'].alignment = b_r_alignment |
||
| 118 | ws['B3'] = 'Name:' |
||
| 119 | ws['C3'].border = b_border |
||
| 120 | ws['C3'].alignment = b_c_alignment |
||
| 121 | ws['C3'] = name |
||
| 122 | |||
| 123 | ws['D3'].alignment = b_r_alignment |
||
| 124 | ws['D3'] = 'Period:' |
||
| 125 | ws['E3'].border = b_border |
||
| 126 | ws['E3'].alignment = b_c_alignment |
||
| 127 | ws['E3'] = period_type |
||
| 128 | |||
| 129 | ws['B4'].alignment = b_r_alignment |
||
| 130 | ws['B4'] = 'Reporting Start Datetime:' |
||
| 131 | ws['C4'].border = b_border |
||
| 132 | ws['C4'].alignment = b_c_alignment |
||
| 133 | ws['C4'] = reporting_start_datetime_local |
||
| 134 | |||
| 135 | ws['D4'].alignment = b_r_alignment |
||
| 136 | ws['D4'] = 'Reporting End Datetime:' |
||
| 137 | ws['E4'].border = b_border |
||
| 138 | ws['E4'].alignment = b_c_alignment |
||
| 139 | ws['E4'] = reporting_end_datetime_local |
||
| 140 | |||
| 141 | if "reporting_period" not in report.keys() or \ |
||
| 142 | "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0: |
||
| 143 | filename = str(uuid.uuid4()) + '.xlsx' |
||
| 144 | wb.save(filename) |
||
| 145 | |||
| 146 | return filename |
||
| 147 | |||
| 148 | #################################################################################################################### |
||
| 149 | |||
| 150 | has_carbon_data_flag = True |
||
| 151 | |||
| 152 | if "values" not in report['reporting_period'].keys() or len(report['reporting_period']['values']) == 0: |
||
| 153 | has_carbon_data_flag = False |
||
| 154 | |||
| 155 | if has_carbon_data_flag: |
||
| 156 | ws['B6'].font = title_font |
||
| 157 | ws['B6'] = name + 'Reporting Period Carbon Dioxide Emissions' |
||
| 158 | |||
| 159 | reporting_period_data = report['reporting_period'] |
||
| 160 | category = report['meter']['energy_category_name'] |
||
| 161 | ca_len = len(category) |
||
| 162 | |||
| 163 | ws.row_dimensions[7].height = 60 |
||
| 164 | ws['B7'].fill = table_fill |
||
| 165 | ws['B7'].border = f_border |
||
| 166 | |||
| 167 | ws['B8'].font = title_font |
||
| 168 | ws['B8'].alignment = c_c_alignment |
||
| 169 | ws['B8'] = 'Carbon Dioxide Emission' |
||
| 170 | ws['B8'].border = f_border |
||
| 171 | |||
| 172 | ws['B9'].font = title_font |
||
| 173 | ws['B9'].alignment = c_c_alignment |
||
| 174 | ws['B9'] = 'Increment Rate' |
||
| 175 | ws['B9'].border = f_border |
||
| 176 | |||
| 177 | col = 'B' |
||
| 178 | |||
| 179 | for i in range(0, ca_len): |
||
| 180 | col = chr(ord('C') + i) |
||
| 181 | |||
| 182 | ws[col + '7'].fill = table_fill |
||
| 183 | ws[col + '7'].font = name_font |
||
| 184 | ws[col + '7'].alignment = c_c_alignment |
||
| 185 | ws[col + '7'] = report['meter']['energy_category_name'] + " (" + report['meter']['unit_of_measure'] + ")" |
||
| 186 | ws[col + '7'].border = f_border |
||
| 187 | |||
| 188 | ws[col + '8'].font = name_font |
||
| 189 | ws[col + '8'].alignment = c_c_alignment |
||
| 190 | ws[col + '8'] = round(reporting_period_data['total_in_category'], 2) |
||
| 191 | ws[col + '8'].border = f_border |
||
| 192 | |||
| 193 | ws[col + '9'].font = name_font |
||
| 194 | ws[col + '9'].alignment = c_c_alignment |
||
| 195 | ws[col + '9'] = str(round(reporting_period_data['increment_rate'] * 100, 2)) + "%" \ |
||
| 196 | if reporting_period_data['increment_rate'] is not None else "-" |
||
| 197 | ws[col + '9'].border = f_border |
||
| 198 | |||
| 199 | # TCE TCO2E |
||
| 200 | end_col = col |
||
| 201 | # TCE |
||
| 202 | tce_col = chr(ord(end_col) + 1) |
||
| 203 | ws[tce_col + '7'].fill = table_fill |
||
| 204 | ws[tce_col + '7'].font = name_font |
||
| 205 | ws[tce_col + '7'].alignment = c_c_alignment |
||
| 206 | ws[tce_col + '7'] = 'Ton of Standard Coal (TCE)' |
||
| 207 | ws[tce_col + '7'].border = f_border |
||
| 208 | |||
| 209 | ws[tce_col + '8'].font = name_font |
||
| 210 | ws[tce_col + '8'].alignment = c_c_alignment |
||
| 211 | ws[tce_col + '8'] = round(reporting_period_data['total_in_kgce'] / 1000, 2) |
||
| 212 | ws[tce_col + '8'].border = f_border |
||
| 213 | |||
| 214 | ws[tce_col + '9'].font = name_font |
||
| 215 | ws[tce_col + '9'].alignment = c_c_alignment |
||
| 216 | ws[tce_col + '9'] = str(round(reporting_period_data['increment_rate'] * 100, 2)) + "%" \ |
||
| 217 | if reporting_period_data['increment_rate'] is not None else "-" |
||
| 218 | ws[tce_col + '9'].border = f_border |
||
| 219 | |||
| 220 | # TCO2E |
||
| 221 | tco2e_col = chr(ord(end_col) + 2) |
||
| 222 | ws[tco2e_col + '7'].fill = table_fill |
||
| 223 | ws[tco2e_col + '7'].font = name_font |
||
| 224 | ws[tco2e_col + '7'].alignment = c_c_alignment |
||
| 225 | ws[tco2e_col + '7'] = 'Ton of Carbon Dioxide Emissions (TCO2E)' |
||
| 226 | ws[tco2e_col + '7'].border = f_border |
||
| 227 | |||
| 228 | ws[tco2e_col + '8'].font = name_font |
||
| 229 | ws[tco2e_col + '8'].alignment = c_c_alignment |
||
| 230 | ws[tco2e_col + '8'] = round(reporting_period_data['total_in_kgco2e'] / 1000, 2) |
||
| 231 | ws[tco2e_col + '8'].border = f_border |
||
| 232 | |||
| 233 | ws[tco2e_col + '9'].font = name_font |
||
| 234 | ws[tco2e_col + '9'].alignment = c_c_alignment |
||
| 235 | ws[tco2e_col + '9'] = str(round(reporting_period_data['increment_rate'] * 100, 2)) + "%" \ |
||
| 236 | if reporting_period_data['increment_rate'] is not None else "-" |
||
| 237 | ws[tco2e_col + '9'].border = f_border |
||
| 238 | |||
| 239 | else: |
||
| 240 | for i in range(6, 9 + 1): |
||
| 241 | ws.rows_dimensions[i].height = 0.1 |
||
| 242 | |||
| 243 | #################################################################################################################### |
||
| 244 | |||
| 245 | has_carbon_detail_flag = True |
||
| 246 | reporting_period_data = report['reporting_period'] |
||
| 247 | category = report['meter']['energy_category_name'] |
||
| 248 | ca_len = len(category) |
||
| 249 | times = reporting_period_data['timestamps'] |
||
| 250 | parameters_names_len = len(report['parameters']['names']) |
||
| 251 | parameters_data = report['parameters'] |
||
| 252 | parameters_parameters_datas_len = 0 |
||
| 253 | for i in range(0, parameters_names_len): |
||
| 254 | if len(parameters_data['timestamps'][i]) == 0: |
||
| 255 | continue |
||
| 256 | parameters_parameters_datas_len += 1 |
||
| 257 | |||
| 258 | if "values" not in reporting_period_data.keys() or len(reporting_period_data['values']) == 0: |
||
| 259 | has_carbon_detail_flag = False |
||
| 260 | |||
| 261 | if has_carbon_detail_flag: |
||
| 262 | start_detail_data_row_number = 13 + (parameters_parameters_datas_len + ca_len) * 6 |
||
| 263 | |||
| 264 | ws['B11'].font = title_font |
||
| 265 | ws['B11'] = name + 'Detailed Data' |
||
| 266 | |||
| 267 | ws.row_dimensions[start_detail_data_row_number].height = 60 |
||
| 268 | ws['B' + str(start_detail_data_row_number)].fill = table_fill |
||
| 269 | ws['B' + str(start_detail_data_row_number)].font = title_font |
||
| 270 | ws['B' + str(start_detail_data_row_number)].border = f_border |
||
| 271 | ws['B' + str(start_detail_data_row_number)].alignment = c_c_alignment |
||
| 272 | ws['B' + str(start_detail_data_row_number)] = 'Datetime' |
||
| 273 | time = times |
||
| 274 | has_data = False |
||
| 275 | max_row = 0 |
||
| 276 | if len(time) > 0: |
||
| 277 | has_data = True |
||
| 278 | max_row = start_detail_data_row_number + len(time) |
||
| 279 | |||
| 280 | if has_data: |
||
| 281 | |||
| 282 | end_data_row_number = start_detail_data_row_number |
||
| 283 | |||
| 284 | for i in range(0, len(time)): |
||
| 285 | col = 'B' |
||
| 286 | end_data_row_number += 1 |
||
| 287 | row = str(end_data_row_number) |
||
| 288 | |||
| 289 | ws[col + row].font = title_font |
||
| 290 | ws[col + row].alignment = c_c_alignment |
||
| 291 | ws[col + row] = time[i] |
||
| 292 | ws[col + row].border = f_border |
||
| 293 | |||
| 294 | ws['B' + str(end_data_row_number + 1)].font = title_font |
||
| 295 | ws['B' + str(end_data_row_number + 1)].alignment = c_c_alignment |
||
| 296 | ws['B' + str(end_data_row_number + 1)] = 'Total' |
||
| 297 | ws['B' + str(end_data_row_number + 1)].border = f_border |
||
| 298 | |||
| 299 | for i in range(0, ca_len): |
||
| 300 | |||
| 301 | col = chr(ord('C') + i) |
||
| 302 | |||
| 303 | ws[col + str(start_detail_data_row_number)].fill = table_fill |
||
| 304 | ws[col + str(start_detail_data_row_number)].font = title_font |
||
| 305 | ws[col + str(start_detail_data_row_number)].alignment = c_c_alignment |
||
| 306 | ws[col + str(start_detail_data_row_number)] = \ |
||
| 307 | report['meter']['energy_category_name']+" (" + report['meter']['unit_of_measure'] + ")" |
||
| 308 | ws[col + str(start_detail_data_row_number)].border = f_border |
||
| 309 | |||
| 310 | time = times |
||
| 311 | time_len = len(time) |
||
| 312 | |||
| 313 | for j in range(0, time_len): |
||
| 314 | row = str(start_detail_data_row_number + 1 + j) |
||
| 315 | |||
| 316 | ws[col + row].font = title_font |
||
| 317 | ws[col + row].alignment = c_c_alignment |
||
| 318 | ws[col + row] = round(reporting_period_data['values'][j], 2) |
||
| 319 | ws[col + row].border = f_border |
||
| 320 | |||
| 321 | ws[col + str(end_data_row_number + 1)].font = title_font |
||
| 322 | ws[col + str(end_data_row_number + 1)].alignment = c_c_alignment |
||
| 323 | ws[col + str(end_data_row_number + 1)] = round(reporting_period_data['total_in_category'], 2) |
||
| 324 | ws[col + str(end_data_row_number + 1)].border = f_border |
||
| 325 | |||
| 326 | line = LineChart() |
||
| 327 | line.title = 'Reporting Period Carbon Dioxide Emissions - ' + report['meter']['energy_category_name'] + \ |
||
| 328 | " (" + report['meter']['unit_of_measure'] + ")" |
||
| 329 | line_data = Reference(ws, min_col=3, min_row=start_detail_data_row_number, max_row=max_row) |
||
| 330 | line.series.append(Series(line_data, title_from_data=True)) |
||
| 331 | labels = Reference(ws, min_col=2, min_row=start_detail_data_row_number + 1, max_row=max_row) |
||
| 332 | line.set_categories(labels) |
||
| 333 | line_data = line.series[0] |
||
| 334 | line_data.marker.symbol = "circle" |
||
| 335 | line_data.smooth = True |
||
| 336 | line.x_axis.crosses = 'min' |
||
| 337 | line.dLbls = DataLabelList() |
||
| 338 | line.dLbls.dLblPos = 't' |
||
| 339 | line.dLbls.showVal = True |
||
| 340 | line.height = 8.25 |
||
| 341 | line.width = 24 |
||
| 342 | ws.add_chart(line, "B12") |
||
| 343 | else: |
||
| 344 | for i in range(11, 43 + 1): |
||
| 345 | ws.row_dimensions[i].height = 0.0 |
||
| 346 | |||
| 347 | #################################################################################################################### |
||
| 348 | has_parameters_names_and_timestamps_and_values_data = True |
||
| 349 | # 12 is the starting line number of the last line chart in the report period |
||
| 350 | time_len = len(reporting_period_data['timestamps']) |
||
| 351 | current_sheet_parameters_row_number = 12 + ca_len * 6 |
||
| 352 | if 'parameters' not in report.keys() or \ |
||
| 353 | report['parameters'] is None or \ |
||
| 354 | 'names' not in report['parameters'].keys() or \ |
||
| 355 | report['parameters']['names'] is None or \ |
||
| 356 | len(report['parameters']['names']) == 0 or \ |
||
| 357 | 'timestamps' not in report['parameters'].keys() or \ |
||
| 358 | report['parameters']['timestamps'] is None or \ |
||
| 359 | len(report['parameters']['timestamps']) == 0 or \ |
||
| 360 | 'values' not in report['parameters'].keys() or \ |
||
| 361 | report['parameters']['values'] is None or \ |
||
| 362 | len(report['parameters']['values']) == 0 or \ |
||
| 363 | timestamps_data_all_equal_0(report['parameters']['timestamps']): |
||
| 364 | has_parameters_names_and_timestamps_and_values_data = False |
||
| 365 | if has_parameters_names_and_timestamps_and_values_data: |
||
| 366 | |||
| 367 | ################################################################################################################ |
||
| 368 | # new worksheet |
||
| 369 | ################################################################################################################ |
||
| 370 | |||
| 371 | parameters_data = report['parameters'] |
||
| 372 | |||
| 373 | parameters_names_len = len(parameters_data['names']) |
||
| 374 | |||
| 375 | file_name = (re.sub(r'[^A-Z]', '', ws.title))+'_' |
||
| 376 | parameters_ws = wb.create_sheet(file_name + 'Parameters') |
||
| 377 | |||
| 378 | parameters_timestamps_data_max_len = \ |
||
| 379 | get_parameters_timestamps_lists_max_len(list(parameters_data['timestamps'])) |
||
| 380 | |||
| 381 | # Row height |
||
| 382 | parameters_ws.row_dimensions[1].height = 102 |
||
| 383 | for i in range(2, 7 + 1): |
||
| 384 | parameters_ws.row_dimensions[i].height = 42 |
||
| 385 | |||
| 386 | for i in range(8, parameters_timestamps_data_max_len + 10): |
||
| 387 | parameters_ws.row_dimensions[i].height = 60 |
||
| 388 | |||
| 389 | # Col width |
||
| 390 | parameters_ws.column_dimensions['A'].width = 1.5 |
||
| 391 | |||
| 392 | parameters_ws.column_dimensions['B'].width = 25.0 |
||
| 393 | |||
| 394 | for i in range(3, 12 + parameters_names_len * 3): |
||
| 395 | parameters_ws.column_dimensions[format_cell.get_column_letter(i)].width = 15.0 |
||
| 396 | |||
| 397 | # Img |
||
| 398 | img = Image("excelexporters/myems.png") |
||
| 399 | parameters_ws.add_image(img, 'A1') |
||
| 400 | |||
| 401 | # Title |
||
| 402 | parameters_ws['B3'].alignment = b_r_alignment |
||
| 403 | parameters_ws['B3'] = 'Name:' |
||
| 404 | parameters_ws['C3'].border = b_border |
||
| 405 | parameters_ws['C3'].alignment = b_c_alignment |
||
| 406 | parameters_ws['C3'] = name |
||
| 407 | |||
| 408 | parameters_ws['D3'].alignment = b_r_alignment |
||
| 409 | parameters_ws['D3'] = 'Period:' |
||
| 410 | parameters_ws['E3'].border = b_border |
||
| 411 | parameters_ws['E3'].alignment = b_c_alignment |
||
| 412 | parameters_ws['E3'] = period_type |
||
| 413 | |||
| 414 | parameters_ws['B4'].alignment = b_r_alignment |
||
| 415 | parameters_ws['B4'] = 'Reporting Start Datetime:' |
||
| 416 | parameters_ws['C4'].border = b_border |
||
| 417 | parameters_ws['C4'].alignment = b_c_alignment |
||
| 418 | parameters_ws['C4'] = reporting_start_datetime_local |
||
| 419 | |||
| 420 | parameters_ws['D4'].alignment = b_r_alignment |
||
| 421 | parameters_ws['D4'] = 'Reporting End Datetime:' |
||
| 422 | parameters_ws['E4'].border = b_border |
||
| 423 | parameters_ws['E4'].alignment = b_c_alignment |
||
| 424 | parameters_ws['E4'] = reporting_end_datetime_local |
||
| 425 | |||
| 426 | parameters_ws_current_row_number = 6 |
||
| 427 | |||
| 428 | parameters_ws['B' + str(parameters_ws_current_row_number)].font = title_font |
||
| 429 | parameters_ws['B' + str(parameters_ws_current_row_number)] = name + ' ' + 'Parameters' |
||
| 430 | |||
| 431 | parameters_ws_current_row_number += 1 |
||
| 432 | |||
| 433 | parameters_table_start_row_number = parameters_ws_current_row_number |
||
| 434 | |||
| 435 | parameters_ws.row_dimensions[parameters_ws_current_row_number].height = 80 |
||
| 436 | |||
| 437 | parameters_ws_current_row_number += 1 |
||
| 438 | |||
| 439 | table_current_col_number = 2 |
||
| 440 | |||
| 441 | for i in range(0, parameters_names_len): |
||
| 442 | |||
| 443 | if len(parameters_data['timestamps'][i]) == 0: |
||
| 444 | continue |
||
| 445 | |||
| 446 | col = format_cell.get_column_letter(table_current_col_number) |
||
| 447 | |||
| 448 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
||
| 449 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
||
| 450 | |||
| 451 | col = format_cell.get_column_letter(table_current_col_number + 1) |
||
| 452 | |||
| 453 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].fill = table_fill |
||
| 454 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].border = f_border |
||
| 455 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].font = name_font |
||
| 456 | parameters_ws[col + str(parameters_ws_current_row_number - 1)].alignment = c_c_alignment |
||
| 457 | parameters_ws[col + str(parameters_ws_current_row_number - 1)] = parameters_data['names'][i] |
||
| 458 | |||
| 459 | table_current_row_number = parameters_ws_current_row_number |
||
| 460 | |||
| 461 | for j, value in enumerate(list(parameters_data['timestamps'][i])): |
||
| 462 | col = format_cell.get_column_letter(table_current_col_number) |
||
| 463 | |||
| 464 | parameters_ws[col + str(table_current_row_number)].border = f_border |
||
| 465 | parameters_ws[col + str(table_current_row_number)].font = title_font |
||
| 466 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
||
| 467 | parameters_ws[col + str(table_current_row_number)] = value |
||
| 468 | |||
| 469 | col = format_cell.get_column_letter(table_current_col_number + 1) |
||
| 470 | |||
| 471 | parameters_ws[col + str(table_current_row_number)].border = f_border |
||
| 472 | parameters_ws[col + str(table_current_row_number)].font = title_font |
||
| 473 | parameters_ws[col + str(table_current_row_number)].alignment = c_c_alignment |
||
| 474 | parameters_ws[col + str(table_current_row_number)] = round(parameters_data['values'][i][j], 2) |
||
| 475 | |||
| 476 | table_current_row_number += 1 |
||
| 477 | |||
| 478 | table_current_col_number = table_current_col_number + 3 |
||
| 479 | |||
| 480 | ################################################################################################################ |
||
| 481 | # parameters chart and parameters table |
||
| 482 | ################################################################################################################ |
||
| 483 | |||
| 484 | ws['B' + str(current_sheet_parameters_row_number)].font = title_font |
||
| 485 | ws['B' + str(current_sheet_parameters_row_number)] = name + ' ' + 'Parameters' |
||
| 486 | |||
| 487 | current_sheet_parameters_row_number += 1 |
||
| 488 | |||
| 489 | chart_start_row_number = current_sheet_parameters_row_number |
||
| 490 | |||
| 491 | col_index = 0 |
||
| 492 | |||
| 493 | for i in range(0, parameters_names_len): |
||
| 494 | |||
| 495 | if len(parameters_data['timestamps'][i]) == 0: |
||
| 496 | continue |
||
| 497 | |||
| 498 | line = LineChart() |
||
| 499 | data_col = 3 + col_index * 3 |
||
| 500 | labels_col = 2 + col_index * 3 |
||
| 501 | col_index += 1 |
||
| 502 | line.title = 'Parameters - ' + \ |
||
| 503 | parameters_ws.cell(row=parameters_table_start_row_number, column=data_col).value |
||
| 504 | labels = Reference(parameters_ws, min_col=labels_col, min_row=parameters_table_start_row_number + 1, |
||
| 505 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
||
| 506 | line_data = Reference(parameters_ws, min_col=data_col, min_row=parameters_table_start_row_number, |
||
| 507 | max_row=(len(parameters_data['timestamps'][i]) + parameters_table_start_row_number)) |
||
| 508 | line.add_data(line_data, titles_from_data=True) |
||
| 509 | line.set_categories(labels) |
||
| 510 | line_data = line.series[0] |
||
| 511 | line_data.marker.symbol = "circle" |
||
| 512 | line_data.smooth = True |
||
| 513 | line.x_axis.crosses = 'min' |
||
| 514 | line.height = 8.25 |
||
| 515 | line.width = 24 |
||
| 516 | line.dLbls = DataLabelList() |
||
| 517 | line.dLbls.dLblPos = 't' |
||
| 518 | line.dLbls.showVal = False |
||
| 519 | line.dLbls.showPercent = False |
||
| 520 | chart_col = 'B' |
||
| 521 | chart_cell = chart_col + str(chart_start_row_number) |
||
| 522 | chart_start_row_number += 6 |
||
| 523 | ws.add_chart(line, chart_cell) |
||
| 524 | |||
| 525 | current_sheet_parameters_row_number = chart_start_row_number |
||
| 526 | |||
| 527 | current_sheet_parameters_row_number += 1 |
||
| 528 | |||
| 529 | filename = str(uuid.uuid4()) + '.xlsx' |
||
| 530 | wb.save(filename) |
||
| 531 | |||
| 532 | return filename |
||
| 533 | |||
| 558 |