Code Duplication    Length = 33-33 lines in 2 locations

myems-api/reports/spacecost.py 1 location

@@ 617-649 (lines=33) @@
614
        result['reporting_period']['total_increment_rate'] = Decimal(0.0)
615
        result['reporting_period']['total_unit'] = config.currency_unit
616
617
        if energy_category_set is not None and len(energy_category_set) > 0:
618
            for energy_category_id in energy_category_set:
619
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
620
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
621
                result['reporting_period']['units'].append(config.currency_unit)
622
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
623
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
624
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
625
                result['reporting_period']['subtotals_per_unit_area'].append(
626
                    reporting[energy_category_id]['subtotal'] / space['area'] if space['area'] > 0.0 else None)
627
                result['reporting_period']['subtotals_per_capita'].append(
628
                    reporting[energy_category_id]['subtotal'] / space['number_of_occupants']
629
                    if space['number_of_occupants'] > 0.0 else None)
630
                result['reporting_period']['toppeaks'].append(reporting[energy_category_id]['toppeak'])
631
                result['reporting_period']['onpeaks'].append(reporting[energy_category_id]['onpeak'])
632
                result['reporting_period']['midpeaks'].append(reporting[energy_category_id]['midpeak'])
633
                result['reporting_period']['offpeaks'].append(reporting[energy_category_id]['offpeak'])
634
                result['reporting_period']['deeps'].append(reporting[energy_category_id]['deep'])
635
                result['reporting_period']['increment_rates'].append(
636
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
637
                    base[energy_category_id]['subtotal']
638
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
639
                result['reporting_period']['total'] += reporting[energy_category_id]['subtotal']
640
641
                rate = list()
642
                for index, value in enumerate(reporting[energy_category_id]['values']):
643
                    if index < len(base[energy_category_id]['values']) \
644
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
645
                        rate.append((value - base[energy_category_id]['values'][index])
646
                                    / base[energy_category_id]['values'][index])
647
                    else:
648
                        rate.append(None)
649
                result['reporting_period']['rates'].append(rate)
650
651
        result['reporting_period']['total_per_unit_area'] = \
652
            result['reporting_period']['total'] / space['area'] if space['area'] > 0.0 else None

myems-api/reports/spacecarbon.py 1 location

@@ 616-648 (lines=33) @@
613
        result['reporting_period']['total_increment_rate'] = Decimal(0.0)
614
        result['reporting_period']['total_unit'] = 'KG'
615
616
        if energy_category_set is not None and len(energy_category_set) > 0:
617
            for energy_category_id in energy_category_set:
618
                result['reporting_period']['names'].append(energy_category_dict[energy_category_id]['name'])
619
                result['reporting_period']['energy_category_ids'].append(energy_category_id)
620
                result['reporting_period']['units'].append('KG')
621
                result['reporting_period']['timestamps'].append(reporting[energy_category_id]['timestamps'])
622
                result['reporting_period']['values'].append(reporting[energy_category_id]['values'])
623
                result['reporting_period']['subtotals'].append(reporting[energy_category_id]['subtotal'])
624
                result['reporting_period']['subtotals_per_unit_area'].append(
625
                    reporting[energy_category_id]['subtotal'] / space['area'] if space['area'] > 0.0 else None)
626
                result['reporting_period']['subtotals_per_capita'].append(
627
                    reporting[energy_category_id]['subtotal'] / space['number_of_occupants']
628
                    if space['number_of_occupants'] > 0.0 else None)
629
                result['reporting_period']['toppeaks'].append(reporting[energy_category_id]['toppeak'])
630
                result['reporting_period']['onpeaks'].append(reporting[energy_category_id]['onpeak'])
631
                result['reporting_period']['midpeaks'].append(reporting[energy_category_id]['midpeak'])
632
                result['reporting_period']['offpeaks'].append(reporting[energy_category_id]['offpeak'])
633
                result['reporting_period']['deeps'].append(reporting[energy_category_id]['deep'])
634
                result['reporting_period']['increment_rates'].append(
635
                    (reporting[energy_category_id]['subtotal'] - base[energy_category_id]['subtotal']) /
636
                    base[energy_category_id]['subtotal']
637
                    if base[energy_category_id]['subtotal'] > 0.0 else None)
638
                result['reporting_period']['total'] += reporting[energy_category_id]['subtotal']
639
640
                rate = list()
641
                for index, value in enumerate(reporting[energy_category_id]['values']):
642
                    if index < len(base[energy_category_id]['values']) \
643
                            and base[energy_category_id]['values'][index] != 0 and value != 0:
644
                        rate.append((value - base[energy_category_id]['values'][index])
645
                                    / base[energy_category_id]['values'][index])
646
                    else:
647
                        rate.append(None)
648
                result['reporting_period']['rates'].append(rate)
649
650
        result['reporting_period']['total_per_unit_area'] = \
651
            result['reporting_period']['total'] / space['area'] if space['area'] > 0.0 else None