Code Duplication    Length = 106-106 lines in 2 locations

excelexporters/spacesaving.py 1 location

@@ 523-628 (lines=106) @@
520
            len(reporting_period_data['timestamps'][0]) == 0:
521
        has_timestamps_data = False
522
523
    if has_values_saving_data and has_timestamps_data:
524
        ca_len = len(reporting_period_data['names'])
525
        time = reporting_period_data['timestamps'][0]
526
527
        ws['B' + str(current_row_number)].font = title_font
528
        ws['B' + str(current_row_number)] = name + ' 详细数据'
529
530
        current_row_number += 1
531
532
        chart_start_row_number = current_row_number
533
534
        current_row_number += ca_len * 5
535
        table_start_row_number = current_row_number
536
537
        ws['B' + str(current_row_number)].fill = table_fill
538
        ws['B' + str(current_row_number)].font = title_font
539
        ws['B' + str(current_row_number)].alignment = c_c_alignment
540
        ws['B' + str(current_row_number)].border = f_border
541
        ws['B' + str(current_row_number)] = '日期时间'
542
543
        col = 'C'
544
545
        for i in range(0, ca_len):
546
            ws[col + str(current_row_number)].fill = table_fill
547
            ws[col + str(current_row_number)].font = title_font
548
            ws[col + str(current_row_number)].alignment = c_c_alignment
549
            ws[col + str(current_row_number)].border = f_border
550
            ws[col + str(current_row_number)] = \
551
                reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
552
            col = chr(ord(col) + 1)
553
554
        current_row_number += 1
555
556
        for i in range(0, len(time)):
557
            ws['B' + str(current_row_number)].font = title_font
558
            ws['B' + str(current_row_number)].alignment = c_c_alignment
559
            ws['B' + str(current_row_number)].border = f_border
560
            ws['B' + str(current_row_number)] = time[i]
561
562
            col = 'C'
563
            for j in range(0, ca_len):
564
                ws[col + str(current_row_number)].font = title_font
565
                ws[col + str(current_row_number)].alignment = c_c_alignment
566
                ws[col + str(current_row_number)].border = f_border
567
                ws[col + str(current_row_number)] = round(reporting_period_data['values_saving'][j][i], 2) \
568
                    if reporting_period_data['values_saving'][j][i] is not None else 0.00
569
                col = chr(ord(col) + 1)
570
571
            current_row_number += 1
572
573
        table_end_row_number = current_row_number - 1
574
575
        ws['B' + str(current_row_number)].font = title_font
576
        ws['B' + str(current_row_number)].alignment = c_c_alignment
577
        ws['B' + str(current_row_number)].border = f_border
578
        ws['B' + str(current_row_number)] = '小计'
579
580
        col = 'C'
581
582
        for i in range(0, ca_len):
583
            ws[col + str(current_row_number)].font = title_font
584
            ws[col + str(current_row_number)].alignment = c_c_alignment
585
            ws[col + str(current_row_number)].border = f_border
586
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
587
            col = chr(ord(col) + 1)
588
589
        current_row_number += 2
590
591
        format_time_width_number = 1.0
592
        min_len_number = 1.0
593
        min_width_number = 11.0  # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
594
595
        if period_type == 'hourly':
596
            format_time_width_number = 4.0
597
            min_len_number = 2
598
            min_width_number = 12.0
599
        elif period_type == 'daily':
600
            format_time_width_number = 2.5
601
            min_len_number = 4
602
            min_width_number = 14.0
603
        elif period_type == 'monthly':
604
            format_time_width_number = 2.1
605
            min_len_number = 4
606
            min_width_number = 12.4
607
        elif period_type == 'yearly':
608
            format_time_width_number = 1.5
609
            min_len_number = 5
610
            min_width_number = 11.5
611
612
        for i in range(0, ca_len):
613
            bar = BarChart()
614
            bar.title = \
615
                reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
616
            labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
617
            bar_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
618
            bar.add_data(bar_data, titles_from_data=True)
619
            bar.set_categories(labels)
620
            bar.height = 5.25
621
            bar.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
622
            bar.dLbls = DataLabelList()
623
            bar.dLbls.showVal = True
624
            bar.dLbls.showPercent = True
625
            chart_col = 'B'
626
            chart_cell = chart_col + str(chart_start_row_number)
627
            chart_start_row_number += 5
628
            ws.add_chart(bar, chart_cell)
629
630
    filename = str(uuid.uuid4()) + '.xlsx'
631
    wb.save(filename)

excelexporters/tenantsaving.py 1 location

@@ 438-543 (lines=106) @@
435
            len(reporting_period_data['timestamps'][0]) == 0:
436
        has_timestamps_data = False
437
438
    if has_values_saving_data and has_timestamps_data:
439
        ca_len = len(reporting_period_data['names'])
440
        time = reporting_period_data['timestamps'][0]
441
442
        ws['B' + str(current_row_number)].font = title_font
443
        ws['B' + str(current_row_number)] = name + ' 详细数据'
444
445
        current_row_number += 1
446
447
        chart_start_row_number = current_row_number
448
449
        current_row_number += ca_len * 5
450
        table_start_row_number = current_row_number
451
452
        ws['B' + str(current_row_number)].fill = table_fill
453
        ws['B' + str(current_row_number)].font = title_font
454
        ws['B' + str(current_row_number)].alignment = c_c_alignment
455
        ws['B' + str(current_row_number)].border = f_border
456
        ws['B' + str(current_row_number)] = '日期时间'
457
458
        col = 'C'
459
460
        for i in range(0, ca_len):
461
            ws[col + str(current_row_number)].fill = table_fill
462
            ws[col + str(current_row_number)].font = title_font
463
            ws[col + str(current_row_number)].alignment = c_c_alignment
464
            ws[col + str(current_row_number)].border = f_border
465
            ws[col + str(current_row_number)] = \
466
                reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
467
            col = chr(ord(col) + 1)
468
469
        current_row_number += 1
470
471
        for i in range(0, len(time)):
472
            ws['B' + str(current_row_number)].font = title_font
473
            ws['B' + str(current_row_number)].alignment = c_c_alignment
474
            ws['B' + str(current_row_number)].border = f_border
475
            ws['B' + str(current_row_number)] = time[i]
476
477
            col = 'C'
478
            for j in range(0, ca_len):
479
                ws[col + str(current_row_number)].font = title_font
480
                ws[col + str(current_row_number)].alignment = c_c_alignment
481
                ws[col + str(current_row_number)].border = f_border
482
                ws[col + str(current_row_number)] = round(reporting_period_data['values_saving'][j][i], 2) \
483
                    if reporting_period_data['values_saving'][j][i] is not None else 0.00
484
                col = chr(ord(col) + 1)
485
486
            current_row_number += 1
487
488
        table_end_row_number = current_row_number - 1
489
490
        ws['B' + str(current_row_number)].font = title_font
491
        ws['B' + str(current_row_number)].alignment = c_c_alignment
492
        ws['B' + str(current_row_number)].border = f_border
493
        ws['B' + str(current_row_number)] = '小计'
494
495
        col = 'C'
496
497
        for i in range(0, ca_len):
498
            ws[col + str(current_row_number)].font = title_font
499
            ws[col + str(current_row_number)].alignment = c_c_alignment
500
            ws[col + str(current_row_number)].border = f_border
501
            ws[col + str(current_row_number)] = round(reporting_period_data['subtotals_saving'][i], 2)
502
            col = chr(ord(col) + 1)
503
504
        current_row_number += 2
505
506
        format_time_width_number = 1.0
507
        min_len_number = 1.0
508
        min_width_number = 11.0  # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
509
510
        if period_type == 'hourly':
511
            format_time_width_number = 4.0
512
            min_len_number = 2
513
            min_width_number = 12.0
514
        elif period_type == 'daily':
515
            format_time_width_number = 2.5
516
            min_len_number = 4
517
            min_width_number = 14.0
518
        elif period_type == 'monthly':
519
            format_time_width_number = 2.1
520
            min_len_number = 4
521
            min_width_number = 12.4
522
        elif period_type == 'yearly':
523
            format_time_width_number = 1.5
524
            min_len_number = 5
525
            min_width_number = 11.5
526
527
        for i in range(0, ca_len):
528
            bar = BarChart()
529
            bar.title = \
530
                reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
531
            labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
532
            bar_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
533
            bar.add_data(bar_data, titles_from_data=True)
534
            bar.set_categories(labels)
535
            bar.height = 5.25
536
            bar.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
537
            bar.dLbls = DataLabelList()
538
            bar.dLbls.showVal = True
539
            bar.dLbls.showPercent = True
540
            chart_col = 'B'
541
            chart_cell = chart_col + str(chart_start_row_number)
542
            chart_start_row_number += 5
543
            ws.add_chart(bar, chart_cell)
544
545
    filename = str(uuid.uuid4()) + '.xlsx'
546
    wb.save(filename)