Code Duplication    Length = 29-29 lines in 2 locations

reports/dashboard.py 1 location

@@ 634-662 (lines=29) @@
631
        ################################################################################################################
632
        child_space_input = dict()
633
634
        if energy_category_set is not None and len(energy_category_set) > 0:
635
            for energy_category_id in energy_category_set:
636
                child_space_input[energy_category_id] = dict()
637
                child_space_input[energy_category_id]['child_space_names'] = list()
638
                child_space_input[energy_category_id]['subtotal'] = Decimal(0.0)
639
                child_space_input[energy_category_id]['subtotal_in_kgce'] = Decimal(0.0)
640
                child_space_input[energy_category_id]['subtotal_in_kgco2e'] = Decimal(0.0)
641
                kgce = energy_category_dict[energy_category_id]['kgce']
642
                kgco2e = energy_category_dict[energy_category_id]['kgco2e']
643
                for child_space in child_space_list:
644
                    child_space_input[energy_category_id]['child_space_names'].append(child_space['name'])
645
646
                    cursor_energy.execute(" SELECT SUM(actual_value) "
647
                                          " FROM tbl_space_input_category_hourly "
648
                                          " WHERE space_id = %s "
649
                                          "     AND energy_category_id = %s "
650
                                          "     AND start_datetime_utc >= %s "
651
                                          "     AND start_datetime_utc < %s "
652
                                          " ORDER BY start_datetime_utc ",
653
                                          (child_space['id'],
654
                                           energy_category_id,
655
                                           reporting_start_datetime_utc,
656
                                           reporting_end_datetime_utc))
657
                    row_subtotal = cursor_energy.fetchone()
658
659
                    subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0]
660
                    child_space_input[energy_category_id]['subtotal'] = subtotal
661
                    child_space_input[energy_category_id]['subtotal_in_kgce'] = subtotal * kgce
662
                    child_space_input[energy_category_id]['subtotal_in_kgco2e'] = subtotal * kgco2e
663
664
        ################################################################################################################
665
        # Step 12: query child spaces energy cost

reports/spaceenergycategory.py 1 location

@@ 478-506 (lines=29) @@
475
        ################################################################################################################
476
        child_space_data = dict()
477
478
        if energy_category_set is not None and len(energy_category_set) > 0:
479
            for energy_category_id in energy_category_set:
480
                child_space_data[energy_category_id] = dict()
481
                child_space_data[energy_category_id]['child_space_names'] = list()
482
                child_space_data[energy_category_id]['subtotal'] = Decimal(0.0)
483
                child_space_data[energy_category_id]['subtotal_in_kgce'] = Decimal(0.0)
484
                child_space_data[energy_category_id]['subtotal_in_kgco2e'] = Decimal(0.0)
485
                kgce = energy_category_dict[energy_category_id]['kgce']
486
                kgco2e = energy_category_dict[energy_category_id]['kgco2e']
487
                for child_space in child_space_list:
488
                    child_space_data[energy_category_id]['child_space_names'].append(child_space['name'])
489
490
                    cursor_energy.execute(" SELECT SUM(actual_value) "
491
                                          " FROM tbl_space_input_category_hourly "
492
                                          " WHERE space_id = %s "
493
                                          "     AND energy_category_id = %s "
494
                                          "     AND start_datetime_utc >= %s "
495
                                          "     AND start_datetime_utc < %s "
496
                                          " ORDER BY start_datetime_utc ",
497
                                          (child_space['id'],
498
                                           energy_category_id,
499
                                           reporting_start_datetime_utc,
500
                                           reporting_end_datetime_utc))
501
                    row_subtotal = cursor_energy.fetchone()
502
503
                    subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0]
504
                    child_space_data[energy_category_id]['subtotal'] = subtotal
505
                    child_space_data[energy_category_id]['subtotal_in_kgce'] = subtotal * kgce
506
                    child_space_data[energy_category_id]['subtotal_in_kgco2e'] = subtotal * kgco2e
507
508
        ################################################################################################################
509
        # Step 12: construct the report