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