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