Code Duplication    Length = 28-28 lines in 2 locations

myems-api/reports/dashboard.py 2 locations

@@ 453-480 (lines=28) @@
450
        # Step 8: query base period energy output
451
        ################################################################################################################
452
        base_output = dict()
453
        if output_energy_category_set is not None and len(output_energy_category_set) > 0:
454
            for energy_category_id in output_energy_category_set:
455
                kgce = energy_category_dict[energy_category_id]['kgce']
456
                kgco2e = energy_category_dict[energy_category_id]['kgco2e']
457
458
                base_output[energy_category_id] = dict()
459
                base_output[energy_category_id]['subtotal'] = Decimal(0.0)
460
                base_output[energy_category_id]['subtotal_in_kgce'] = Decimal(0.0)
461
                base_output[energy_category_id]['subtotal_in_kgco2e'] = Decimal(0.0)
462
463
                cursor_energy.execute(" SELECT SUM(actual_value) "
464
                                      " FROM tbl_space_output_category_hourly "
465
                                      " WHERE space_id = %s "
466
                                      "     AND energy_category_id = %s "
467
                                      "     AND start_datetime_utc >= %s "
468
                                      "     AND start_datetime_utc < %s ",
469
                                      (space['id'],
470
                                       energy_category_id,
471
                                       base_start_datetime_utc,
472
                                       base_end_datetime_utc))
473
                row_space_sum = cursor_energy.fetchone()
474
                if row_space_sum is None or len(row_space_sum) < 1 or row_space_sum[0] is None:
475
                    actual_value = Decimal(0.0)
476
                else:
477
                    actual_value = row_space_sum[0]
478
                base_output[energy_category_id]['subtotal'] = actual_value
479
                base_output[energy_category_id]['subtotal_in_kgce'] = actual_value * kgce
480
                base_output[energy_category_id]['subtotal_in_kgco2e'] = actual_value * kgco2e
481
482
        ################################################################################################################
483
        # Step 9: query reporting period energy input
@@ 394-421 (lines=28) @@
391
        # Step 6: query base period energy input
392
        ################################################################################################################
393
        base_input = dict()
394
        if input_energy_category_set is not None and len(input_energy_category_set) > 0:
395
            for energy_category_id in input_energy_category_set:
396
                kgce = energy_category_dict[energy_category_id]['kgce']
397
                kgco2e = energy_category_dict[energy_category_id]['kgco2e']
398
399
                base_input[energy_category_id] = dict()
400
                base_input[energy_category_id]['subtotal'] = Decimal(0.0)
401
                base_input[energy_category_id]['subtotal_in_kgce'] = Decimal(0.0)
402
                base_input[energy_category_id]['subtotal_in_kgco2e'] = Decimal(0.0)
403
404
                cursor_energy.execute(" SELECT SUM(actual_value) "
405
                                      " FROM tbl_space_input_category_hourly "
406
                                      " WHERE space_id = %s "
407
                                      "     AND energy_category_id = %s "
408
                                      "     AND start_datetime_utc >= %s "
409
                                      "     AND start_datetime_utc < %s ",
410
                                      (space['id'],
411
                                       energy_category_id,
412
                                       base_start_datetime_utc,
413
                                       base_end_datetime_utc))
414
                row_space_sum = cursor_energy.fetchone()
415
                if row_space_sum is None or len(row_space_sum) < 1 or row_space_sum[0] is None:
416
                    actual_value = Decimal(0.0)
417
                else:
418
                    actual_value = row_space_sum[0]
419
                base_input[energy_category_id]['subtotal'] = actual_value
420
                base_input[energy_category_id]['subtotal_in_kgce'] = actual_value * kgce
421
                base_input[energy_category_id]['subtotal_in_kgco2e'] = actual_value * kgco2e
422
423
        ################################################################################################################
424
        # Step 7: query base period energy cost