From 9606d60f5570e7cc53c28055467b8fde9039a842 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Wed, 13 Apr 2022 16:29:31 +0800 Subject: [PATCH] removed dictionary based cursors from api/reports --- myems-api/reports/advancedreport.py | 33 +++++------ myems-api/reports/combinedequipmentbatch.py | 26 ++++---- myems-api/reports/distributionsystem.py | 18 +++--- myems-api/reports/energyflowdiagram.py | 66 ++++++++++----------- myems-api/reports/equipmentbatch.py | 26 ++++---- myems-api/reports/equipmenttracking.py | 18 +++--- myems-api/reports/meterbatch.py | 26 ++++---- myems-api/reports/metertracking.py | 18 +++--- myems-api/reports/shopfloorbatch.py | 26 ++++---- myems-api/reports/storebatch.py | 24 ++++---- myems-api/reports/tenantbatch.py | 28 ++++----- 11 files changed, 154 insertions(+), 155 deletions(-) diff --git a/myems-api/reports/advancedreport.py b/myems-api/reports/advancedreport.py index c3070b5c..81dacd25 100644 --- a/myems-api/reports/advancedreport.py +++ b/myems-api/reports/advancedreport.py @@ -71,7 +71,7 @@ class AdvancedReportCollection: ################################################################################################################ 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 " " FROM tbl_reports_files " @@ -91,17 +91,17 @@ class AdvancedReportCollection: if rows is not None and len(rows) > 0: for row in rows: # 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. 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) - meta_result = {"id": row['id'], - "file_name": row['file_name'], - "uuid": row['uuid'], + meta_result = {"id": row[0], + "file_name": row[1], + "uuid": row[2], "create_datetime_local": create_datetime_local.isoformat(), - "file_type": row['file_type'], - "file_size_bytes": sys.getsizeof(row['file_object']), + "file_type": row[4], + "file_size_bytes": sys.getsizeof(row[5]), "file_bytes_base64": base64_message} result.append(meta_result) @@ -126,7 +126,7 @@ class AdvancedReportItem: description='API.INVALID_ADVANCED_REPORT_ID') 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 " " FROM tbl_reports_files " @@ -144,16 +144,15 @@ class AdvancedReportItem: description='API.ADVANCED_REPORT_NOT_FOUND') # 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. base64_message = base64_encoded_data.decode('utf-8') - result = {"id": row['id'], - "file_name": row['file_name'], - "uuid": row['uuid'], - "create_datetime": - row['create_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000, - "file_type": row['file_type'], + result = {"id": row[0], + "file_name": row[1], + "uuid": row[2], + "create_datetime": row[3].replace(tzinfo=timezone.utc).timestamp() * 1000, + "file_type": row[4], "file_bytes_base64": base64_message} resp.text = json.dumps(result) @@ -165,7 +164,7 @@ class AdvancedReportItem: description='API.INVALID_ADVANCED_REPORT_ID') 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 " " FROM tbl_reports_files " diff --git a/myems-api/reports/combinedequipmentbatch.py b/myems-api/reports/combinedequipmentbatch.py index cb61e84c..aafd4b8a 100644 --- a/myems-api/reports/combinedequipmentbatch.py +++ b/myems-api/reports/combinedequipmentbatch.py @@ -83,7 +83,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -98,7 +98,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -112,8 +112,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all combined equipments in the space tree @@ -134,11 +134,11 @@ class Reporting: rows_combined_equipments = cursor_system_db.fetchall() if rows_combined_equipments is not None and len(rows_combined_equipments) > 0: for row in rows_combined_equipments: - combined_equipment_dict[row['id']] = {"combined_equipment_name": row['combined_equipment_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description'], - "values": list()} + combined_equipment_dict[row[0]] = {"combined_equipment_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4], + "values": list()} ################################################################################################################ # Step 4: query energy categories @@ -178,10 +178,10 @@ class Reporting: description='API.ENERGY_CATEGORY_NOT_FOUND') energy_category_list = list() for row_energy_category in rows_energy_categories: - if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + if row_energy_category[0] in energy_category_set: + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input diff --git a/myems-api/reports/distributionsystem.py b/myems-api/reports/distributionsystem.py index 328128a4..2269b7b8 100644 --- a/myems-api/reports/distributionsystem.py +++ b/myems-api/reports/distributionsystem.py @@ -48,7 +48,7 @@ class Reporting: # Step 2: Step 2: query the distribution system ################################################################################################################ 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 " " FROM tbl_distribution_systems " @@ -75,10 +75,10 @@ class Reporting: circuit_list = list() if rows is not None and len(rows) > 0: for row in rows: - circuit_list.append({"id": row['id'], "name": row['name'], "uuid": row['uuid'], - "distribution_room": row['distribution_room'], "switchgear": row['switchgear'], - "peak_load": row['peak_load'], "peak_current": row['peak_current'], - "customers": row['customers'], "meters": row['meters'], + circuit_list.append({"id": row[0], "name": row[1], "uuid": row[2], + "distribution_room": row[3], "switchgear": row[4], + "peak_load": row[5], "peak_current": row[6], + "customers": row[7], "meters": row[8], "points": list()}) ################################################################################################################ @@ -95,10 +95,10 @@ class Reporting: if rows is not None and len(rows) > 0: for row in rows: - circuit_list[x]['points'].append({"id": row['id'], - "name": row['name'], - "object_type": row['object_type'], - "units": row['units'], + circuit_list[x]['points'].append({"id": row[0], + "name": row[1], + "object_type": row[2], + "units": row[3], "value": None}) if cursor_system: cursor_system.close() diff --git a/myems-api/reports/energyflowdiagram.py b/myems-api/reports/energyflowdiagram.py index fd2844b4..2eb692a1 100644 --- a/myems-api/reports/energyflowdiagram.py +++ b/myems-api/reports/energyflowdiagram.py @@ -87,7 +87,7 @@ class Reporting: ################################################################################################################ 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 " " FROM tbl_energy_flow_diagrams " @@ -103,8 +103,8 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') else: - energy_flow_diagram_name = row['name'] - energy_flow_diagram_uuid = row['uuid'] + energy_flow_diagram_name = row[0] + energy_flow_diagram_uuid = row[1] ################################################################################################################ # Step 3: query nodes @@ -119,10 +119,10 @@ class Reporting: node_list_dict = dict() if rows_nodes is not None and len(rows_nodes) > 0: for row in rows_nodes: - node_dict[row['id']] = row['name'] - if node_list_dict.get(row['energy_flow_diagram_id']) is None: - node_list_dict[row['energy_flow_diagram_id']] = list() - node_list_dict[row['energy_flow_diagram_id']].append({"id": row['id'], "name": row['name']}) + node_dict[row[0]] = row[2] + if node_list_dict.get(row[1]) is None: + node_list_dict[row[1]] = list() + node_list_dict[row[1]].append({"id": row[0], "name": row[2]}) ################################################################################################################ # Step 4: query links @@ -135,10 +135,10 @@ class Reporting: meter_dict = dict() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - meter_dict[row['uuid']] = {"type": 'meter', - "id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + meter_dict[row[2]] = {"type": 'meter', + "id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_offline_meters ") @@ -148,10 +148,10 @@ class Reporting: offline_meter_dict = dict() if rows_offline_meters is not None and len(rows_offline_meters) > 0: for row in rows_offline_meters: - offline_meter_dict[row['uuid']] = {"type": 'offline_meter', - "id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + offline_meter_dict[row[2]] = {"type": 'offline_meter', + "id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_virtual_meters ") @@ -161,10 +161,10 @@ class Reporting: virtual_meter_dict = dict() if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: for row in rows_virtual_meters: - virtual_meter_dict[row['uuid']] = {"type": 'virtual_meter', - "id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + virtual_meter_dict[row[2]] = {"type": 'virtual_meter', + "id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid " " FROM tbl_energy_flow_diagrams_links") @@ -175,23 +175,23 @@ class Reporting: if rows_links is not None and len(rows_links) > 0: for row in rows_links: # find meter by uuid - meter = meter_dict.get(row['meter_uuid'], None) + meter = meter_dict.get(row[4], 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: - 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: - link_list_dict[row['energy_flow_diagram_id']] = list() - link_list_dict[row['energy_flow_diagram_id']].append({"id": row['id'], - "source_node": { - "id": row['source_node_id'], - "name": node_dict.get(row['source_node_id'])}, - "target_node": { - "id": row['target_node_id'], - "name": node_dict.get(row['target_node_id'])}, - "meter": meter, - "value": None}) + if link_list_dict.get(row[1]) is None: + link_list_dict[row[1]] = list() + link_list_dict[row[1]].append({"id": row[0], + "source_node": { + "id": row[2], + "name": node_dict.get(row[2])}, + "target_node": { + "id": row[3], + "name": node_dict.get(row[3])}, + "meter": meter, + "value": None}) meta_result = {"id": energy_flow_diagram_id, "name": energy_flow_diagram_name, diff --git a/myems-api/reports/equipmentbatch.py b/myems-api/reports/equipmentbatch.py index 73d27965..061329dc 100644 --- a/myems-api/reports/equipmentbatch.py +++ b/myems-api/reports/equipmentbatch.py @@ -83,7 +83,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -98,7 +98,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -112,8 +112,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all equipments in the space tree @@ -134,11 +134,11 @@ class Reporting: rows_equipments = cursor_system_db.fetchall() if rows_equipments is not None and len(rows_equipments) > 0: for row in rows_equipments: - equipment_dict[row['id']] = {"equipment_name": row['equipment_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description'], - "values": list()} + equipment_dict[row[0]] = {"equipment_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4], + "values": list()} ################################################################################################################ # Step 4: query energy categories @@ -178,10 +178,10 @@ class Reporting: description='API.ENERGY_CATEGORY_NOT_FOUND') energy_category_list = list() for row_energy_category in rows_energy_categories: - if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + if row_energy_category[0] in energy_category_set: + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input diff --git a/myems-api/reports/equipmenttracking.py b/myems-api/reports/equipmenttracking.py index 878852e0..ab59990c 100644 --- a/myems-api/reports/equipmenttracking.py +++ b/myems-api/reports/equipmenttracking.py @@ -41,7 +41,7 @@ class Reporting: space_id = int(space_id) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_spaces " @@ -56,7 +56,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree ################################################################################################################ @@ -69,8 +69,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all equipments in the space tree @@ -91,11 +91,11 @@ class Reporting: rows_equipments = cursor.fetchall() if rows_equipments is not None and len(rows_equipments) > 0: for row in rows_equipments: - equipment_list.append({"id": row['id'], - "equipment_name": row['equipment_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description']}) + equipment_list.append({"id": row[0], + "equipment_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4]}) if cursor: cursor.close() diff --git a/myems-api/reports/meterbatch.py b/myems-api/reports/meterbatch.py index 1441a4a0..d4902b79 100644 --- a/myems-api/reports/meterbatch.py +++ b/myems-api/reports/meterbatch.py @@ -82,7 +82,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -97,7 +97,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -111,8 +111,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all meters in the space tree @@ -134,11 +134,11 @@ class Reporting: rows_meters = cursor_system_db.fetchall() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - meter_dict[row['id']] = {"meter_name": row['meter_name'], - "energy_category_id": row['energy_category_id'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "values": list()} + meter_dict[row[0]] = {"meter_name": row[1], + "energy_category_id": row[2], + "space_name": row[3], + "cost_center_name": row[4], + "values": list()} ################################################################################################################ # Step 4: query energy categories @@ -174,10 +174,10 @@ class Reporting: description='API.ENERGY_CATEGORY_NOT_FOUND') energy_category_list = list() for row_energy_category in rows_energy_categories: - if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + if row_energy_category[0] in energy_category_set: + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input diff --git a/myems-api/reports/metertracking.py b/myems-api/reports/metertracking.py index 0ce4fe0f..5adc8391 100644 --- a/myems-api/reports/metertracking.py +++ b/myems-api/reports/metertracking.py @@ -85,7 +85,7 @@ class Reporting: description='API.THE_REPORTING_PERIOD_MUST_BE_LONGER_THAN_15_MINUTES') 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) cursor_historical = cnx_historical.cursor() @@ -103,7 +103,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -117,8 +117,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all meters in the space tree @@ -140,11 +140,11 @@ class Reporting: rows_meters = cursor_system_db.fetchall() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - meter_dict[row['id']] = {"meter_name": row['meter_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "energy_category_name": row['energy_category_name'], - "description": row['description']} + meter_dict[row[0]] = {"meter_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "energy_category_name": row[4], + "description": row[5]} ################################################################################################################ # Step 4: query start value and end value diff --git a/myems-api/reports/shopfloorbatch.py b/myems-api/reports/shopfloorbatch.py index 63a74b1e..72d932a0 100644 --- a/myems-api/reports/shopfloorbatch.py +++ b/myems-api/reports/shopfloorbatch.py @@ -83,7 +83,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -98,7 +98,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -112,8 +112,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all shopfloors in the space tree @@ -134,11 +134,11 @@ class Reporting: rows_shopfloors = cursor_system_db.fetchall() if rows_shopfloors is not None and len(rows_shopfloors) > 0: for row in rows_shopfloors: - shopfloor_dict[row['id']] = {"shopfloor_name": row['shopfloor_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description'], - "values": list()} + shopfloor_dict[row[0]] = {"shopfloor_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4], + "values": list()} ################################################################################################################ # Step 4: query energy categories @@ -178,10 +178,10 @@ class Reporting: description='API.ENERGY_CATEGORY_NOT_FOUND') energy_category_list = list() for row_energy_category in rows_energy_categories: - if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + if row_energy_category[0] in energy_category_set: + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input diff --git a/myems-api/reports/storebatch.py b/myems-api/reports/storebatch.py index 7ea9c781..c2924507 100644 --- a/myems-api/reports/storebatch.py +++ b/myems-api/reports/storebatch.py @@ -83,7 +83,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -98,7 +98,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -112,8 +112,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all stores in the space tree @@ -133,11 +133,11 @@ class Reporting: rows_stores = cursor_system_db.fetchall() if rows_stores is not None and len(rows_stores) > 0: for row in rows_stores: - store_dict[row['id']] = {"store_name": row['store_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description'], - "values": list()} + store_dict[row[0]] = {"store_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4], + "values": list()} ################################################################################################################ # Step 4: query energy categories @@ -178,9 +178,9 @@ class Reporting: energy_category_list = list() for row_energy_category in rows_energy_categories: if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input diff --git a/myems-api/reports/tenantbatch.py b/myems-api/reports/tenantbatch.py index c2ea25d9..39eb1216 100644 --- a/myems-api/reports/tenantbatch.py +++ b/myems-api/reports/tenantbatch.py @@ -83,7 +83,7 @@ class Reporting: description='API.INVALID_REPORTING_PERIOD_END_DATETIME') 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 " " FROM tbl_spaces " @@ -98,7 +98,7 @@ class Reporting: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - space_name = row['name'] + space_name = row[0] ################################################################################################################ # Step 2: build a space tree @@ -112,8 +112,8 @@ class Reporting: node_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - parent_node = node_dict[row['parent_space_id']] if row['parent_space_id'] is not None else None - node_dict[row['id']] = AnyNode(id=row['id'], parent=parent_node, name=row['name']) + parent_node = node_dict[row[2]] if row[2] is not None else None + node_dict[row[0]] = AnyNode(id=row[0], parent=parent_node, name=row[1]) ################################################################################################################ # Step 3: query all tenants in the space tree @@ -133,12 +133,12 @@ class Reporting: rows_tenants = cursor_system_db.fetchall() if rows_tenants is not None and len(rows_tenants) > 0: for row in rows_tenants: - tenant_dict[row['id']] = {"tenant_name": row['tenant_name'], - "space_name": row['space_name'], - "cost_center_name": row['cost_center_name'], - "description": row['description'], - "values": list(), - "maximum": list()} + tenant_dict[row[0]] = {"tenant_name": row[1], + "space_name": row[2], + "cost_center_name": row[3], + "description": row[4], + "values": list(), + "maximum": list()} ################################################################################################################ # Step 4: query energy categories @@ -178,10 +178,10 @@ class Reporting: description='API.ENERGY_CATEGORY_NOT_FOUND') energy_category_list = list() for row_energy_category in rows_energy_categories: - if row_energy_category['id'] in energy_category_set: - energy_category_list.append({"id": row_energy_category['id'], - "name": row_energy_category['name'], - "unit_of_measure": row_energy_category['unit_of_measure']}) + if row_energy_category[0] in energy_category_set: + energy_category_list.append({"id": row_energy_category[0], + "name": row_energy_category[1], + "unit_of_measure": row_energy_category[2]}) ################################################################################################################ # Step 5: query reporting period energy input