added maximum load data
parent
8bde969c4e
commit
2d91cecec9
|
@ -1,8 +1,11 @@
|
|||
import base64
|
||||
import uuid
|
||||
import os
|
||||
|
||||
|
||||
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
|
||||
from openpyxl.drawing.image import Image
|
||||
from openpyxl.utils import column_index_from_string, get_column_letter
|
||||
from openpyxl import Workbook
|
||||
|
||||
|
||||
|
@ -129,30 +132,38 @@ def generate_excel(report, space_name, reporting_start_datetime_local, reporting
|
|||
ws['C5'] = reporting_end_datetime_local
|
||||
|
||||
# Title
|
||||
ws['B6'].border = f_border
|
||||
ws['B6'].font = name_font
|
||||
ws['B6'].alignment = c_c_alignment
|
||||
ws['B6'].fill = table_fill
|
||||
ws['B6'] = 'Name'
|
||||
ws['B7'].border = f_border
|
||||
ws['B7'].font = name_font
|
||||
ws['B7'].alignment = c_c_alignment
|
||||
ws['B7'].fill = table_fill
|
||||
ws['B7'] = 'Name'
|
||||
|
||||
ws['C6'].border = f_border
|
||||
ws['C6'].alignment = c_c_alignment
|
||||
ws['C6'].font = name_font
|
||||
ws['C6'].fill = table_fill
|
||||
ws['C6'] = 'Space'
|
||||
ws['C7'].border = f_border
|
||||
ws['C7'].alignment = c_c_alignment
|
||||
ws['C7'].font = name_font
|
||||
ws['C7'].fill = table_fill
|
||||
ws['C7'] = 'Space'
|
||||
|
||||
ca_len = len(report['energycategories'])
|
||||
|
||||
for i in range(0, ca_len):
|
||||
col = chr(ord('D') + i)
|
||||
ws[col + '6'].fill = table_fill
|
||||
ws[col + '6'].font = name_font
|
||||
ws[col + '6'].alignment = c_c_alignment
|
||||
ws[col + '6'] = report['energycategories'][i]['name'] + \
|
||||
col = get_column_letter(column_index_from_string('D') + i * 2)
|
||||
ws[col + '7'].fill = table_fill
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = report['energycategories'][i]['name'] + \
|
||||
" (" + report['energycategories'][i]['unit_of_measure'] + ")"
|
||||
ws[col + '6'].border = f_border
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
current_row_number = 7
|
||||
col = get_column_letter(column_index_from_string(col) + 1)
|
||||
ws[col + '7'].fill = table_fill
|
||||
ws[col + '7'].font = name_font
|
||||
ws[col + '7'].alignment = c_c_alignment
|
||||
ws[col + '7'] = report['energycategories'][i]['name'] + \
|
||||
" Maximum Load (" + report['energycategories'][i]['unit_of_measure'] + ")"
|
||||
ws[col + '7'].border = f_border
|
||||
|
||||
current_row_number = 8
|
||||
for i in range(0, len(report['tenants'])):
|
||||
|
||||
ws['B' + str(current_row_number)].font = title_font
|
||||
|
@ -167,12 +178,17 @@ def generate_excel(report, space_name, reporting_start_datetime_local, reporting
|
|||
|
||||
ca_len = len(report['tenants'][i]['values'])
|
||||
for j in range(0, ca_len):
|
||||
col = chr(ord('D') + j)
|
||||
ws[col + str(current_row_number)].font = data_font
|
||||
col = get_column_letter(column_index_from_string('D') + j * 2)
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)] = report['tenants'][i]['values'][j]
|
||||
|
||||
col = get_column_letter(column_index_from_string(col) + 1)
|
||||
ws[col + str(current_row_number)].font = title_font
|
||||
ws[col + str(current_row_number)].border = f_border
|
||||
ws[col + str(current_row_number)].alignment = c_c_alignment
|
||||
ws[col + str(current_row_number)] = report['tenants'][i]['maximum'][j]
|
||||
current_row_number += 1
|
||||
|
||||
filename = str(uuid.uuid4()) + '.xlsx'
|
||||
|
|
|
@ -137,7 +137,8 @@ class Reporting:
|
|||
"space_name": row['space_name'],
|
||||
"cost_center_name": row['cost_center_name'],
|
||||
"description": row['description'],
|
||||
"values": list()}
|
||||
"values": list(),
|
||||
"maximum": list()}
|
||||
|
||||
################################################################################################################
|
||||
# Step 4: query energy categories
|
||||
|
@ -187,7 +188,7 @@ class Reporting:
|
|||
################################################################################################################
|
||||
for tenant_id in tenant_dict:
|
||||
|
||||
cursor_energy_db.execute(" SELECT energy_category_id, SUM(actual_value) "
|
||||
cursor_energy_db.execute(" SELECT energy_category_id, SUM(actual_value), max(actual_value)"
|
||||
" FROM tbl_tenant_input_category_hourly "
|
||||
" WHERE tenant_id = %s "
|
||||
" AND start_datetime_utc >= %s "
|
||||
|
@ -199,11 +200,14 @@ class Reporting:
|
|||
rows_tenant_energy = cursor_energy_db.fetchall()
|
||||
for energy_category in energy_category_list:
|
||||
subtotal = Decimal(0.0)
|
||||
maximum = Decimal(0.0)
|
||||
for row_tenant_energy in rows_tenant_energy:
|
||||
if energy_category['id'] == row_tenant_energy[0]:
|
||||
subtotal = row_tenant_energy[1]
|
||||
maximum = row_tenant_energy[2]
|
||||
break
|
||||
tenant_dict[tenant_id]['values'].append(subtotal)
|
||||
tenant_dict[tenant_id]['maximum'].append(maximum)
|
||||
|
||||
if cursor_system_db:
|
||||
cursor_system_db.close()
|
||||
|
@ -227,6 +231,7 @@ class Reporting:
|
|||
"cost_center_name": tenant['cost_center_name'],
|
||||
"description": tenant['description'],
|
||||
"values": tenant['values'],
|
||||
"maximum": tenant['maximum'],
|
||||
})
|
||||
|
||||
result = {'tenants': tenant_list,
|
||||
|
|
|
@ -179,7 +179,10 @@ const TenantBatch = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
detailed_value['space'] = currentTenant['space_name'];
|
||||
detailed_value['costcenter'] = currentTenant['cost_center_name'];
|
||||
currentTenant['values'].forEach((currentValue, energyCategoryIndex) => {
|
||||
detailed_value['a' + energyCategoryIndex] = currentValue.toFixed(2);
|
||||
detailed_value['a' + 2 * energyCategoryIndex] = currentValue.toFixed(2);
|
||||
});
|
||||
currentTenant['maximum'].forEach((currentValue, energyCategoryIndex) => {
|
||||
detailed_value['a' + (2 * energyCategoryIndex + 1)] = currentValue.toFixed(2);
|
||||
});
|
||||
tenants.push(detailed_value);
|
||||
});
|
||||
|
@ -200,13 +203,18 @@ const TenantBatch = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
});
|
||||
json['energycategories'].forEach((currentValue, index) => {
|
||||
detailed_column_list.push({
|
||||
dataField: 'a' + index,
|
||||
dataField: 'a' + 2 * index,
|
||||
text: currentValue['name'] + ' (' + currentValue['unit_of_measure'] + ')',
|
||||
sort: true
|
||||
},{
|
||||
dataField: 'a' + (2 * index + 1),
|
||||
text: currentValue['name'] + ' ' + t('Maximum Load') + ' (' + currentValue['unit_of_measure'] + ')',
|
||||
sort: true
|
||||
})
|
||||
});
|
||||
setDetailedDataTableColumns(detailed_column_list);
|
||||
|
||||
setDetailedDataTableColumns(detailed_column_list);
|
||||
console.log(detailed_column_list);
|
||||
setExcelBytesBase64(json['excel_bytes_base64']);
|
||||
|
||||
// enable submit button
|
||||
|
|
Loading…
Reference in New Issue