Code Duplication    Length = 22-23 lines in 4 locations

myems-api/reports/combinedequipmentincome.py 1 location

@@ 579-601 (lines=23) @@
576
        result['reporting_period']['total_increment_rate'] = Decimal(0.0)
577
        result['reporting_period']['total_unit'] = config.currency_unit
578
579
        if energy_category_set is not None and len(energy_category_set) > 0:
580
            for energy_category_id in energy_category_set:
581
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
582
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
583
                result['reporting_period']['units'].append(config.currency_unit)
584
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
585
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
586
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
587
                result['reporting_period']['increment_rates'].append(
588
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
589
                    base[energy_category_id]['subtotal']
590
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
591
                result['reporting_period']['total'] += reporting[energy_category_id]['subtotal']
592
593
                rate = list()
594
                for index, value in enumerate(reporting[energy_category_id]['values']):
595
                    if index < len(base[energy_category_id]['values']) \
596
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
597
                        rate.append((value - base[energy_category_id]['values'][index])
598
                                    / base[energy_category_id]['values'][index])
599
                    else:
600
                        rate.append(None)
601
                result['reporting_period']['rates'].append(rate)
602
603
        result['reporting_period']['total_increment_rate'] = \
604
            (result['reporting_period']['total'] - result['base_period']['total']) / \

myems-api/reports/equipmentincome.py 1 location

@@ 530-552 (lines=23) @@
527
        result['reporting_period']['total_increment_rate'] = Decimal(0.0)
528
        result['reporting_period']['total_unit'] = config.currency_unit
529
530
        if energy_category_set is not None and len(energy_category_set) > 0:
531
            for energy_category_id in energy_category_set:
532
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
533
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
534
                result['reporting_period']['units'].append(config.currency_unit)
535
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
536
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
537
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
538
                result['reporting_period']['increment_rates'].append(
539
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
540
                    base[energy_category_id]['subtotal']
541
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
542
                result['reporting_period']['total'] += reporting[energy_category_id]['subtotal']
543
544
                rate = list()
545
                for index, value in enumerate(reporting[energy_category_id]['values']):
546
                    if index < len(base[energy_category_id]['values']) \
547
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
548
                        rate.append((value - base[energy_category_id]['values'][index])
549
                                    / base[energy_category_id]['values'][index])
550
                    else:
551
                        rate.append(None)
552
                result['reporting_period']['rates'].append(rate)
553
554
        result['reporting_period']['total_increment_rate'] = \
555
            (result['reporting_period']['total'] - result['base_period']['total']) / \

myems-api/reports/combinedequipmentoutput.py 1 location

@@ 573-594 (lines=22) @@
570
        result['reporting_period']['subtotals'] = list()
571
        result['reporting_period']['increment_rates'] = list()
572
573
        if energy_category_set is not None and len(energy_category_set) > 0:
574
            for energy_category_id in energy_category_set:
575
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
576
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
577
                result['reporting_period']['units'].append(energy_category_dict[energy_category_id]['unit_of_measure'])
578
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
579
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
580
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
581
                result['reporting_period']['increment_rates'].append(
582
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
583
                    base[energy_category_id]['subtotal']
584
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
585
586
                rate = list()
587
                for index, value in enumerate(reporting[energy_category_id]['values']):
588
                    if index < len(base[energy_category_id]['values']) \
589
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
590
                        rate.append((value - base[energy_category_id]['values'][index])
591
                                    / base[energy_category_id]['values'][index])
592
                    else:
593
                        rate.append(None)
594
                result['reporting_period']['rates'].append(rate)
595
596
        result['parameters'] = {
597
            "names": parameters_data['names'],

myems-api/reports/equipmentoutput.py 1 location

@@ 523-544 (lines=22) @@
520
        result['reporting_period']['subtotals'] = list()
521
        result['reporting_period']['increment_rates'] = list()
522
523
        if energy_category_set is not None and len(energy_category_set) > 0:
524
            for energy_category_id in energy_category_set:
525
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
526
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
527
                result['reporting_period']['units'].append(energy_category_dict[energy_category_id]['unit_of_measure'])
528
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
529
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
530
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
531
                result['reporting_period']['increment_rates'].append(
532
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
533
                    base[energy_category_id]['subtotal']
534
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
535
536
                rate = list()
537
                for index, value in enumerate(reporting[energy_category_id]['values']):
538
                    if index < len(base[energy_category_id]['values']) \
539
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
540
                        rate.append((value - base[energy_category_id]['values'][index])
541
                                    / base[energy_category_id]['values'][index])
542
                    else:
543
                        rate.append(None)
544
                result['reporting_period']['rates'].append(rate)
545
546
        result['parameters'] = {
547
            "names": parameters_data['names'],