@@ 509-531 (lines=23) @@ | ||
506 | ################################################################################################################ |
|
507 | child_space_data = dict() |
|
508 | ||
509 | if energy_category_set is not None and len(energy_category_set) > 0: |
|
510 | for energy_category_id in energy_category_set: |
|
511 | child_space_data[energy_category_id] = dict() |
|
512 | child_space_data[energy_category_id]['child_space_names'] = list() |
|
513 | child_space_data[energy_category_id]['subtotals'] = list() |
|
514 | for child_space in child_space_list: |
|
515 | child_space_data[energy_category_id]['child_space_names'].append(child_space['name']) |
|
516 | ||
517 | cursor_energy.execute(" SELECT SUM(actual_value) " |
|
518 | " FROM tbl_space_output_category_hourly " |
|
519 | " WHERE space_id = %s " |
|
520 | " AND energy_category_id = %s " |
|
521 | " AND start_datetime_utc >= %s " |
|
522 | " AND start_datetime_utc < %s ", |
|
523 | (child_space['id'], |
|
524 | energy_category_id, |
|
525 | reporting_start_datetime_utc, |
|
526 | reporting_end_datetime_utc)) |
|
527 | row_subtotal = cursor_energy.fetchone() |
|
528 | ||
529 | subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0] |
|
530 | child_space_data[energy_category_id]['subtotals'].append(subtotal) |
|
531 | ||
532 | ################################################################################################################ |
|
533 | # Step 12: construct the report |
|
534 | ################################################################################################################ |
@@ 536-559 (lines=24) @@ | ||
533 | ################################################################################################################ |
|
534 | child_space_data = dict() |
|
535 | ||
536 | if energy_item_set is not None and len(energy_item_set) > 0: |
|
537 | for energy_item_id in energy_item_set: |
|
538 | child_space_data[energy_item_id] = dict() |
|
539 | child_space_data[energy_item_id]['child_space_names'] = list() |
|
540 | child_space_data[energy_item_id]['subtotals'] = list() |
|
541 | ||
542 | for child_space in child_space_list: |
|
543 | child_space_data[energy_item_id]['child_space_names'].append(child_space['name']) |
|
544 | ||
545 | cursor_energy.execute(" SELECT SUM(actual_value) " |
|
546 | " FROM tbl_space_input_item_hourly " |
|
547 | " WHERE space_id = %s " |
|
548 | " AND energy_item_id = %s " |
|
549 | " AND start_datetime_utc >= %s " |
|
550 | " AND start_datetime_utc < %s ", |
|
551 | (child_space['id'], |
|
552 | energy_item_id, |
|
553 | reporting_start_datetime_utc, |
|
554 | reporting_end_datetime_utc)) |
|
555 | row_subtotal = cursor_energy.fetchone() |
|
556 | ||
557 | subtotal = Decimal(0.0) if (row_subtotal is None or row_subtotal[0] is None) else row_subtotal[0] |
|
558 | child_space_data[energy_item_id]['subtotals'].append(subtotal) |
|
559 | ||
560 | ################################################################################################################ |
|
561 | # Step 12: construct the report |
|
562 | ################################################################################################################ |