Code Duplication    Length = 23-24 lines in 2 locations

reports/spaceoutput.py 1 location

@@ 445-467 (lines=23) @@
442
        ################################################################################################################
443
        child_space_data = dict()
444
445
        if energy_category_set is not None and len(energy_category_set) > 0:
446
            for energy_category_id in energy_category_set:
447
                child_space_data[energy_category_id] = dict()
448
                child_space_data[energy_category_id]['child_space_names'] = list()
449
                child_space_data[energy_category_id]['subtotals'] = list()
450
                for child_space in child_space_list:
451
                    child_space_data[energy_category_id]['child_space_names'].append(child_space['name'])
452
453
                    cursor_energy.execute(" SELECT SUM(actual_value) "
454
                                          " FROM tbl_space_output_category_hourly "
455
                                          " WHERE space_id = %s "
456
                                          "     AND energy_category_id = %s "
457
                                          "     AND start_datetime_utc >= %s "
458
                                          "     AND start_datetime_utc < %s "
459
                                          " ORDER BY start_datetime_utc ",
460
                                          (child_space['id'],
461
                                           energy_category_id,
462
                                           reporting_start_datetime_utc,
463
                                           reporting_end_datetime_utc))
464
                    row_subtotal = cursor_energy.fetchone()
465
466
                    subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0]
467
                    child_space_data[energy_category_id]['subtotals'].append(subtotal)
468
469
        ################################################################################################################
470
        # Step 12: construct the report

reports/spaceenergyitem.py 1 location

@@ 471-494 (lines=24) @@
468
        ################################################################################################################
469
        child_space_data = dict()
470
471
        if energy_item_set is not None and len(energy_item_set) > 0:
472
            for energy_item_id in energy_item_set:
473
                child_space_data[energy_item_id] = dict()
474
                child_space_data[energy_item_id]['child_space_names'] = list()
475
                child_space_data[energy_item_id]['subtotals'] = list()
476
477
                for child_space in child_space_list:
478
                    child_space_data[energy_item_id]['child_space_names'].append(child_space['name'])
479
480
                    cursor_energy.execute(" SELECT SUM(actual_value) "
481
                                          " FROM tbl_space_input_item_hourly "
482
                                          " WHERE space_id = %s "
483
                                          "     AND energy_item_id = %s "
484
                                          "     AND start_datetime_utc >= %s "
485
                                          "     AND start_datetime_utc < %s "
486
                                          " ORDER BY start_datetime_utc ",
487
                                          (child_space['id'],
488
                                           energy_item_id,
489
                                           reporting_start_datetime_utc,
490
                                           reporting_end_datetime_utc))
491
                    row_subtotal = cursor_energy.fetchone()
492
493
                    subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0]
494
                    child_space_data[energy_item_id]['subtotals'].append(subtotal)
495
496
        ################################################################################################################
497
        # Step 12: construct the report