Merge branch 'develop'

pull/142/MERGE
13621160019@163.com 2022-04-13 16:37:37 +08:00
commit 847729068c
11 changed files with 154 additions and 155 deletions

View File

@ -71,7 +71,7 @@ class AdvancedReportCollection:
################################################################################################################ ################################################################################################################
cnx_reporting = mysql.connector.connect(**config.myems_reporting_db) cnx_reporting = mysql.connector.connect(**config.myems_reporting_db)
cursor_reporting = cnx_reporting.cursor(dictionary=True) cursor_reporting = cnx_reporting.cursor()
query = (" SELECT id, file_name, uuid, create_datetime_utc, file_type, file_object " query = (" SELECT id, file_name, uuid, create_datetime_utc, file_type, file_object "
" FROM tbl_reports_files " " FROM tbl_reports_files "
@ -91,17 +91,17 @@ class AdvancedReportCollection:
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
# Base64 encode the bytes # Base64 encode the bytes
base64_encoded_data = base64.b64encode(row['file_object']) base64_encoded_data = base64.b64encode(row[5])
# get the Base64 encoded data using human-readable characters. # get the Base64 encoded data using human-readable characters.
base64_message = base64_encoded_data.decode('utf-8') base64_message = base64_encoded_data.decode('utf-8')
create_datetime_local = row['create_datetime_utc'].replace(tzinfo=None) + \ create_datetime_local = row[3].replace(tzinfo=None) + \
timedelta(minutes=timezone_offset) timedelta(minutes=timezone_offset)
meta_result = {"id": row['id'], meta_result = {"id": row[0],
"file_name": row['file_name'], "file_name": row[1],
"uuid": row['uuid'], "uuid": row[2],
"create_datetime_local": create_datetime_local.isoformat(), "create_datetime_local": create_datetime_local.isoformat(),
"file_type": row['file_type'], "file_type": row[4],
"file_size_bytes": sys.getsizeof(row['file_object']), "file_size_bytes": sys.getsizeof(row[5]),
"file_bytes_base64": base64_message} "file_bytes_base64": base64_message}
result.append(meta_result) result.append(meta_result)
@ -126,7 +126,7 @@ class AdvancedReportItem:
description='API.INVALID_ADVANCED_REPORT_ID') description='API.INVALID_ADVANCED_REPORT_ID')
cnx_reporting = mysql.connector.connect(**config.myems_reporting_db) cnx_reporting = mysql.connector.connect(**config.myems_reporting_db)
cursor_reporting = cnx_reporting.cursor(dictionary=True) cursor_reporting = cnx_reporting.cursor()
query = (" SELECT id, file_name, uuid, create_datetime_utc, file_type, file_object " query = (" SELECT id, file_name, uuid, create_datetime_utc, file_type, file_object "
" FROM tbl_reports_files " " FROM tbl_reports_files "
@ -144,16 +144,15 @@ class AdvancedReportItem:
description='API.ADVANCED_REPORT_NOT_FOUND') description='API.ADVANCED_REPORT_NOT_FOUND')
# Base64 encode the bytes # Base64 encode the bytes
base64_encoded_data = base64.b64encode(row['file_object']) base64_encoded_data = base64.b64encode(row[5])
# get the Base64 encoded data using human-readable characters. # get the Base64 encoded data using human-readable characters.
base64_message = base64_encoded_data.decode('utf-8') base64_message = base64_encoded_data.decode('utf-8')
result = {"id": row['id'], result = {"id": row[0],
"file_name": row['file_name'], "file_name": row[1],
"uuid": row['uuid'], "uuid": row[2],
"create_datetime": "create_datetime": row[3].replace(tzinfo=timezone.utc).timestamp() * 1000,
row['create_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000, "file_type": row[4],
"file_type": row['file_type'],
"file_bytes_base64": base64_message} "file_bytes_base64": base64_message}
resp.text = json.dumps(result) resp.text = json.dumps(result)
@ -165,7 +164,7 @@ class AdvancedReportItem:
description='API.INVALID_ADVANCED_REPORT_ID') description='API.INVALID_ADVANCED_REPORT_ID')
cnx_reporting = mysql.connector.connect(**config.myems_reporting_db) cnx_reporting = mysql.connector.connect(**config.myems_reporting_db)
cursor_reporting = cnx_reporting.cursor(dictionary=True) cursor_reporting = cnx_reporting.cursor()
cursor_reporting.execute(" SELECT id " cursor_reporting.execute(" SELECT id "
" FROM tbl_reports_files " " FROM tbl_reports_files "

View File

@ -83,7 +83,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -98,7 +98,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -112,8 +112,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all combined equipments in the space tree # Step 3: query all combined equipments in the space tree
@ -134,11 +134,11 @@ class Reporting:
rows_combined_equipments = cursor_system_db.fetchall() rows_combined_equipments = cursor_system_db.fetchall()
if rows_combined_equipments is not None and len(rows_combined_equipments) > 0: if rows_combined_equipments is not None and len(rows_combined_equipments) > 0:
for row in rows_combined_equipments: for row in rows_combined_equipments:
combined_equipment_dict[row['id']] = {"combined_equipment_name": row['combined_equipment_name'], combined_equipment_dict[row[0]] = {"combined_equipment_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description'], "description": row[4],
"values": list()} "values": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -178,10 +178,10 @@ class Reporting:
description='API.ENERGY_CATEGORY_NOT_FOUND') description='API.ENERGY_CATEGORY_NOT_FOUND')
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category[0] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input

View File

@ -48,7 +48,7 @@ class Reporting:
# Step 2: Step 2: query the distribution system # Step 2: Step 2: query the distribution system
################################################################################################################ ################################################################################################################
cnx_system = mysql.connector.connect(**config.myems_system_db) cnx_system = mysql.connector.connect(**config.myems_system_db)
cursor_system = cnx_system.cursor(dictionary=True) cursor_system = cnx_system.cursor()
cursor_system.execute(" SELECT name " cursor_system.execute(" SELECT name "
" FROM tbl_distribution_systems " " FROM tbl_distribution_systems "
@ -75,10 +75,10 @@ class Reporting:
circuit_list = list() circuit_list = list()
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
circuit_list.append({"id": row['id'], "name": row['name'], "uuid": row['uuid'], circuit_list.append({"id": row[0], "name": row[1], "uuid": row[2],
"distribution_room": row['distribution_room'], "switchgear": row['switchgear'], "distribution_room": row[3], "switchgear": row[4],
"peak_load": row['peak_load'], "peak_current": row['peak_current'], "peak_load": row[5], "peak_current": row[6],
"customers": row['customers'], "meters": row['meters'], "customers": row[7], "meters": row[8],
"points": list()}) "points": list()})
################################################################################################################ ################################################################################################################
@ -95,10 +95,10 @@ class Reporting:
if rows is not None and len(rows) > 0: if rows is not None and len(rows) > 0:
for row in rows: for row in rows:
circuit_list[x]['points'].append({"id": row['id'], circuit_list[x]['points'].append({"id": row[0],
"name": row['name'], "name": row[1],
"object_type": row['object_type'], "object_type": row[2],
"units": row['units'], "units": row[3],
"value": None}) "value": None})
if cursor_system: if cursor_system:
cursor_system.close() cursor_system.close()

View File

@ -87,7 +87,7 @@ class Reporting:
################################################################################################################ ################################################################################################################
cnx_system = mysql.connector.connect(**config.myems_system_db) cnx_system = mysql.connector.connect(**config.myems_system_db)
cursor_system = cnx_system.cursor(dictionary=True) cursor_system = cnx_system.cursor()
query = (" SELECT name, uuid " query = (" SELECT name, uuid "
" FROM tbl_energy_flow_diagrams " " FROM tbl_energy_flow_diagrams "
@ -103,8 +103,8 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND')
else: else:
energy_flow_diagram_name = row['name'] energy_flow_diagram_name = row[0]
energy_flow_diagram_uuid = row['uuid'] energy_flow_diagram_uuid = row[1]
################################################################################################################ ################################################################################################################
# Step 3: query nodes # Step 3: query nodes
@ -119,10 +119,10 @@ class Reporting:
node_list_dict = dict() node_list_dict = dict()
if rows_nodes is not None and len(rows_nodes) > 0: if rows_nodes is not None and len(rows_nodes) > 0:
for row in rows_nodes: for row in rows_nodes:
node_dict[row['id']] = row['name'] node_dict[row[0]] = row[2]
if node_list_dict.get(row['energy_flow_diagram_id']) is None: if node_list_dict.get(row[1]) is None:
node_list_dict[row['energy_flow_diagram_id']] = list() node_list_dict[row[1]] = list()
node_list_dict[row['energy_flow_diagram_id']].append({"id": row['id'], "name": row['name']}) node_list_dict[row[1]].append({"id": row[0], "name": row[2]})
################################################################################################################ ################################################################################################################
# Step 4: query links # Step 4: query links
@ -135,10 +135,10 @@ class Reporting:
meter_dict = dict() meter_dict = dict()
if rows_meters is not None and len(rows_meters) > 0: if rows_meters is not None and len(rows_meters) > 0:
for row in rows_meters: for row in rows_meters:
meter_dict[row['uuid']] = {"type": 'meter', meter_dict[row[2]] = {"type": 'meter',
"id": row['id'], "id": row[0],
"name": row['name'], "name": row[1],
"uuid": row['uuid']} "uuid": row[2]}
query = (" SELECT id, name, uuid " query = (" SELECT id, name, uuid "
" FROM tbl_offline_meters ") " FROM tbl_offline_meters ")
@ -148,10 +148,10 @@ class Reporting:
offline_meter_dict = dict() offline_meter_dict = dict()
if rows_offline_meters is not None and len(rows_offline_meters) > 0: if rows_offline_meters is not None and len(rows_offline_meters) > 0:
for row in rows_offline_meters: for row in rows_offline_meters:
offline_meter_dict[row['uuid']] = {"type": 'offline_meter', offline_meter_dict[row[2]] = {"type": 'offline_meter',
"id": row['id'], "id": row[0],
"name": row['name'], "name": row[1],
"uuid": row['uuid']} "uuid": row[2]}
query = (" SELECT id, name, uuid " query = (" SELECT id, name, uuid "
" FROM tbl_virtual_meters ") " FROM tbl_virtual_meters ")
@ -161,10 +161,10 @@ class Reporting:
virtual_meter_dict = dict() virtual_meter_dict = dict()
if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: if rows_virtual_meters is not None and len(rows_virtual_meters) > 0:
for row in rows_virtual_meters: for row in rows_virtual_meters:
virtual_meter_dict[row['uuid']] = {"type": 'virtual_meter', virtual_meter_dict[row[2]] = {"type": 'virtual_meter',
"id": row['id'], "id": row[0],
"name": row['name'], "name": row[1],
"uuid": row['uuid']} "uuid": row[2]}
query = (" SELECT id, energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid " query = (" SELECT id, energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid "
" FROM tbl_energy_flow_diagrams_links") " FROM tbl_energy_flow_diagrams_links")
@ -175,23 +175,23 @@ class Reporting:
if rows_links is not None and len(rows_links) > 0: if rows_links is not None and len(rows_links) > 0:
for row in rows_links: for row in rows_links:
# find meter by uuid # find meter by uuid
meter = meter_dict.get(row['meter_uuid'], None) meter = meter_dict.get(row[4], None)
if meter is None: if meter is None:
meter = virtual_meter_dict.get(row['meter_uuid'], None) meter = virtual_meter_dict.get(row[4], None)
if meter is None: if meter is None:
meter = offline_meter_dict.get(row['meter_uuid'], None) meter = offline_meter_dict.get(row[4], None)
if link_list_dict.get(row['energy_flow_diagram_id']) is None: if link_list_dict.get(row[1]) is None:
link_list_dict[row['energy_flow_diagram_id']] = list() link_list_dict[row[1]] = list()
link_list_dict[row['energy_flow_diagram_id']].append({"id": row['id'], link_list_dict[row[1]].append({"id": row[0],
"source_node": { "source_node": {
"id": row['source_node_id'], "id": row[2],
"name": node_dict.get(row['source_node_id'])}, "name": node_dict.get(row[2])},
"target_node": { "target_node": {
"id": row['target_node_id'], "id": row[3],
"name": node_dict.get(row['target_node_id'])}, "name": node_dict.get(row[3])},
"meter": meter, "meter": meter,
"value": None}) "value": None})
meta_result = {"id": energy_flow_diagram_id, meta_result = {"id": energy_flow_diagram_id,
"name": energy_flow_diagram_name, "name": energy_flow_diagram_name,

View File

@ -83,7 +83,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -98,7 +98,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -112,8 +112,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all equipments in the space tree # Step 3: query all equipments in the space tree
@ -134,11 +134,11 @@ class Reporting:
rows_equipments = cursor_system_db.fetchall() rows_equipments = cursor_system_db.fetchall()
if rows_equipments is not None and len(rows_equipments) > 0: if rows_equipments is not None and len(rows_equipments) > 0:
for row in rows_equipments: for row in rows_equipments:
equipment_dict[row['id']] = {"equipment_name": row['equipment_name'], equipment_dict[row[0]] = {"equipment_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description'], "description": row[4],
"values": list()} "values": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -178,10 +178,10 @@ class Reporting:
description='API.ENERGY_CATEGORY_NOT_FOUND') description='API.ENERGY_CATEGORY_NOT_FOUND')
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category[0] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input

View File

@ -41,7 +41,7 @@ class Reporting:
space_id = int(space_id) space_id = int(space_id)
cnx = mysql.connector.connect(**config.myems_system_db) cnx = mysql.connector.connect(**config.myems_system_db)
cursor = cnx.cursor(dictionary=True) cursor = cnx.cursor()
cursor.execute(" SELECT name " cursor.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -56,7 +56,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
################################################################################################################ ################################################################################################################
@ -69,8 +69,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all equipments in the space tree # Step 3: query all equipments in the space tree
@ -91,11 +91,11 @@ class Reporting:
rows_equipments = cursor.fetchall() rows_equipments = cursor.fetchall()
if rows_equipments is not None and len(rows_equipments) > 0: if rows_equipments is not None and len(rows_equipments) > 0:
for row in rows_equipments: for row in rows_equipments:
equipment_list.append({"id": row['id'], equipment_list.append({"id": row[0],
"equipment_name": row['equipment_name'], "equipment_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description']}) "description": row[4]})
if cursor: if cursor:
cursor.close() cursor.close()

View File

@ -82,7 +82,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -97,7 +97,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -111,8 +111,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all meters in the space tree # Step 3: query all meters in the space tree
@ -134,11 +134,11 @@ class Reporting:
rows_meters = cursor_system_db.fetchall() rows_meters = cursor_system_db.fetchall()
if rows_meters is not None and len(rows_meters) > 0: if rows_meters is not None and len(rows_meters) > 0:
for row in rows_meters: for row in rows_meters:
meter_dict[row['id']] = {"meter_name": row['meter_name'], meter_dict[row[0]] = {"meter_name": row[1],
"energy_category_id": row['energy_category_id'], "energy_category_id": row[2],
"space_name": row['space_name'], "space_name": row[3],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[4],
"values": list()} "values": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -174,10 +174,10 @@ class Reporting:
description='API.ENERGY_CATEGORY_NOT_FOUND') description='API.ENERGY_CATEGORY_NOT_FOUND')
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category[0] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input

View File

@ -85,7 +85,7 @@ class Reporting:
description='API.THE_REPORTING_PERIOD_MUST_BE_LONGER_THAN_15_MINUTES') description='API.THE_REPORTING_PERIOD_MUST_BE_LONGER_THAN_15_MINUTES')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cnx_historical = mysql.connector.connect(**config.myems_historical_db) cnx_historical = mysql.connector.connect(**config.myems_historical_db)
cursor_historical = cnx_historical.cursor() cursor_historical = cnx_historical.cursor()
@ -103,7 +103,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -117,8 +117,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all meters in the space tree # Step 3: query all meters in the space tree
@ -140,11 +140,11 @@ class Reporting:
rows_meters = cursor_system_db.fetchall() rows_meters = cursor_system_db.fetchall()
if rows_meters is not None and len(rows_meters) > 0: if rows_meters is not None and len(rows_meters) > 0:
for row in rows_meters: for row in rows_meters:
meter_dict[row['id']] = {"meter_name": row['meter_name'], meter_dict[row[0]] = {"meter_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"energy_category_name": row['energy_category_name'], "energy_category_name": row[4],
"description": row['description']} "description": row[5]}
################################################################################################################ ################################################################################################################
# Step 4: query start value and end value # Step 4: query start value and end value

View File

@ -83,7 +83,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -98,7 +98,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -112,8 +112,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all shopfloors in the space tree # Step 3: query all shopfloors in the space tree
@ -134,11 +134,11 @@ class Reporting:
rows_shopfloors = cursor_system_db.fetchall() rows_shopfloors = cursor_system_db.fetchall()
if rows_shopfloors is not None and len(rows_shopfloors) > 0: if rows_shopfloors is not None and len(rows_shopfloors) > 0:
for row in rows_shopfloors: for row in rows_shopfloors:
shopfloor_dict[row['id']] = {"shopfloor_name": row['shopfloor_name'], shopfloor_dict[row[0]] = {"shopfloor_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description'], "description": row[4],
"values": list()} "values": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -178,10 +178,10 @@ class Reporting:
description='API.ENERGY_CATEGORY_NOT_FOUND') description='API.ENERGY_CATEGORY_NOT_FOUND')
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category[0] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input

View File

@ -83,7 +83,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -98,7 +98,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -112,8 +112,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all stores in the space tree # Step 3: query all stores in the space tree
@ -133,11 +133,11 @@ class Reporting:
rows_stores = cursor_system_db.fetchall() rows_stores = cursor_system_db.fetchall()
if rows_stores is not None and len(rows_stores) > 0: if rows_stores is not None and len(rows_stores) > 0:
for row in rows_stores: for row in rows_stores:
store_dict[row['id']] = {"store_name": row['store_name'], store_dict[row[0]] = {"store_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description'], "description": row[4],
"values": list()} "values": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -178,9 +178,9 @@ class Reporting:
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category['id'] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input

View File

@ -83,7 +83,7 @@ class Reporting:
description='API.INVALID_REPORTING_PERIOD_END_DATETIME') description='API.INVALID_REPORTING_PERIOD_END_DATETIME')
cnx_system_db = mysql.connector.connect(**config.myems_system_db) cnx_system_db = mysql.connector.connect(**config.myems_system_db)
cursor_system_db = cnx_system_db.cursor(dictionary=True) cursor_system_db = cnx_system_db.cursor()
cursor_system_db.execute(" SELECT name " cursor_system_db.execute(" SELECT name "
" FROM tbl_spaces " " FROM tbl_spaces "
@ -98,7 +98,7 @@ class Reporting:
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
description='API.SPACE_NOT_FOUND') description='API.SPACE_NOT_FOUND')
else: else:
space_name = row['name'] space_name = row[0]
################################################################################################################ ################################################################################################################
# Step 2: build a space tree # Step 2: build a space tree
@ -112,8 +112,8 @@ class Reporting:
node_dict = dict() node_dict = dict()
if rows_spaces is not None and len(rows_spaces) > 0: if rows_spaces is not None and len(rows_spaces) > 0:
for row in rows_spaces: for row in rows_spaces:
parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None parent_node = node_dict[row[2]] if row[2] is not None else None
node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1])
################################################################################################################ ################################################################################################################
# Step 3: query all tenants in the space tree # Step 3: query all tenants in the space tree
@ -133,12 +133,12 @@ class Reporting:
rows_tenants = cursor_system_db.fetchall() rows_tenants = cursor_system_db.fetchall()
if rows_tenants is not None and len(rows_tenants) > 0: if rows_tenants is not None and len(rows_tenants) > 0:
for row in rows_tenants: for row in rows_tenants:
tenant_dict[row['id']] = {"tenant_name": row['tenant_name'], tenant_dict[row[0]] = {"tenant_name": row[1],
"space_name": row['space_name'], "space_name": row[2],
"cost_center_name": row['cost_center_name'], "cost_center_name": row[3],
"description": row['description'], "description": row[4],
"values": list(), "values": list(),
"maximum": list()} "maximum": list()}
################################################################################################################ ################################################################################################################
# Step 4: query energy categories # Step 4: query energy categories
@ -178,10 +178,10 @@ class Reporting:
description='API.ENERGY_CATEGORY_NOT_FOUND') description='API.ENERGY_CATEGORY_NOT_FOUND')
energy_category_list = list() energy_category_list = list()
for row_energy_category in rows_energy_categories: for row_energy_category in rows_energy_categories:
if row_energy_category['id'] in energy_category_set: if row_energy_category[0] in energy_category_set:
energy_category_list.append({"id": row_energy_category['id'], energy_category_list.append({"id": row_energy_category[0],
"name": row_energy_category['name'], "name": row_energy_category[1],
"unit_of_measure": row_energy_category['unit_of_measure']}) "unit_of_measure": row_energy_category[2]})
################################################################################################################ ################################################################################################################
# Step 5: query reporting period energy input # Step 5: query reporting period energy input