added associated equipment data to combinedequipmentload report in API

pull/26/head
13621160019@163.com 2021-03-31 14:34:27 +08:00
parent a24a6ddd09
commit 32eb0441cb
3 changed files with 175 additions and 10 deletions

View File

@ -154,7 +154,7 @@ def generate_excel(report,
return filename
#################################################
# First: 统计分析
# First: 负荷分析
# 6: title
# 7: table title
# 8~2*ca_len table_data
@ -175,7 +175,7 @@ def generate_excel(report,
if has_energy_data_flag:
ws['B6'].font = title_font
ws['B6'] = name + ' 统计分析'
ws['B6'] = name + ' 负荷分析'
category = reporting_period_data['names']
@ -357,6 +357,84 @@ def generate_excel(report,
chart_cell = str(analysis_end_row_number + 6 * i)
ws.add_chart(line, chart_col + chart_cell)
#####################################
has_associated_equipment_flag = True
current_row_number = detailed_start_row_number + 3 + time_len
if "associated_equipment" not in report.keys() or \
"energy_category_names" not in report['associated_equipment'].keys() or \
len(report['associated_equipment']["energy_category_names"]) == 0 \
or 'associated_equipment_names_array' not in report['associated_equipment'].keys() \
or report['associated_equipment']['associated_equipment_names_array'] is None \
or len(report['associated_equipment']['associated_equipment_names_array']) == 0 \
or len(report['associated_equipment']['associated_equipment_names_array'][0]) == 0:
has_associated_equipment_flag = False
if has_associated_equipment_flag:
associated_equipment = report['associated_equipment']
ws['B' + str(current_row_number)].font = title_font
ws['B' + str(current_row_number)] = name + ' 相关设备数据'
current_row_number += 1
table_start_row_number = current_row_number
ws.row_dimensions[current_row_number].height = 60
ws['B' + str(current_row_number)].fill = table_fill
ws['B' + str(current_row_number)].font = name_font
ws['B' + str(current_row_number)].alignment = c_c_alignment
ws['B' + str(current_row_number)].border = f_border
ws['B' + str(current_row_number)] = '相关设备'
ca_len = len(associated_equipment['energy_category_names'])
for i in range(0, ca_len):
col_average = chr(ord('C') + 2 * i)
col_maximum = chr(ord('D') + 2 * i)
ws[col_average + str(current_row_number)].font = name_font
ws[col_average + str(current_row_number)].alignment = c_c_alignment
ws[col_average + str(current_row_number)] = names[i] + " 平均负荷(" + \
reporting_period_data['units'][i] + "/H)"
ws[col_average + str(current_row_number)].border = f_border
ws[col_maximum + str(current_row_number)].font = name_font
ws[col_maximum + str(current_row_number)].alignment = c_c_alignment
ws[col_maximum + str(current_row_number)] = names[i] + " 最大负荷(" + \
reporting_period_data['units'][i] + "/H)"
ws[col_maximum + str(current_row_number)].border = f_border
associated_equipment_len = len(associated_equipment['associated_equipment_names_array'][0])
# table_date
for j in range(0, associated_equipment_len):
current_row_number += 1
rows = str(current_row_number)
ws['B' + rows].font = title_font
ws['B' + rows].alignment = c_c_alignment
ws['B' + rows] = associated_equipment['associated_equipment_names_array'][0][j]
ws['B' + rows].border = f_border
for index in range(0, ca_len):
col_average = chr(ord('C') + 2 * index)
col_maximum = chr(ord('D') + 2 * index)
ws[col_average + str(rows)].font = name_font
ws[col_average + str(rows)].alignment = c_c_alignment
ws[col_average + str(rows)] = associated_equipment['sub_averages_array'][index][j] \
if associated_equipment['sub_averages_array'][index][j] is not None else ''
ws[col_average + str(rows)].number_format = '0.00'
ws[col_average + str(rows)].border = f_border
ws[col_maximum + str(rows)].font = name_font
ws[col_maximum + str(rows)].alignment = c_c_alignment
ws[col_maximum + str(rows)] = associated_equipment['sub_maximums_array'][index][j] \
if associated_equipment['sub_maximums_array'][index][j] is not None else ''
ws[col_maximum + str(rows)].number_format = '0.00'
ws[col_maximum + str(rows)].border = f_border
filename = str(uuid.uuid4()) + '.xlsx'
wb.save(filename)

View File

@ -23,11 +23,13 @@ class Reporting:
# Step 2: query the combined equipment
# Step 3: query energy categories
# Step 4: query associated points
# Step 5: query base period energy input
# Step 6: query reporting period energy input
# Step 7: query tariff data
# Step 8: query associated points data
# Step 9: construct the report
# Step 5: query associated equipments
# Step 6: query base period energy input
# Step 7: query reporting period energy input
# Step 8: query tariff data
# Step 9: query associated points data
# Step 10: query associated equipments energy input
# Step 11: construct the report
####################################################################################################################
@staticmethod
def on_get(req, resp):
@ -234,6 +236,19 @@ class Reporting:
for row in rows_points:
point_list.append({"id": row[0], "name": row[1], "units": row[2], "object_type": row[3]})
################################################################################################################
# Step 5: query associated equipments
################################################################################################################
associated_equipment_list = list()
cursor_system.execute(" SELECT e.id, e.name "
" FROM tbl_equipments e,tbl_combined_equipments_equipments ee"
" WHERE ee.combined_equipment_id = %s AND e.id = ee.equipment_id"
" ORDER BY id ", (combined_equipment['id'],))
rows_associated_equipments = cursor_system.fetchall()
if rows_associated_equipments is not None and len(rows_associated_equipments) > 0:
for row in rows_associated_equipments:
associated_equipment_list.append({"id": row[0], "name": row[1]})
################################################################################################################
# Step 6: query base period energy input
################################################################################################################
@ -440,7 +455,50 @@ class Reporting:
parameters_data['values'].append(point_values)
################################################################################################################
# Step 10: construct the report
# Step 10: query associated equipments energy input
################################################################################################################
associated_equipment_data = dict()
if energy_category_set is not None and len(energy_category_set) > 0:
for energy_category_id in energy_category_set:
associated_equipment_data[energy_category_id] = dict()
associated_equipment_data[energy_category_id]['associated_equipment_names'] = list()
associated_equipment_data[energy_category_id]['average'] = list()
associated_equipment_data[energy_category_id]['maximum'] = list()
associated_equipment_data[energy_category_id]['sub_averages'] = list()
associated_equipment_data[energy_category_id]['sub_maximums'] = list()
for associated_equipment in associated_equipment_list:
associated_equipment_data[energy_category_id]['associated_equipment_names'].append(
associated_equipment['name'])
cursor_energy.execute(" SELECT start_datetime_utc, actual_value "
" FROM tbl_equipment_input_category_hourly "
" WHERE equipment_id = %s "
" AND energy_category_id = %s "
" AND start_datetime_utc >= %s "
" AND start_datetime_utc < %s "
" ORDER BY start_datetime_utc ",
(associated_equipment['id'],
energy_category_id,
reporting_start_datetime_utc,
reporting_end_datetime_utc))
rows_associated_equipments_hourly = cursor_energy.fetchall()
rows_associated_equipment_periodically, \
associated_equipment_data[energy_category_id]['average'], \
associated_equipment_data[energy_category_id]['maximum'] = \
utilities.averaging_hourly_data_by_period(rows_associated_equipments_hourly,
reporting_start_datetime_utc,
reporting_end_datetime_utc,
period_type)
associated_equipment_data[energy_category_id]['sub_averages'].append(
associated_equipment_data[energy_category_id]['average'])
associated_equipment_data[energy_category_id]['sub_maximums'].append(
associated_equipment_data[energy_category_id]['maximum'])
################################################################################################################
# Step 11: construct the report
################################################################################################################
if cursor_system:
cursor_system.close()
@ -532,6 +590,25 @@ class Reporting:
"values": parameters_data['values']
}
result['associated_equipment'] = dict()
result['associated_equipment']['energy_category_names'] = list()
result['associated_equipment']['units'] = list()
result['associated_equipment']['associated_equipment_names_array'] = list()
result['associated_equipment']['sub_averages_array'] = list()
result['associated_equipment']['sub_maximums_array'] = list()
if energy_category_set is not None and len(energy_category_set) > 0:
for energy_category_id in energy_category_set:
result['associated_equipment']['energy_category_names'].append(
energy_category_dict[energy_category_id]['name'])
result['associated_equipment']['units'].append(
energy_category_dict[energy_category_id]['unit_of_measure'])
result['associated_equipment']['associated_equipment_names_array'].append(
associated_equipment_data[energy_category_id]['associated_equipment_names'])
result['associated_equipment']['sub_averages_array'].append(
associated_equipment_data[energy_category_id]['sub_averages'])
result['associated_equipment']['sub_maximums_array'].append(
associated_equipment_data[energy_category_id]['sub_maximums'])
# export result to Excel file and then encode the file to base64 string
result['excel_bytes_base64'] = excelexporters.combinedequipmentload.export(result,
combined_equipment['name'],

View File

@ -424,6 +424,7 @@ const CombinedEquipmentLoad = ({ setRedirect, setRedirectUrl, t }) => {
});
});
setDetailedDataTableColumns(detailed_column_list);
let associated_equipment_value_list = [];
if (json['associated_equipment']['associated_equipment_names_array'].length > 0) {
json['associated_equipment']['associated_equipment_names_array'][0].forEach((currentEquipmentName, equipmentIndex) => {
@ -431,8 +432,17 @@ const CombinedEquipmentLoad = ({ setRedirect, setRedirectUrl, t }) => {
associated_equipment_value['id'] = equipmentIndex;
associated_equipment_value['name'] = currentEquipmentName;
json['associated_equipment']['energy_category_names'].forEach((currentValue, energyCategoryIndex) => {
associated_equipment_value['a' + 2 * energyCategoryIndex] = json['associated_equipment']['sub_averages'][energyCategoryIndex][equipmentIndex].toFixed(2);
associated_equipment_value['a' + 2 * energyCategoryIndex + 1] = json['associated_equipment']['sub_maximums'][energyCategoryIndex][equipmentIndex].toFixed(2);
if (json['associated_equipment']['sub_averages_array'][energyCategoryIndex][equipmentIndex] != null) {
associated_equipment_value['a' + 2 * energyCategoryIndex] = json['associated_equipment']['sub_averages_array'][energyCategoryIndex][equipmentIndex].toFixed(2);
} else {
associated_equipment_value['a' + 2 * energyCategoryIndex] = '';
};
if (json['associated_equipment']['sub_maximums_array'][energyCategoryIndex][equipmentIndex] != null) {
associated_equipment_value['a' + (2 * energyCategoryIndex + 1)] = json['associated_equipment']['sub_maximums_array'][energyCategoryIndex][equipmentIndex].toFixed(2);
} else {
associated_equipment_value['a' + (2 * energyCategoryIndex + 1)] = '';
};
});
associated_equipment_value_list.push(associated_equipment_value);
});