Code Duplication    Length = 106-108 lines in 4 locations

excelexporters/spaceenergyitem.py 1 location

@@ 390-497 (lines=108) @@
387
                len(reporting_period_data['timestamps'][0]) == 0:
388
            has_timestamps_data = False
389
390
        if has_values_data and has_timestamps_data:
391
            ca_len = len(reporting_period_data['names'])
392
            time = reporting_period_data['timestamps'][0]
393
394
            ws['B' + str(current_row_number)].font = title_font
395
            ws['B' + str(current_row_number)] = name + ' 详细数据'
396
397
            current_row_number += 1
398
399
            chart_start_row_number = current_row_number
400
401
            current_row_number += ca_len * 6
402
            table_start_row_number = current_row_number
403
404
            ws['B' + str(current_row_number)].fill = table_fill
405
            ws['B' + str(current_row_number)].font = title_small_font
406
            ws['B' + str(current_row_number)].alignment = c_c_alignment
407
            ws['B' + str(current_row_number)].border = f_border
408
            ws['B' + str(current_row_number)] = '日期时间'
409
410
            col = 'C'
411
412
            for i in range(0, ca_len):
413
                ws[col + str(current_row_number)].fill = table_fill
414
                ws[col + str(current_row_number)].font = title_small_font
415
                ws[col + str(current_row_number)].alignment = c_c_alignment
416
                ws[col + str(current_row_number)].border = f_border
417
                ws[col + str(current_row_number)] = \
418
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
419
                col = chr(ord(col) + 1)
420
421
            current_row_number += 1
422
423
            for i in range(0, len(time)):
424
                ws['B' + str(current_row_number)].font = title_font
425
                ws['B' + str(current_row_number)].alignment = c_c_alignment
426
                ws['B' + str(current_row_number)].border = f_border
427
                ws['B' + str(current_row_number)] = time[i]
428
429
                col = 'C'
430
                for j in range(0, ca_len):
431
                    ws[col + str(current_row_number)].font = title_font
432
                    ws[col + str(current_row_number)].alignment = c_c_alignment
433
                    ws[col + str(current_row_number)].border = f_border
434
                    ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
435
                        if reporting_period_data['values'][j][i] is not None else 0.00
436
                    col = chr(ord(col) + 1)
437
438
                current_row_number += 1
439
440
            table_end_row_number = current_row_number - 1
441
442
            ws['B' + str(current_row_number)].font = title_font
443
            ws['B' + str(current_row_number)].alignment = c_c_alignment
444
            ws['B' + str(current_row_number)].border = f_border
445
            ws['B' + str(current_row_number)] = '小计'
446
447
            col = 'C'
448
449
            for i in range(0, ca_len):
450
                ws[col + str(current_row_number)].font = title_font
451
                ws[col + str(current_row_number)].alignment = c_c_alignment
452
                ws[col + str(current_row_number)].border = f_border
453
                ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
454
                col = chr(ord(col) + 1)
455
456
            current_row_number += 2
457
458
            format_time_width_number = 1.0
459
            min_len_number = 1.0
460
            min_width_number = 11.0  # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
461
462
            if period_type == 'hourly':
463
                format_time_width_number = 4.0
464
                min_len_number = 2
465
                min_width_number = 12.0
466
            elif period_type == 'daily':
467
                format_time_width_number = 2.5
468
                min_len_number = 4
469
                min_width_number = 14.0
470
            elif period_type == 'monthly':
471
                format_time_width_number = 2.1
472
                min_len_number = 4
473
                min_width_number = 12.4
474
            elif period_type == 'yearly':
475
                format_time_width_number = 1.5
476
                min_len_number = 5
477
                min_width_number = 11.5
478
479
            for i in range(0, ca_len):
480
                bar = BarChart()
481
                bar.title = \
482
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
483
                labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
484
                bar_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
485
                bar.add_data(bar_data, titles_from_data=True)
486
                bar.set_categories(labels)
487
                bar.height = 5.85
488
                bar.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
489
                if bar.width > 24:
490
                    bar.width = 24
491
                bar.dLbls = DataLabelList()
492
                bar.dLbls.showVal = False
493
                bar.dLbls.showPercent = True
494
                chart_col = 'B'
495
                chart_cell = chart_col + str(chart_start_row_number)
496
                chart_start_row_number += 6
497
                ws.add_chart(bar, chart_cell)
498
499
    filename = str(uuid.uuid4()) + '.xlsx'
500
    wb.save(filename)

excelexporters/tenantenergyitem.py 1 location

@@ 314-421 (lines=108) @@
311
                len(reporting_period_data['timestamps'][0]) == 0:
312
            has_timestamps_data = False
313
314
        if has_values_data and has_timestamps_data:
315
            ca_len = len(reporting_period_data['names'])
316
            time = reporting_period_data['timestamps'][0]
317
318
            ws['B' + str(current_row_number)].font = title_font
319
            ws['B' + str(current_row_number)] = name + ' 详细数据'
320
321
            current_row_number += 1
322
323
            chart_start_row_number = current_row_number
324
325
            current_row_number += ca_len * 6
326
            table_start_row_number = current_row_number
327
328
            ws['B' + str(current_row_number)].fill = table_fill
329
            ws['B' + str(current_row_number)].font = title_small_font
330
            ws['B' + str(current_row_number)].alignment = c_c_alignment
331
            ws['B' + str(current_row_number)].border = f_border
332
            ws['B' + str(current_row_number)] = '日期时间'
333
334
            col = 'C'
335
336
            for i in range(0, ca_len):
337
                ws[col + str(current_row_number)].fill = table_fill
338
                ws[col + str(current_row_number)].font = title_small_font
339
                ws[col + str(current_row_number)].alignment = c_c_alignment
340
                ws[col + str(current_row_number)].border = f_border
341
                ws[col + str(current_row_number)] = \
342
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
343
                col = chr(ord(col) + 1)
344
345
            current_row_number += 1
346
347
            for i in range(0, len(time)):
348
                ws['B' + str(current_row_number)].font = title_font
349
                ws['B' + str(current_row_number)].alignment = c_c_alignment
350
                ws['B' + str(current_row_number)].border = f_border
351
                ws['B' + str(current_row_number)] = time[i]
352
353
                col = 'C'
354
                for j in range(0, ca_len):
355
                    ws[col + str(current_row_number)].font = title_font
356
                    ws[col + str(current_row_number)].alignment = c_c_alignment
357
                    ws[col + str(current_row_number)].border = f_border
358
                    ws[col + str(current_row_number)] = round(reporting_period_data['values'][j][i], 2) \
359
                        if reporting_period_data['values'][j][i] is not None else 0.00
360
                    col = chr(ord(col) + 1)
361
362
                current_row_number += 1
363
364
            table_end_row_number = current_row_number - 1
365
366
            ws['B' + str(current_row_number)].font = title_font
367
            ws['B' + str(current_row_number)].alignment = c_c_alignment
368
            ws['B' + str(current_row_number)].border = f_border
369
            ws['B' + str(current_row_number)] = '小计'
370
371
            col = 'C'
372
373
            for i in range(0, ca_len):
374
                ws[col + str(current_row_number)].font = title_font
375
                ws[col + str(current_row_number)].alignment = c_c_alignment
376
                ws[col + str(current_row_number)].border = f_border
377
                ws[col + str(current_row_number)] = round(reporting_period_data['subtotals'][i], 2)
378
                col = chr(ord(col) + 1)
379
380
            current_row_number += 2
381
382
            format_time_width_number = 1.0
383
            min_len_number = 1.0
384
            min_width_number = 11.0  # format_time_width_number * min_len_number + 4 and min_width_number > 11.0
385
386
            if period_type == 'hourly':
387
                format_time_width_number = 4.0
388
                min_len_number = 2
389
                min_width_number = 12.0
390
            elif period_type == 'daily':
391
                format_time_width_number = 2.5
392
                min_len_number = 4
393
                min_width_number = 14.0
394
            elif period_type == 'monthly':
395
                format_time_width_number = 2.1
396
                min_len_number = 4
397
                min_width_number = 12.4
398
            elif period_type == 'yearly':
399
                format_time_width_number = 1.5
400
                min_len_number = 5
401
                min_width_number = 11.5
402
403
            for i in range(0, ca_len):
404
                bar = BarChart()
405
                bar.title = \
406
                    reporting_period_data['names'][i] + " (" + reporting_period_data['units'][i] + ")"
407
                labels = Reference(ws, min_col=2, min_row=table_start_row_number + 1, max_row=table_end_row_number)
408
                bar_data = Reference(ws, min_col=3 + i, min_row=table_start_row_number, max_row=table_end_row_number)
409
                bar.add_data(bar_data, titles_from_data=True)
410
                bar.set_categories(labels)
411
                bar.height = 5.85
412
                bar.width = format_time_width_number * len(time) if len(time) > min_len_number else min_width_number
413
                if bar.width > 24:
414
                    bar.width = 24
415
                bar.dLbls = DataLabelList()
416
                bar.dLbls.showVal = False
417
                bar.dLbls.showPercent = True
418
                chart_col = 'B'
419
                chart_cell = chart_col + str(chart_start_row_number)
420
                chart_start_row_number += 6
421
                ws.add_chart(bar, chart_cell)
422
423
    filename = str(uuid.uuid4()) + '.xlsx'
424
    wb.save(filename)

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)