From e5a8c38ed2276e231e2ef4cd873e71ecf147ad23 Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Wed, 13 Apr 2022 15:08:43 +0800 Subject: [PATCH] removed dictionary based cursors from api/core --- myems-api/core/combinedequipment.py | 4 +- myems-api/core/datasource.py | 73 +++--- myems-api/core/distributioncircuit.py | 72 +++--- myems-api/core/distributionsystem.py | 34 +-- myems-api/core/energyflowdiagram.py | 310 +++++++++++++------------- myems-api/core/energyitem.py | 28 +-- myems-api/core/equipment.py | 307 +++++++++++++------------ myems-api/core/gateway.py | 41 ++-- myems-api/core/knowledgefile.py | 20 +- myems-api/core/menu.py | 56 ++--- myems-api/core/meter.py | 144 ++++++------ myems-api/core/offlinemeter.py | 80 +++---- myems-api/core/point.py | 64 +++--- myems-api/core/rule.py | 40 ++-- myems-api/core/sensor.py | 20 +- myems-api/core/shopfloor.py | 112 +++++----- myems-api/core/space.py | 228 +++++++++---------- myems-api/core/store.py | 140 ++++++------ myems-api/core/tariff.py | 72 +++--- myems-api/core/tenant.py | 160 ++++++------- myems-api/core/textmessage.py | 3 +- myems-api/core/user.py | 10 +- myems-api/core/virtualmeter.py | 160 ++++++------- myems-api/core/webmessage.py | 36 +-- myems-api/core/wechatmessage.py | 6 +- 25 files changed, 1106 insertions(+), 1114 deletions(-) diff --git a/myems-api/core/combinedequipment.py b/myems-api/core/combinedequipment.py index c5654467..155ee007 100644 --- a/myems-api/core/combinedequipment.py +++ b/myems-api/core/combinedequipment.py @@ -732,8 +732,8 @@ class CombinedEquipmentParameterCollection: point_dict = dict() if rows_points is not None and len(rows_points) > 0: for row in rows_points: - point_dict[row['id']] = {"id": row[0], - "name": row[1]} + point_dict[row[0]] = {"id": row[0], + "name": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") diff --git a/myems-api/core/datasource.py b/myems-api/core/datasource.py index ec4f122b..f2410cc4 100644 --- a/myems-api/core/datasource.py +++ b/myems-api/core/datasource.py @@ -21,7 +21,7 @@ class DataSourceCollection: def on_get(req, resp): access_control(req) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_gateways ") @@ -30,9 +30,9 @@ class DataSourceCollection: gateway_dict = dict() if rows_gateways is not None and len(rows_gateways) > 0: for row in rows_gateways: - gateway_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + gateway_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, gateway_id, protocol, connection, last_seen_datetime_utc " " FROM tbl_data_sources " @@ -49,18 +49,17 @@ class DataSourceCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - if isinstance(row['last_seen_datetime_utc'], datetime): - last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \ - timedelta(minutes=timezone_offset) + if isinstance(row[6], datetime): + last_seen_datetime_local = row[6].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset) last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_seen_datetime = None - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "gateway": gateway_dict.get(row['gateway_id']), - "protocol": row['protocol'], - "connection": row['connection'], + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "gateway": gateway_dict.get(row[3]), + "protocol": row[4], + "connection": row[5], "last_seen_datetime": last_seen_datetime } @@ -179,7 +178,7 @@ class DataSourceItem: description='API.INVALID_DATA_SOURCE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_gateways ") @@ -188,9 +187,9 @@ class DataSourceItem: gateway_dict = dict() if rows_gateways is not None and len(rows_gateways) > 0: for row in rows_gateways: - gateway_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + gateway_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, gateway_id, protocol, connection, last_seen_datetime_utc " " FROM tbl_data_sources " @@ -207,19 +206,19 @@ class DataSourceItem: if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - if isinstance(row['last_seen_datetime_utc'], datetime): - last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[6], datetime): + last_seen_datetime_local = row[6].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_seen_datetime = None - result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "gateway": gateway_dict.get(row['gateway_id']), - "protocol": row['protocol'], - "connection": row['connection'], + result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "gateway": gateway_dict.get(row[3]), + "protocol": row[4], + "connection": row[5], "last_seen_datetime": last_seen_datetime } @@ -383,7 +382,7 @@ class DataSourcePointCollection: description='API.INVALID_DATA_SOURCE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_data_sources " @@ -407,17 +406,17 @@ class DataSourcePointCollection: if rows_point is not None and len(rows_point) > 0: for row in rows_point: - meta_result = {"id": row['id'], - "name": row['name'], - "object_type": row['object_type'], - "units": row['units'], - "high_limit": row['high_limit'], - "low_limit": row['low_limit'], - "ratio": float(row['ratio']), - "is_trend": bool(row['is_trend']), - "is_virtual": bool(row['is_virtual']), - "address": row['address'], - "description": row['description']} + meta_result = {"id": row[0], + "name": row[1], + "object_type": row[2], + "units": row[3], + "high_limit": row[4], + "low_limit": row[5], + "ratio": float(row[6]), + "is_trend": bool(row[7]), + "is_virtual": bool(row[8]), + "address": row[9], + "description": row[10]} result.append(meta_result) cursor.close() diff --git a/myems-api/core/distributioncircuit.py b/myems-api/core/distributioncircuit.py index 9ab8aae9..718c314b 100644 --- a/myems-api/core/distributioncircuit.py +++ b/myems-api/core/distributioncircuit.py @@ -19,7 +19,7 @@ class DistributionCircuitCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_distribution_systems ") @@ -29,9 +29,9 @@ class DistributionCircuitCollection: distribution_system_dict = dict() if rows_distribution_systems is not None and len(rows_distribution_systems) > 0: for row in rows_distribution_systems: - distribution_system_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + distribution_system_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, distribution_system_id, " " distribution_room, switchgear, peak_load, peak_current, customers, meters " " FROM tbl_distribution_circuits " @@ -42,17 +42,17 @@ class DistributionCircuitCollection: result = list() if rows_distribution_circuits is not None and len(rows_distribution_circuits) > 0: for row in rows_distribution_circuits: - distribution_system = distribution_system_dict.get(row['distribution_system_id']) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + distribution_system = distribution_system_dict.get(row[3]) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "distribution_system": distribution_system, - "distribution_room": row['distribution_room'], - "switchgear": row['switchgear'], - "peak_load": row['peak_load'], - "peak_current": row['peak_current'], - "customers": row['customers'], - "meters": row['meters']} + "distribution_room": row[4], + "switchgear": row[5], + "peak_load": row[6], + "peak_current": row[7], + "customers": row[8], + "meters": row[9]} result.append(meta_result) cursor.close() @@ -189,7 +189,7 @@ class DistributionCircuitItem: description='API.INVALID_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_distribution_systems ") @@ -199,9 +199,9 @@ class DistributionCircuitItem: distribution_system_dict = dict() if rows_distribution_systems is not None and len(rows_distribution_systems) > 0: for row in rows_distribution_systems: - distribution_system_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + distribution_system_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, distribution_system_id, " " distribution_room, switchgear, peak_load, peak_current, customers, meters " @@ -216,17 +216,17 @@ class DistributionCircuitItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.DISTRIBUTION_CIRCUIT_NOT_FOUND') else: - distribution_system = distribution_system_dict.get(row['distribution_system_id']) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + distribution_system = distribution_system_dict.get(row[3]) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "distribution_system": distribution_system, - "distribution_room": row['distribution_room'], - "switchgear": row['switchgear'], - "peak_load": row['peak_load'], - "peak_current": row['peak_current'], - "customers": row['customers'], - "meters": row['meters']} + "distribution_room": row[4], + "switchgear": row[5], + "peak_load": row[6], + "peak_current": row[7], + "customers": row[8], + "meters": row[9]} resp.text = json.dumps(meta_result) @@ -395,7 +395,7 @@ class DistributionCircuitPointCollection: description='API.INVALID_DISTRIBUTION_CIRCUIT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_distribution_systems ") @@ -405,9 +405,9 @@ class DistributionCircuitPointCollection: distribution_system_dict = dict() if rows_distribution_systems is not None and len(rows_distribution_systems) > 0: for row in rows_distribution_systems: - distribution_system_dict[row['uuid']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + distribution_system_dict[row['uuid']] = {"id": row[0], + "name": row[1], + "uuid": row[2]} cursor.execute(" SELECT name " " FROM tbl_distribution_circuits " @@ -431,10 +431,10 @@ class DistributionCircuitPointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - meta_result = {"id": row['point_id'], "name": row['point_name'], "address": row['point_address'], - "distribution_circuit": {"id": row['distribution_circuit_id'], - "name": row['distribution_circuit_name'], - "uuid": row['distribution_circuit_uuid']}} + meta_result = {"id": row[0], "name": row[1], "address": row[2], + "distribution_circuit": {"id": row[3], + "name": row[4], + "uuid": row[5]}} result.append(meta_result) resp.text = json.dumps(result) diff --git a/myems-api/core/distributionsystem.py b/myems-api/core/distributionsystem.py index ca598f63..a442e880 100644 --- a/myems-api/core/distributionsystem.py +++ b/myems-api/core/distributionsystem.py @@ -19,7 +19,7 @@ class DistributionSystemCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, " " svg, description " @@ -32,11 +32,11 @@ class DistributionSystemCollection: if rows_distribution_systems is not None and len(rows_distribution_systems) > 0: for row in rows_distribution_systems: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "svg": row['svg'], - "description": row['description']} + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "svg": row[3], + "description": row[4]} result.append(meta_result) cursor.close() @@ -121,7 +121,7 @@ class DistributionSystemItem: description='API.INVALID_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, " " svg, description " @@ -136,11 +136,11 @@ class DistributionSystemItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.DISTRIBUTION_SYSTEM_NOT_FOUND') else: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "svg": row['svg'], - "description": row['description']} + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "svg": row[3], + "description": row[4]} resp.text = json.dumps(meta_result) @@ -265,7 +265,7 @@ class DistributionSystemDistributionCircuitCollection: description='API.INVALID_DISTRIBUTION_SYSTEM_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_distribution_systems " @@ -287,10 +287,10 @@ class DistributionSystemDistributionCircuitCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - meta_result = {"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']} + meta_result = {"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]} result.append(meta_result) resp.text = json.dumps(result) diff --git a/myems-api/core/energyflowdiagram.py b/myems-api/core/energyflowdiagram.py index eaa96990..6d60985c 100644 --- a/myems-api/core/energyflowdiagram.py +++ b/myems-api/core/energyflowdiagram.py @@ -19,12 +19,8 @@ class EnergyFlowDiagramCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() - query = (" SELECT id, energy_flow_diagram_id, name " - " FROM tbl_energy_flow_diagrams_nodes") - cursor.execute(query) - rows_nodes = cursor.fetchall() query = (" SELECT id, name, uuid " " FROM tbl_meters ") cursor.execute(query) @@ -33,10 +29,10 @@ class EnergyFlowDiagramCollection: 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 ") @@ -46,10 +42,10 @@ class EnergyFlowDiagramCollection: 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 ") @@ -59,19 +55,24 @@ class EnergyFlowDiagramCollection: 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, name " + " FROM tbl_energy_flow_diagrams_nodes") + cursor.execute(query) + rows_nodes = cursor.fetchall() node_dict = dict() 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]}) query = (" SELECT id, energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid " " FROM tbl_energy_flow_diagrams_links") @@ -82,22 +83,22 @@ class EnergyFlowDiagramCollection: 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}) + 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}) query = (" SELECT id, name, uuid " " FROM tbl_energy_flow_diagrams " @@ -109,11 +110,11 @@ class EnergyFlowDiagramCollection: if rows_energy_flow_diagrams is not None and len(rows_energy_flow_diagrams) > 0: for row in rows_energy_flow_diagrams: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "nodes": node_list_dict.get(row['id'], None), - "links": link_list_dict.get(row['id'], None), } + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "nodes": node_list_dict.get(row[0], None), + "links": link_list_dict.get(row[0], None), } result.append(meta_result) cursor.close() @@ -182,12 +183,8 @@ class EnergyFlowDiagramItem: description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() - query = (" SELECT id, energy_flow_diagram_id, name " - " FROM tbl_energy_flow_diagrams_nodes") - cursor.execute(query) - rows_nodes = cursor.fetchall() query = (" SELECT id, name, uuid " " FROM tbl_meters ") cursor.execute(query) @@ -196,10 +193,10 @@ class EnergyFlowDiagramItem: 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 ") @@ -209,10 +206,10 @@ class EnergyFlowDiagramItem: 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 ") @@ -222,19 +219,24 @@ class EnergyFlowDiagramItem: 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, name " + " FROM tbl_energy_flow_diagrams_nodes") + cursor.execute(query) + rows_nodes = cursor.fetchall() node_dict = dict() 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]}) query = (" SELECT id, energy_flow_diagram_id, source_node_id, target_node_id, meter_uuid " " FROM tbl_energy_flow_diagrams_links") @@ -245,22 +247,22 @@ class EnergyFlowDiagramItem: 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}) + 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}) query = (" SELECT id, name, uuid " " FROM tbl_energy_flow_diagrams " @@ -274,11 +276,11 @@ class EnergyFlowDiagramItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.ENERGY_FLOW_DIAGRAM_NOT_FOUND') else: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "nodes": node_list_dict.get(row['id'], None), - "links": link_list_dict.get(row['id'], None), + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "nodes": node_list_dict.get(row[0], None), + "links": link_list_dict.get(row[0], None), } resp.text = json.dumps(meta_result) @@ -386,7 +388,7 @@ class EnergyFlowDiagramLinkCollection: description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name " " FROM tbl_energy_flow_diagrams_nodes ") @@ -396,8 +398,8 @@ class EnergyFlowDiagramLinkCollection: node_dict = dict() if rows_nodes is not None and len(rows_nodes) > 0: for row in rows_nodes: - node_dict[row['id']] = {"id": row['id'], - "name": row['name']} + node_dict[row[0]] = {"id": row[0], + "name": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -407,10 +409,10 @@ class EnergyFlowDiagramLinkCollection: 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 ") @@ -420,10 +422,10 @@ class EnergyFlowDiagramLinkCollection: 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 ") @@ -433,10 +435,10 @@ class EnergyFlowDiagramLinkCollection: 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]} cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " @@ -457,16 +459,16 @@ class EnergyFlowDiagramLinkCollection: result = list() if rows_links is not None and len(rows_links) > 0: for row in rows_links: - source_node = node_dict.get(row['source_node_id'], None) - target_node = node_dict.get(row['target_node_id'], None) + source_node = node_dict.get(row[1], None) + target_node = node_dict.get(row[2], None) # find meter by uuid - meter = meter_dict.get(row['meter_uuid'], None) + meter = meter_dict.get(row[3], None) if meter is None: - meter = virtual_meter_dict.get(row['meter_uuid'], None) + meter = virtual_meter_dict.get(row[3], None) if meter is None: - meter = offline_meter_dict.get(row['meter_uuid'], None) + meter = offline_meter_dict.get(row[3], None) - meta_result = {"id": row['id'], + meta_result = {"id": row[0], "source_node": source_node, "target_node": target_node, "meter": meter} @@ -515,7 +517,7 @@ class EnergyFlowDiagramLinkCollection: meter_uuid = str.strip(new_values['data']['meter_uuid']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " @@ -567,10 +569,10 @@ class EnergyFlowDiagramLinkCollection: 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 ") @@ -580,10 +582,10 @@ class EnergyFlowDiagramLinkCollection: 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 ") @@ -593,10 +595,10 @@ class EnergyFlowDiagramLinkCollection: 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]} # validate meter uuid if meter_dict.get(meter_uuid) is None and \ @@ -642,7 +644,7 @@ class EnergyFlowDiagramLinkItem: description='API.INVALID_ENERGY_FLOW_DIAGRAM_LINK_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name " " FROM tbl_energy_flow_diagrams_nodes ") @@ -652,8 +654,8 @@ class EnergyFlowDiagramLinkItem: node_dict = dict() if rows_nodes is not None and len(rows_nodes) > 0: for row in rows_nodes: - node_dict[row['id']] = {"id": row['id'], - "name": row['name']} + node_dict[row[0]] = {"id": row[0], + "name": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -663,10 +665,10 @@ class EnergyFlowDiagramLinkItem: 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 ") @@ -676,10 +678,10 @@ class EnergyFlowDiagramLinkItem: 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 ") @@ -689,10 +691,10 @@ class EnergyFlowDiagramLinkItem: 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, source_node_id, target_node_id, meter_uuid " " FROM tbl_energy_flow_diagrams_links " @@ -706,16 +708,16 @@ class EnergyFlowDiagramLinkItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.ENERGY_FLOW_DIAGRAM_LINK_NOT_FOUND_OR_NOT_MATCH') else: - source_node = node_dict.get(row['source_node_id'], None) - target_node = node_dict.get(row['target_node_id'], None) + source_node = node_dict.get(row[1], None) + target_node = node_dict.get(row[2], None) # find meter by uuid - meter = meter_dict.get(row['meter_uuid'], None) + meter = meter_dict.get(row[3], None) if meter is None: - meter = virtual_meter_dict.get(row['meter_uuid'], None) + meter = virtual_meter_dict.get(row[3], None) if meter is None: - meter = offline_meter_dict.get(row['meter_uuid'], None) + meter = offline_meter_dict.get(row[3], None) - meta_result = {"id": row['id'], + meta_result = {"id": row[0], "source_node": source_node, "target_node": target_node, "meter": meter} @@ -813,7 +815,7 @@ class EnergyFlowDiagramLinkItem: meter_uuid = str.strip(new_values['data']['meter_uuid']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " @@ -877,10 +879,10 @@ class EnergyFlowDiagramLinkItem: 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 ") @@ -890,10 +892,10 @@ class EnergyFlowDiagramLinkItem: 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 ") @@ -903,10 +905,10 @@ class EnergyFlowDiagramLinkItem: 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]} # validate meter uuid if meter_dict.get(meter_uuid) is None and \ @@ -947,7 +949,7 @@ class EnergyFlowDiagramNodeCollection: description='API.INVALID_ENERGY_FLOW_DIAGRAM_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " @@ -968,8 +970,8 @@ class EnergyFlowDiagramNodeCollection: result = list() if rows_nodes is not None and len(rows_nodes) > 0: for row in rows_nodes: - meta_result = {"id": row['id'], - "name": row['name']} + meta_result = {"id": row[0], + "name": row[1]} result.append(meta_result) cursor.close() @@ -999,7 +1001,7 @@ class EnergyFlowDiagramNodeCollection: name = str.strip(new_values['data']['name']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " @@ -1054,7 +1056,7 @@ class EnergyFlowDiagramNodeItem: description='API.INVALID_ENERGY_FLOW_DIAGRAM_NODE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name " " FROM tbl_energy_flow_diagrams_nodes " @@ -1068,8 +1070,8 @@ class EnergyFlowDiagramNodeItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.ENERGY_FLOW_DIAGRAM_NODE_NOT_FOUND_OR_NOT_MATCH') else: - meta_result = {"id": row['id'], - "name": row['name']} + meta_result = {"id": row[0], + "name": row[1]} resp.text = json.dumps(meta_result) @@ -1149,7 +1151,7 @@ class EnergyFlowDiagramNodeItem: name = str.strip(new_values['data']['name']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_energy_flow_diagrams " diff --git a/myems-api/core/energyitem.py b/myems-api/core/energyitem.py index 6ef9c035..edfe598d 100644 --- a/myems-api/core/energyitem.py +++ b/myems-api/core/energyitem.py @@ -19,7 +19,7 @@ class EnergyItemCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -29,9 +29,9 @@ class EnergyItemCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id " " FROM tbl_energy_items " @@ -44,8 +44,8 @@ class EnergyItemCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -131,7 +131,7 @@ class EnergyItemItem: description='API.INVALID_ENERGY_ITEM_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -141,9 +141,9 @@ class EnergyItemItem: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id " " FROM tbl_energy_items " @@ -156,10 +156,10 @@ class EnergyItemItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.ENERGY_ITEM_NOT_FOUND') - energy_category = energy_category_dict.get(row['energy_category_id'], None) - result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category} resp.text = json.dumps(result) diff --git a/myems-api/core/equipment.py b/myems-api/core/equipment.py index 4526abf8..5cdc963b 100644 --- a/myems-api/core/equipment.py +++ b/myems-api/core/equipment.py @@ -19,7 +19,7 @@ class EquipmentCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -29,9 +29,9 @@ class EquipmentCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " is_input_counted, is_output_counted, " @@ -44,15 +44,15 @@ class EquipmentCollection: result = list() if rows_equipments is not None and len(rows_equipments) > 0: for row in rows_equipments: - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "is_input_counted": bool(row['is_input_counted']), - "is_output_counted": bool(row['is_output_counted']), + cost_center = cost_center_dict.get(row[5], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "is_input_counted": bool(row[3]), + "is_output_counted": bool(row[4]), "cost_center": cost_center, - "description": row['description'], - "qrcode": 'equipment:' + row['uuid']} + "description": row[6], + "qrcode": 'equipment:' + row[2]} result.append(meta_result) cursor.close() @@ -164,7 +164,7 @@ class EquipmentItem: description='API.INVALID_EQUIPMENT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -174,9 +174,9 @@ class EquipmentItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " is_input_counted, is_output_counted, " @@ -192,15 +192,15 @@ class EquipmentItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.EQUIPMENT_NOT_FOUND') else: - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "is_input_counted": bool(row['is_input_counted']), - "is_output_counted": bool(row['is_output_counted']), + cost_center = cost_center_dict.get(row[5], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "is_input_counted": bool(row[3]), + "is_output_counted": bool(row[4]), "cost_center": cost_center, - "description": row['description'], - "qrcode": 'equipment:' + row['uuid']} + "description": row[6], + "qrcode": 'equipment:' + row[2]} resp.text = json.dumps(meta_result) @@ -406,7 +406,7 @@ class EquipmentItem: new_values = json.loads(raw_json) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " " WHERE id = %s ", (id_,)) @@ -427,17 +427,16 @@ class EquipmentItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.EQUIPMENT_NOT_FOUND') else: - add_values = (" INSERT INTO tbl_equipments " " (name, uuid, is_input_counted, is_output_counted, " " cost_center_id, description) " " VALUES (%s, %s, %s, %s, %s, %s) ") - cursor.execute(add_values, (row['name'] + ' Copy', + cursor.execute(add_values, (row[0] + ' Copy', str(uuid.uuid4()), - row['is_input_counted'], - row['is_output_counted'], - row['cost_center_id'], - row['description'])) + row[1], + row[2], + row[3], + row[4])) new_id = cursor.lastrowid cnx.commit() @@ -452,8 +451,8 @@ class EquipmentItem: " VALUES ") for row in rows_meters: add_values += " (" + str(new_id) + "," - add_values += str(row['meter_id']) + "," - add_values += str(bool(row['is_output'])) + "), " + add_values += str(row[0]) + "," + add_values += str(bool(row[1])) + "), " # trim ", " at the end of string and then execute cursor.execute(add_values[:-2]) cnx.commit() @@ -469,8 +468,8 @@ class EquipmentItem: " VALUES ") for row in rows_offline_meters: add_values += " (" + str(new_id) + "," - add_values += "'" + str(row['offline_meter_id']) + "'," - add_values += str(bool(row['is_output'])) + "), " + add_values += "'" + str(row[0]) + "'," + add_values += str(bool(row[1])) + "), " # trim ", " at the end of string and then execute cursor.execute(add_values[:-2]) cnx.commit() @@ -486,8 +485,8 @@ class EquipmentItem: " VALUES ") for row in rows_virtual_meters: add_values += " (" + str(new_id) + "," - add_values += str(row['virtual_meter_id']) + "," - add_values += str(bool(row['is_output'])) + "), " + add_values += str(row[0]) + "," + add_values += str(bool(row[1])) + "), " # trim ", " at the end of string and then execute cursor.execute(add_values[:-2]) cnx.commit() @@ -505,24 +504,24 @@ class EquipmentItem: " VALUES ") for row in rows_parameters: add_values += " (" + str(new_id) + "," - add_values += "'" + str(row['name']) + "'," - add_values += "'" + str(row['parameter_type']) + "'," - if row['constant'] is not None: - add_values += "'" + str(row['constant']) + "'," + add_values += "'" + str(row[0]) + "'," + add_values += "'" + str(row[1]) + "'," + if row[2] is not None: + add_values += "'" + str(row[2]) + "'," else: add_values += "null, " - if row['point_id'] is not None: - add_values += str(row['point_id']) + "," + if row[3] is not None: + add_values += str(row[3]) + "," else: add_values += "null, " - if row['numerator_meter_uuid'] is not None: - add_values += "'" + row['numerator_meter_uuid'] + "'," + if row[4] is not None: + add_values += "'" + row[4] + "'," else: add_values += "null, " - if row['denominator_meter_uuid'] is not None: - add_values += "'" + row['denominator_meter_uuid'] + "'), " + if row[5] is not None: + add_values += "'" + row[5] + "'), " else: add_values += "null), " @@ -553,7 +552,7 @@ class EquipmentParameterCollection: description='API.INVALID_EQUIPMENT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " @@ -572,8 +571,8 @@ class EquipmentParameterCollection: point_dict = dict() if rows_points is not None and len(rows_points) > 0: for row in rows_points: - point_dict[row['id']] = {"id": row['id'], - "name": row['name']} + point_dict[row[0]] = {"id": row[0], + "name": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -583,10 +582,10 @@ class EquipmentParameterCollection: 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 ") @@ -596,10 +595,10 @@ class EquipmentParameterCollection: 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 ") @@ -609,10 +608,10 @@ class EquipmentParameterCollection: 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, name, parameter_type, " " constant, point_id, numerator_meter_uuid, denominator_meter_uuid " @@ -629,35 +628,35 @@ class EquipmentParameterCollection: point = None numerator_meter = None denominator_meter = None - if row['parameter_type'] == 'point': - point = point_dict.get(row['point_id'], None) + if row[2] == 'point': + point = point_dict.get(row[4], None) constant = None numerator_meter = None denominator_meter = None - elif row['parameter_type'] == 'constant': - constant = row['constant'] + elif row[2] == 'constant': + constant = row[3] point = None numerator_meter = None denominator_meter = None - elif row['parameter_type'] == 'fraction': + elif row[2] == 'fraction': constant = None point = None # find numerator meter by uuid - numerator_meter = meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = meter_dict.get(row[5], None) if numerator_meter is None: - numerator_meter = virtual_meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = virtual_meter_dict.get(row[5], None) if numerator_meter is None: - numerator_meter = offline_meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = offline_meter_dict.get(row[5], None) # find denominator meter by uuid - denominator_meter = meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = meter_dict.get(row[6], None) if denominator_meter is None: - denominator_meter = virtual_meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = virtual_meter_dict.get(row[6], None) if denominator_meter is None: - denominator_meter = offline_meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = offline_meter_dict.get(row[6], None) - meta_result = {"id": row['id'], - "name": row['name'], - "parameter_type": row['parameter_type'], + meta_result = {"id": row[0], + "name": row[1], + "parameter_type": row[2], "constant": constant, "point": point, "numerator_meter": numerator_meter, @@ -732,8 +731,7 @@ class EquipmentParameterCollection: denominator_meter_uuid = str.strip(new_values['data']['denominator_meter_uuid']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) - + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " " WHERE id = %s ", (id_,)) @@ -757,7 +755,6 @@ class EquipmentParameterCollection: if point_id is None: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_POINT_ID') - query = (" SELECT id, name " " FROM tbl_points " " WHERE id = %s ") @@ -774,19 +771,17 @@ class EquipmentParameterCollection: description='API.INVALID_CONSTANT_VALUE') elif parameter_type == 'fraction': - query = (" SELECT id, name, uuid " " FROM tbl_meters ") cursor.execute(query) rows_meters = cursor.fetchall() - 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 ") @@ -796,10 +791,10 @@ class EquipmentParameterCollection: 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 ") @@ -809,10 +804,10 @@ class EquipmentParameterCollection: 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]} # validate numerator meter uuid if meter_dict.get(numerator_meter_uuid) is None and \ @@ -874,7 +869,7 @@ class EquipmentParameterItem: description='API.INVALID_EQUIPMENT_PARAMETER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name " " FROM tbl_points ") @@ -884,8 +879,8 @@ class EquipmentParameterItem: point_dict = dict() if rows_points is not None and len(rows_points) > 0: for row in rows_points: - point_dict[row['id']] = {"id": row['id'], - "name": row['name']} + point_dict[row[0]] = {"id": row[1], + "name": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -895,10 +890,10 @@ class EquipmentParameterItem: 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 ") @@ -908,10 +903,10 @@ class EquipmentParameterItem: 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 ") @@ -921,10 +916,10 @@ class EquipmentParameterItem: 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, name, parameter_type, " " constant, point_id, numerator_meter_uuid, denominator_meter_uuid " @@ -943,35 +938,35 @@ class EquipmentParameterItem: point = None numerator_meter = None denominator_meter = None - if row['parameter_type'] == 'point': - point = point_dict.get(row['point_id'], None) + if row[2] == 'point': + point = point_dict.get(row[4], None) constant = None numerator_meter = None denominator_meter = None - elif row['parameter_type'] == 'constant': - constant = row['constant'] + elif row[2] == 'constant': + constant = row[3] point = None numerator_meter = None denominator_meter = None - elif row['parameter_type'] == 'fraction': + elif row[2] == 'fraction': constant = None point = None # find numerator meter by uuid - numerator_meter = meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = meter_dict.get(row[5], None) if numerator_meter is None: - numerator_meter = virtual_meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = virtual_meter_dict.get(row[5], None) if numerator_meter is None: - numerator_meter = offline_meter_dict.get(row['numerator_meter_uuid'], None) + numerator_meter = offline_meter_dict.get(row[5], None) # find denominator meter by uuid - denominator_meter = meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = meter_dict.get(row[6], None) if denominator_meter is None: - denominator_meter = virtual_meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = virtual_meter_dict.get(row[6], None) if denominator_meter is None: - denominator_meter = offline_meter_dict.get(row['denominator_meter_uuid'], None) + denominator_meter = offline_meter_dict.get(row[6], None) - meta_result = {"id": row['id'], - "name": row['name'], - "parameter_type": row['parameter_type'], + meta_result = {"id": row[0], + "name": row[1], + "parameter_type": row[2], "constant": constant, "point": point, "numerator_meter": numerator_meter, @@ -1096,7 +1091,7 @@ class EquipmentParameterItem: denominator_meter_uuid = str.strip(new_values['data']['denominator_meter_uuid']) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " @@ -1161,10 +1156,10 @@ class EquipmentParameterItem: 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 ") @@ -1174,10 +1169,10 @@ class EquipmentParameterItem: 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 ") @@ -1187,10 +1182,10 @@ class EquipmentParameterItem: 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]} # validate numerator meter uuid if meter_dict.get(numerator_meter_uuid) is None and \ @@ -1246,7 +1241,7 @@ class EquipmentMeterCollection: description='API.INVALID_EQUIPMENT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " @@ -1265,9 +1260,9 @@ class EquipmentMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " " FROM tbl_equipments e, tbl_equipments_meters em, tbl_meters m " @@ -1279,10 +1274,10 @@ class EquipmentMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category, - "is_output": bool(row['is_output'])} + "is_output": bool(row[4])} result.append(meta_result) resp.text = json.dumps(result) @@ -1438,7 +1433,7 @@ class EquipmentOfflineMeterCollection: description='API.INVALID_EQUIPMENT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " @@ -1457,9 +1452,9 @@ class EquipmentOfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " " FROM tbl_equipments e, tbl_equipments_offline_meters em, tbl_offline_meters m " @@ -1471,10 +1466,10 @@ class EquipmentOfflineMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category, - "is_output": bool(row['is_output'])} + "is_output": bool(row[4])} result.append(meta_result) resp.text = json.dumps(result) @@ -1630,7 +1625,7 @@ class EquipmentVirtualMeterCollection: description='API.INVALID_EQUIPMENT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_equipments " @@ -1649,9 +1644,9 @@ class EquipmentVirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id, em.is_output " " FROM tbl_equipments e, tbl_equipments_virtual_meters em, tbl_virtual_meters m " @@ -1663,10 +1658,10 @@ class EquipmentVirtualMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category, - "is_output": bool(row['is_output'])} + "is_output": bool(row[4])} result.append(meta_result) resp.text = json.dumps(result) diff --git a/myems-api/core/gateway.py b/myems-api/core/gateway.py index 0b9cf308..305989cd 100644 --- a/myems-api/core/gateway.py +++ b/myems-api/core/gateway.py @@ -21,8 +21,7 @@ class GatewayCollection: def on_get(req, resp): access_control(req) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) - + cursor = cnx.cursor() query = (" SELECT id, name, uuid, token, last_seen_datetime_utc " " FROM tbl_gateways " " ORDER BY id ") @@ -38,14 +37,14 @@ class GatewayCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - if isinstance(row['last_seen_datetime_utc'], datetime): - last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[4], datetime): + last_seen_datetime_local = row[4].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_seen_datetime = None - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], - "token": row['token'], + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], + "token": row[3], "last_seen_datetime": last_seen_datetime } result.append(meta_result) @@ -115,7 +114,7 @@ class GatewayItem: description='API.INVALID_GATEWAY_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, token, last_seen_datetime_utc " " FROM tbl_gateways " @@ -132,17 +131,17 @@ class GatewayItem: if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - if isinstance(row['last_seen_datetime_utc'], datetime): - last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[4], datetime): + last_seen_datetime_local = row[4].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_seen_datetime = None - result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "token": row['token'], + result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "token": row[3], "last_seen_datetime": last_seen_datetime} resp.text = json.dumps(result) @@ -262,7 +261,7 @@ class GatewayDataSourceCollection: description='API.INVALID_GATEWAY_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_gateways " @@ -287,17 +286,17 @@ class GatewayDataSourceCollection: rows_data_source = cursor.fetchall() if rows_data_source is not None and len(rows_data_source) > 0: for row in rows_data_source: - if isinstance(row['last_seen_datetime_utc'], datetime): - last_seen_datetime_local = row['last_seen_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[5], datetime): + last_seen_datetime_local = row[5].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_seen_datetime = None - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "protocol": row['protocol'], - "connection": row['connection'], + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "protocol": row[3], + "connection": row[4], "last_seen_datetime": last_seen_datetime, } result.append(meta_result) diff --git a/myems-api/core/knowledgefile.py b/myems-api/core/knowledgefile.py index 2f97699d..8b80a145 100644 --- a/myems-api/core/knowledgefile.py +++ b/myems-api/core/knowledgefile.py @@ -23,7 +23,7 @@ class KnowledgeFileCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT uuid, display_name " " FROM tbl_users ") @@ -35,10 +35,10 @@ class KnowledgeFileCollection: user_dict = dict() if rows is not None and len(rows) > 0: for row in rows: - user_dict[row['uuid']] = row['display_name'] + user_dict[row[0]] = row[1] cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, file_name, uuid, upload_datetime_utc, upload_user_uuid, file_object" " FROM tbl_knowledge_files " @@ -55,17 +55,17 @@ class KnowledgeFileCollection: timezone_offset = -timezone_offset 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') - upload_datetime_local = row['upload_datetime_utc'].replace(tzinfo=None) + \ + upload_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], "upload_datetime": upload_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), - "user_display_name": user_dict.get(row['upload_user_uuid'], None), - "file_size_bytes": sys.getsizeof(row['file_object']), + "user_display_name": user_dict.get(row[4], None), + "file_size_bytes": sys.getsizeof(row[5]), "file_bytes_base64": base64_message } result.append(meta_result) diff --git a/myems-api/core/menu.py b/myems-api/core/menu.py index f53715ab..acfe0bb1 100644 --- a/myems-api/core/menu.py +++ b/myems-api/core/menu.py @@ -18,7 +18,7 @@ class MenuCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, route, parent_menu_id, is_hidden " " FROM tbl_menus " @@ -29,11 +29,11 @@ class MenuCollection: result = list() if rows_menus is not None and len(rows_menus) > 0: for row in rows_menus: - temp = {"id": row['id'], - "name": row['name'], - "route": row['route'], - "parent_menu_id": row['parent_menu_id'], - "is_hidden": bool(row['is_hidden'])} + temp = {"id": row[0], + "name": row[1], + "route": row[2], + "parent_menu_id": row[3], + "is_hidden": bool(row[4])} result.append(temp) @@ -59,7 +59,7 @@ class MenuItem: description='API.INVALID_MENU_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, route, parent_menu_id, is_hidden " " FROM tbl_menus " @@ -69,11 +69,11 @@ class MenuItem: result = None if rows_menu is not None and len(rows_menu) > 0: - result = {"id": rows_menu['id'], - "name": rows_menu['name'], - "route": rows_menu['route'], - "parent_menu_id": rows_menu['parent_menu_id'], - "is_hidden": bool(rows_menu['is_hidden'])} + result = {"id": rows_menu[0], + "name": rows_menu[1], + "route": rows_menu[2], + "parent_menu_id": rows_menu[3], + "is_hidden": bool(rows_menu[4])} cursor.close() cnx.close() @@ -133,7 +133,7 @@ class MenuChildrenCollection: description='API.INVALID_MENU_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, route, parent_menu_id, is_hidden " " FROM tbl_menus " @@ -155,15 +155,15 @@ class MenuChildrenCollection: menu_dict = dict() if rows_menus is not None and len(rows_menus) > 0: for row in rows_menus: - menu_dict[row['id']] = {"id": row['id'], - "name": row['name']} + menu_dict[row[0]] = {"id": row[0], + "name": row[1]} result = dict() result['current'] = dict() - result['current']['id'] = row_current_menu['id'] - result['current']['name'] = row_current_menu['name'] - result['current']['parent_menu'] = menu_dict.get(row_current_menu['parent_menu_id'], None) - result['current']['is_hidden'] = bool(row_current_menu['is_hidden']) + result['current']['id'] = row_current_menu[0] + result['current']['name'] = row_current_menu[1] + result['current']['parent_menu'] = menu_dict.get(row_current_menu[3], None) + result['current']['is_hidden'] = bool(row_current_menu[4]) result['children'] = list() @@ -176,11 +176,11 @@ class MenuChildrenCollection: if rows_menus is not None and len(rows_menus) > 0: for row in rows_menus: - parent_menu = menu_dict.get(row['parent_menu_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], + parent_menu = menu_dict.get(row[3], None) + meta_result = {"id": row[0], + "name": row[1], "parent_menu": parent_menu, - "is_hidden": bool(row['is_hidden'])} + "is_hidden": bool(row[4])} result['children'].append(meta_result) cursor.close() @@ -201,7 +201,7 @@ class MenuWebCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, route, parent_menu_id " " FROM tbl_menus " @@ -212,8 +212,8 @@ class MenuWebCollection: first_level_routes = {} if rows_menus is not None and len(rows_menus) > 0: for row in rows_menus: - first_level_routes[row['id']] = { - 'route': row['route'], + first_level_routes[row[0]] = { + 'route': row[1], 'children': [] } @@ -225,8 +225,8 @@ class MenuWebCollection: if rows_menus is not None and len(rows_menus) > 0: for row in rows_menus: - if row['parent_menu_id'] in first_level_routes.keys(): - first_level_routes[row['parent_menu_id']]['children'].append(row['route']) + if row[2] in first_level_routes.keys(): + first_level_routes[row[2]]['children'].append(row[1]) result = dict() for _id, item in first_level_routes.items(): diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index e9c04dc3..745c97ec 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -19,7 +19,7 @@ class MeterCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -29,9 +29,9 @@ class MeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -41,9 +41,9 @@ class MeterCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -53,9 +53,9 @@ class MeterCollection: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -65,9 +65,9 @@ class MeterCollection: master_meter_dict = dict() if rows_master_meters is not None and len(rows_master_meters) > 0: for row in rows_master_meters: - master_meter_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + master_meter_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id, " " is_counted, hourly_low_limit, hourly_high_limit, " @@ -80,22 +80,22 @@ class MeterCollection: result = list() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - master_meter = master_meter_dict.get(row['master_meter_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + cost_center = cost_center_dict.get(row[7], None) + energy_item = energy_item_dict.get(row[8], None) + master_meter = master_meter_dict.get(row[9], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, - "hourly_low_limit": row['hourly_low_limit'], - "hourly_high_limit": row['hourly_high_limit'], + "is_counted": True if row[4] else False, + "hourly_low_limit": row[5], + "hourly_high_limit": row[6], "cost_center": cost_center, "energy_item": energy_item, "master_meter": master_meter, - "description": row['description'], - "qrcode": "meter:" + row['uuid']} + "description": row[10], + "qrcode": "meter:" + row[2]} result.append(meta_result) cursor.close() @@ -290,7 +290,7 @@ class MeterItem: description='API.INVALID_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -300,9 +300,9 @@ class MeterItem: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -312,9 +312,9 @@ class MeterItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -324,9 +324,9 @@ class MeterItem: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_meters ") @@ -336,9 +336,9 @@ class MeterItem: master_meter_dict = dict() if rows_master_meters is not None and len(rows_master_meters) > 0: for row in rows_master_meters: - master_meter_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + master_meter_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id, " " is_counted, hourly_low_limit, hourly_high_limit, " @@ -354,22 +354,22 @@ class MeterItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND') else: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - master_meter = master_meter_dict.get(row['master_meter_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + cost_center = cost_center_dict.get(row[7], None) + energy_item = energy_item_dict.get(row[8], None) + master_meter = master_meter_dict.get(row[9], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, - "hourly_low_limit": row['hourly_low_limit'], - "hourly_high_limit": row['hourly_high_limit'], + "is_counted": True if row[4] else False, + "hourly_low_limit": row[5], + "hourly_high_limit": row[6], "cost_center": cost_center, "energy_item": energy_item, "master_meter": master_meter, - "description": row['description'], - "qrcode": "meter:"+row['uuid']} + "description": row[10], + "qrcode": "meter:"+row[2]} resp.text = json.dumps(meta_result) @@ -766,7 +766,7 @@ class MeterSubmeterCollection: description='API.INVALID_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name, uuid " " FROM tbl_meters " @@ -779,8 +779,8 @@ class MeterSubmeterCollection: description='API.METER_NOT_FOUND') else: master_meter = {"id": id_, - "name": row['name'], - "uuid": row['uuid']} + "name": row[0], + "uuid": row[1]} query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -790,9 +790,9 @@ class MeterSubmeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -802,9 +802,9 @@ class MeterSubmeterCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -814,9 +814,9 @@ class MeterSubmeterCollection: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id, " " is_counted, hourly_low_limit, hourly_high_limit, " @@ -830,20 +830,20 @@ class MeterSubmeterCollection: result = list() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + cost_center = cost_center_dict.get(row[7], None) + energy_item = energy_item_dict.get(row[8], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, - "hourly_low_limit": row['hourly_low_limit'], - "hourly_high_limit": row['hourly_high_limit'], + "is_counted": True if row[4] else False, + "hourly_low_limit": row[5], + "hourly_high_limit": row[6], "cost_center": cost_center, "energy_item": energy_item, "master_meter": master_meter, - "description": row['description']} + "description": row[10]} result.append(meta_result) cursor.close() diff --git a/myems-api/core/offlinemeter.py b/myems-api/core/offlinemeter.py index acd0a5a4..efee02c5 100644 --- a/myems-api/core/offlinemeter.py +++ b/myems-api/core/offlinemeter.py @@ -19,7 +19,7 @@ class OfflineMeterCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -29,9 +29,9 @@ class OfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -41,9 +41,9 @@ class OfflineMeterCollection: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -53,9 +53,9 @@ class OfflineMeterCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id, " " is_counted, hourly_low_limit, hourly_high_limit, " @@ -68,19 +68,19 @@ class OfflineMeterCollection: result = list() if rows_meters is not None and len(rows_meters) > 0: for row in rows_meters: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + energy_item = energy_item_dict.get(row[7], None) + cost_center = cost_center_dict.get(row[8], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, - "hourly_low_limit": row['hourly_low_limit'], - "hourly_high_limit": row['hourly_high_limit'], + "is_counted": True if row[4] else False, + "hourly_low_limit": row[5], + "hourly_high_limit": row[6], "energy_item": energy_item, "cost_center": cost_center, - "description": row['description']} + "description": row[9]} result.append(meta_result) cursor.close() @@ -248,7 +248,7 @@ class OfflineMeterItem: description='API.INVALID_OFFLINE_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -258,9 +258,9 @@ class OfflineMeterItem: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -270,9 +270,9 @@ class OfflineMeterItem: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -282,9 +282,9 @@ class OfflineMeterItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id, " " is_counted, hourly_low_limit, hourly_high_limit, " @@ -300,19 +300,19 @@ class OfflineMeterItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.OFFLINE_METER_NOT_FOUND') else: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + energy_item = energy_item_dict.get(row[7], None) + cost_center = cost_center_dict.get(row[8], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, - "hourly_low_limit": row['hourly_low_limit'], - "hourly_high_limit": row['hourly_high_limit'], + "is_counted": True if row[4] else False, + "hourly_low_limit": row[5], + "hourly_high_limit": row[6], "energy_item": energy_item, "cost_center": cost_center, - "description": row['description']} + "description": row[9]} resp.text = json.dumps(meta_result) diff --git a/myems-api/core/point.py b/myems-api/core/point.py index cc8a85f4..a2c834b5 100644 --- a/myems-api/core/point.py +++ b/myems-api/core/point.py @@ -20,7 +20,7 @@ class PointCollection: """Handles GET requests""" access_control(req) cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_data_sources ") @@ -30,9 +30,9 @@ class PointCollection: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, data_source_id, object_type, units, " " high_limit, low_limit, ratio, is_trend, is_virtual, address, description " @@ -45,19 +45,19 @@ class PointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - data_source = data_source_dict.get(row['data_source_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], + data_source = data_source_dict.get(row[2], None) + meta_result = {"id": row[0], + "name": row[1], "data_source": data_source, - "object_type": row['object_type'], - "units": row['units'], - "high_limit": row['high_limit'], - "low_limit": row['low_limit'], - "ratio": float(row['ratio']), - "is_trend": bool(row['is_trend']), - "is_virtual": bool(row['is_virtual']), - "address": row['address'], - "description": row['description']} + "object_type": row[3], + "units": row[4], + "high_limit": row[5], + "low_limit": row[6], + "ratio": float(row[7]), + "is_trend": bool(row[8]), + "is_virtual": bool(row[9]), + "address": row[10], + "description": row[11]} result.append(meta_result) resp.text = json.dumps(result) @@ -216,7 +216,7 @@ class PointItem: description='API.INVALID_POINT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_data_sources ") @@ -226,9 +226,9 @@ class PointItem: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, data_source_id, object_type, units, " " high_limit, low_limit, ratio, is_trend, is_virtual, address, description " @@ -242,19 +242,19 @@ class PointItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.POINT_NOT_FOUND') - data_source = data_source_dict.get(row['data_source_id'], None) - result = {"id": row['id'], - "name": row['name'], + data_source = data_source_dict.get(row[2], None) + result = {"id": row[0], + "name": row[1], "data_source": data_source, - "object_type": row['object_type'], - "units": row['units'], - "high_limit": row['high_limit'], - "low_limit": row['low_limit'], - "ratio": float(row['ratio']), - "is_trend": bool(row['is_trend']), - "is_virtual": bool(row['is_virtual']), - "address": row['address'], - "description": row['description']} + "object_type": row[3], + "units": row[4], + "high_limit": row[5], + "low_limit": row[6], + "ratio": float(row[7]), + "is_trend": bool(row[8]), + "is_virtual": bool(row[9]), + "address": row[10], + "description": row[11]} resp.text = json.dumps(result) @staticmethod diff --git a/myems-api/core/rule.py b/myems-api/core/rule.py index 881ca38a..23faccc8 100644 --- a/myems-api/core/rule.py +++ b/myems-api/core/rule.py @@ -22,7 +22,7 @@ class RuleCollection: """Handles GET requests""" access_control(req) cnx = mysql.connector.connect(**config.myems_fdd_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, " " category, fdd_code, priority, " @@ -42,25 +42,25 @@ class RuleCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - if isinstance(row['last_run_datetime_utc'], datetime): - last_run_datetime_local = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[10], datetime): + last_run_datetime_local = row[10].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_run_datetime = last_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_run_datetime = None - if isinstance(row['next_run_datetime_utc'], datetime): - next_run_datetime_local = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[11], datetime): + next_run_datetime_local = row[11].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) next_run_datetime = next_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: next_run_datetime = None - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], - "category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'], - "channel": row['channel'], "expression": row['expression'], - "message_template": row['message_template'].replace("
", ""), - "is_enabled": bool(row['is_enabled']), + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], + "category": row[3], "fdd_code": row[4], "priority": row[5], + "channel": row[6], "expression": row[7], + "message_template": row[8].replace("
", ""), + "is_enabled": bool(row[9]), "last_run_datetime": last_run_datetime, "next_run_datetime": next_run_datetime, } @@ -204,7 +204,7 @@ class RuleItem: description='API.INVALID_RULE_ID') cnx = mysql.connector.connect(**config.myems_fdd_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, " " category, fdd_code, priority, " @@ -223,25 +223,25 @@ class RuleItem: if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - if isinstance(row['last_run_datetime_utc'], datetime): - last_run_datetime_local = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[10], datetime): + last_run_datetime_local = row[10].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) last_run_datetime = last_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: last_run_datetime = None - if isinstance(row['next_run_datetime_utc'], datetime): - next_run_datetime_local = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + if isinstance(row[11], datetime): + next_run_datetime_local = row[11].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) next_run_datetime = next_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') else: next_run_datetime = None - result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], - "category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'], - "channel": row['channel'], "expression": row['expression'], - "message_template": row['message_template'].replace("
", ""), - "is_enabled": bool(row['is_enabled']), + result = {"id": row[0], "name": row[1], "uuid": row[2], + "category": row[3], "fdd_code": row[4], "priority": row[5], + "channel": row[6], "expression": row[7], + "message_template": row[8].replace("
", ""), + "is_enabled": bool(row[9]), "last_run_datetime": last_run_datetime, "next_run_datetime": next_run_datetime, } diff --git a/myems-api/core/sensor.py b/myems-api/core/sensor.py index 5dba9441..d0e65357 100644 --- a/myems-api/core/sensor.py +++ b/myems-api/core/sensor.py @@ -19,7 +19,7 @@ class SensorCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, description " " FROM tbl_sensors " @@ -30,10 +30,10 @@ class SensorCollection: result = list() if rows_sensors is not None and len(rows_sensors) > 0: for row in rows_sensors: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "description": row['description']} + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "description": row[3]} result.append(meta_result) cursor.close() @@ -110,7 +110,7 @@ class SensorItem: description='API.INVALID_SENSOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, description " " FROM tbl_sensors " @@ -124,10 +124,10 @@ class SensorItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SENSOR_NOT_FOUND') else: - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "description": row['description']} + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "description": row[3]} resp.text = json.dumps(meta_result) diff --git a/myems-api/core/shopfloor.py b/myems-api/core/shopfloor.py index f3ec62fb..9de81e07 100644 --- a/myems-api/core/shopfloor.py +++ b/myems-api/core/shopfloor.py @@ -19,7 +19,7 @@ class ShopfloorCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -29,9 +29,9 @@ class ShopfloorCollection: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -41,9 +41,9 @@ class ShopfloorCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " area, is_input_counted, " @@ -56,17 +56,17 @@ class ShopfloorCollection: result = list() if rows_shopfloors is not None and len(rows_shopfloors) > 0: for row in rows_shopfloors: - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "area": row['area'], - "is_input_counted": bool(row['is_input_counted']), + contact = contact_dict.get(row[5], None) + cost_center = cost_center_dict.get(row[6], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "area": row[3], + "is_input_counted": bool(row[4]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": "shopfloor:" + row['uuid']} + "description": row[7], + "qrcode": "shopfloor:" + row[2]} result.append(meta_result) cursor.close() @@ -202,7 +202,7 @@ class ShopfloorItem: description='API.INVALID_SHOPFLOOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -212,9 +212,9 @@ class ShopfloorItem: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -224,9 +224,9 @@ class ShopfloorItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " area, is_input_counted, contact_id, cost_center_id, description " @@ -241,17 +241,17 @@ class ShopfloorItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SHOPFLOOR_NOT_FOUND') else: - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "area": row['area'], - "is_input_counted": bool(row['is_input_counted']), + contact = contact_dict.get(row[5], None) + cost_center = cost_center_dict.get(row[6], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "area": row[3], + "is_input_counted": bool(row[4]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": "shopfloor:" + row['uuid']} + "description": row[7], + "qrcode": "shopfloor:" + row[2]} resp.text = json.dumps(meta_result) @@ -685,7 +685,7 @@ class ShopfloorMeterCollection: description='API.INVALID_SHOPFLOOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_shopfloors " @@ -704,9 +704,9 @@ class ShopfloorMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_shopfloors s, tbl_shopfloors_meters sm, tbl_meters m " @@ -718,8 +718,8 @@ class ShopfloorMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -869,7 +869,7 @@ class ShopfloorOfflineMeterCollection: description='API.INVALID_SHOPFLOOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_shopfloors " @@ -888,9 +888,9 @@ class ShopfloorOfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_shopfloors s, tbl_shopfloors_offline_meters sm, tbl_offline_meters m " @@ -902,8 +902,8 @@ class ShopfloorOfflineMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -1054,7 +1054,7 @@ class ShopfloorPointCollection: description='API.INVALID_SHOPFLOOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_shopfloors " @@ -1073,9 +1073,9 @@ class ShopfloorPointCollection: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT p.id, p.name, p.data_source_id " " FROM tbl_shopfloors s, tbl_shopfloors_points sp, tbl_points p " @@ -1087,8 +1087,8 @@ class ShopfloorPointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - data_source = data_source_dict.get(row['data_source_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "data_source": data_source} + data_source = data_source_dict.get(row[2], None) + meta_result = {"id": row[0], "name": row[1], "data_source": data_source} result.append(meta_result) resp.text = json.dumps(result) @@ -1408,7 +1408,7 @@ class ShopfloorVirtualMeterCollection: description='API.INVALID_SHOPFLOOR_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_shopfloors " @@ -1427,9 +1427,9 @@ class ShopfloorVirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_shopfloors s, tbl_shopfloors_virtual_meters sm, tbl_virtual_meters m " @@ -1441,8 +1441,8 @@ class ShopfloorVirtualMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) diff --git a/myems-api/core/space.py b/myems-api/core/space.py index 52e25d28..58994785 100644 --- a/myems-api/core/space.py +++ b/myems-api/core/space.py @@ -22,7 +22,7 @@ class SpaceCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_spaces ") @@ -32,9 +32,9 @@ class SpaceCollection: space_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - space_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + space_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, utc_offset " " FROM tbl_timezones ") @@ -44,9 +44,9 @@ class SpaceCollection: timezone_dict = dict() if rows_timezones is not None and len(rows_timezones) > 0: for row in rows_timezones: - timezone_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "utc_offset": row['utc_offset']} + timezone_dict[row[0]] = {"id": row[0], + "name": row[1], + "utc_offset": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -56,9 +56,9 @@ class SpaceCollection: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -68,9 +68,9 @@ class SpaceCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " parent_space_id, area, timezone_id, is_input_counted, is_output_counted, " @@ -83,22 +83,22 @@ class SpaceCollection: result = list() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - timezone = timezone_dict.get(row['timezone_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - parent_space = space_dict.get(row['parent_space_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + timezone = timezone_dict.get(row[5], None) + contact = contact_dict.get(row[8], None) + cost_center = cost_center_dict.get(row[9], None) + parent_space = space_dict.get(row[3], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "parent_space": parent_space, - "area": row['area'], + "area": row[4], "timezone": timezone, - "is_input_counted": bool(row['is_input_counted']), - "is_output_counted": bool(row['is_output_counted']), + "is_input_counted": bool(row[6]), + "is_output_counted": bool(row[7]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": "space:" + row['uuid']} + "description": row[10], + "qrcode": "space:" + row[2]} result.append(meta_result) cursor.close() @@ -278,7 +278,7 @@ class SpaceItem: description='API.INVALID_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_spaces ") @@ -288,9 +288,9 @@ class SpaceItem: space_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - space_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + space_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, utc_offset " " FROM tbl_timezones ") @@ -300,9 +300,9 @@ class SpaceItem: timezone_dict = dict() if rows_timezones is not None and len(rows_timezones) > 0: for row in rows_timezones: - timezone_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "utc_offset": row['utc_offset']} + timezone_dict[row[0]] = {"id": row[0], + "name": row[1], + "utc_offset": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -312,9 +312,9 @@ class SpaceItem: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -324,9 +324,9 @@ class SpaceItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " parent_space_id, area, timezone_id, is_input_counted, is_output_counted, " @@ -342,22 +342,22 @@ class SpaceItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.SPACE_NOT_FOUND') else: - parent_space = space_dict.get(row['parent_space_id'], None) - timezone = timezone_dict.get(row['timezone_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + parent_space = space_dict.get(row[3], None) + timezone = timezone_dict.get(row[5], None) + contact = contact_dict.get(row[8], None) + cost_center = cost_center_dict.get(row[9], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "parent_space_id": parent_space, - "area": row['area'], + "area": row[4], "timezone": timezone, - "is_input_counted": bool(row['is_input_counted']), - "is_output_counted": bool(row['is_output_counted']), + "is_input_counted": bool(row[6]), + "is_output_counted": bool(row[7]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": "space:" + row['uuid']} + "description": row[10], + "qrcode": "space:" + row[2]} resp.text = json.dumps(meta_result) @@ -709,7 +709,7 @@ class SpaceChildrenCollection: description='API.INVALID_SPACE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid, " " parent_space_id, area, timezone_id, is_input_counted, is_output_counted, " @@ -733,9 +733,9 @@ class SpaceChildrenCollection: space_dict = dict() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - space_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + space_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, utc_offset " " FROM tbl_timezones ") @@ -745,9 +745,9 @@ class SpaceChildrenCollection: timezone_dict = dict() if rows_timezones is not None and len(rows_timezones) > 0: for row in rows_timezones: - timezone_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "utc_offset": row['utc_offset']} + timezone_dict[row[0]] = {"id": row[0], + "name": row[1], + "utc_offset": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -757,9 +757,9 @@ class SpaceChildrenCollection: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -769,23 +769,23 @@ class SpaceChildrenCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} result = dict() result['current'] = dict() - result['current']['id'] = row_current_space['id'] - result['current']['name'] = row_current_space['name'] - result['current']['uuid'] = row_current_space['uuid'] - result['current']['parent_space'] = space_dict.get(row_current_space['parent_space_id'], None) - result['current']['area'] = row_current_space['area'] - result['current']['timezone'] = timezone_dict.get(row_current_space['timezone_id'], None) - result['current']['is_input_counted'] = bool(row_current_space['is_input_counted']) - result['current']['is_output_counted'] = bool(row_current_space['is_output_counted']) - result['current']['contact'] = contact_dict.get(row_current_space['contact_id'], None) - result['current']['cost_center'] = cost_center_dict.get(row_current_space['cost_center_id'], None) - result['current']['description'] = row_current_space['description'] - result['current']['qrcode'] = 'space:' + row_current_space['uuid'] + result['current']['id'] = row_current_space[0] + result['current']['name'] = row_current_space[1] + result['current']['uuid'] = row_current_space[2] + result['current']['parent_space'] = space_dict.get(row_current_space[3], None) + result['current']['area'] = row_current_space[4] + result['current']['timezone'] = timezone_dict.get(row_current_space[5], None) + result['current']['is_input_counted'] = bool(row_current_space[6]) + result['current']['is_output_counted'] = bool(row_current_space[7]) + result['current']['contact'] = contact_dict.get(row_current_space[8], None) + result['current']['cost_center'] = cost_center_dict.get(row_current_space[9], None) + result['current']['description'] = row_current_space[10] + result['current']['qrcode'] = 'space:' + row_current_space[2] result['children'] = list() @@ -800,22 +800,22 @@ class SpaceChildrenCollection: if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - timezone = timezone_dict.get(row['timezone_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - parent_space = space_dict.get(row['parent_space_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], + timezone = timezone_dict.get(row[5], None) + contact = contact_dict.get(row[8], None) + cost_center = cost_center_dict.get(row[9], None) + parent_space = space_dict.get(row[3], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], "parent_space": parent_space, - "area": row['area'], + "area": row[4], "timezone": timezone, - "is_input_counted": bool(row['is_input_counted']), - "is_output_counted": bool(row['is_output_counted']), + "is_input_counted": bool(row[6]), + "is_output_counted": bool(row[7]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": 'space:' + row['uuid']} + "description": row[10], + "qrcode": 'space:' + row[2]} result['children'].append(meta_result) cursor.close() @@ -1181,7 +1181,7 @@ class SpaceMeterCollection: description='API.INVALID_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 " @@ -1200,9 +1200,9 @@ class SpaceMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_spaces s, tbl_spaces_meters sm, tbl_meters m " @@ -1214,8 +1214,8 @@ class SpaceMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -1367,7 +1367,7 @@ class SpaceOfflineMeterCollection: description='API.INVALID_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 " @@ -1386,9 +1386,9 @@ class SpaceOfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_spaces s, tbl_spaces_offline_meters sm, tbl_offline_meters m " @@ -1400,8 +1400,8 @@ class SpaceOfflineMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -1552,7 +1552,7 @@ class SpacePointCollection: description='API.INVALID_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 " @@ -1571,9 +1571,9 @@ class SpacePointCollection: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT p.id, p.name, p.data_source_id " " FROM tbl_spaces s, tbl_spaces_points sp, tbl_points p " @@ -1585,8 +1585,8 @@ class SpacePointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - data_source = data_source_dict.get(row['data_source_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "data_source": data_source} + data_source = data_source_dict.get(row[2], None) + meta_result = {"id": row[0], "name": row[1], "data_source": data_source} result.append(meta_result) resp.text = json.dumps(result) @@ -2416,7 +2416,7 @@ class SpaceVirtualMeterCollection: description='API.INVALID_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 " @@ -2435,9 +2435,9 @@ class SpaceVirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_spaces s, tbl_spaces_virtual_meters sm, tbl_virtual_meters m " @@ -2449,8 +2449,8 @@ class SpaceVirtualMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -2678,7 +2678,7 @@ class SpaceTreeCollection: description='API.PRIVILEGE_NOT_FOUND') # get all spaces cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, parent_space_id " " FROM tbl_spaces " @@ -2688,8 +2688,8 @@ class SpaceTreeCollection: 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]) cursor.close() cnx.close() diff --git a/myems-api/core/store.py b/myems-api/core/store.py index 89086b11..ac448e55 100644 --- a/myems-api/core/store.py +++ b/myems-api/core/store.py @@ -19,7 +19,7 @@ class StoreCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_store_types ") @@ -29,9 +29,9 @@ class StoreCollection: store_type_dict = dict() if rows_store_types is not None and len(rows_store_types) > 0: for row in rows_store_types: - store_type_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + store_type_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -41,9 +41,9 @@ class StoreCollection: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -53,9 +53,9 @@ class StoreCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " address, latitude, longitude, area, store_type_id, " @@ -68,23 +68,23 @@ class StoreCollection: result = list() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - store_type = store_type_dict.get(row['store_type_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) + store_type = store_type_dict.get(row[7], None) + contact = contact_dict.get(row[9], None) + cost_center = cost_center_dict.get(row[10], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "address": row['address'], - "latitude": row['latitude'], - "longitude": row['longitude'], - "area": row['area'], + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "address": row[3], + "latitude": row[4], + "longitude": row[5], + "area": row[6], "store_type": store_type, - "is_input_counted": bool(row['is_input_counted']), + "is_input_counted": bool(row[8]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": 'store:' + row['uuid']} + "description": row[11], + "qrcode": 'store:' + row[2]} result.append(meta_result) cursor.close() @@ -263,7 +263,7 @@ class StoreItem: description='API.INVALID_STORE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_store_types ") @@ -273,9 +273,9 @@ class StoreItem: store_type_dict = dict() if rows_store_types is not None and len(rows_store_types) > 0: for row in rows_store_types: - store_type_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + store_type_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -285,9 +285,9 @@ class StoreItem: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -297,9 +297,9 @@ class StoreItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " address, latitude, longitude, area, store_type_id," @@ -316,22 +316,22 @@ class StoreItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.STORE_NOT_FOUND') else: - store_type = store_type_dict.get(row['store_type_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "address": row['address'], - "latitude": row['latitude'], - "longitude": row['longitude'], - "area": row['area'], + store_type = store_type_dict.get(row[7], None) + contact = contact_dict.get(row[9], None) + cost_center = cost_center_dict.get(row[10], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "address": row[3], + "latitude": row[4], + "longitude": row[5], + "area": row[6], "store_type": store_type, - "is_input_counted": bool(row['is_input_counted']), + "is_input_counted": bool(row[8]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": 'store:' + row['uuid']} + "description": row[11], + "qrcode": 'store:' + row[2]} resp.text = json.dumps(meta_result) @@ -625,7 +625,7 @@ class StoreMeterCollection: description='API.INVALID_STORE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_stores " @@ -644,9 +644,9 @@ class StoreMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_stores t, tbl_stores_meters tm, tbl_meters m " @@ -658,8 +658,8 @@ class StoreMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -809,7 +809,7 @@ class StoreOfflineMeterCollection: description='API.INVALID_STORE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_stores " @@ -828,9 +828,9 @@ class StoreOfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_stores s, tbl_stores_offline_meters sm, tbl_offline_meters m " @@ -842,8 +842,8 @@ class StoreOfflineMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -994,7 +994,7 @@ class StorePointCollection: description='API.INVALID_STORE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_stores " @@ -1013,9 +1013,9 @@ class StorePointCollection: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT p.id, p.name, p.data_source_id " " FROM tbl_stores t, tbl_stores_points tp, tbl_points p " @@ -1027,8 +1027,8 @@ class StorePointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - data_source = data_source_dict.get(row['data_source_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "data_source": data_source} + data_source = data_source_dict.get(row[2], None) + meta_result = {"id": row[0], "name": row[1], "data_source": data_source} result.append(meta_result) resp.text = json.dumps(result) @@ -1348,7 +1348,7 @@ class StoreVirtualMeterCollection: description='API.INVALID_STORE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_stores " @@ -1367,9 +1367,9 @@ class StoreVirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[1], + "name": row[2], + "uuid": row[3]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_stores t, tbl_stores_virtual_meters tm, tbl_virtual_meters m " @@ -1381,8 +1381,8 @@ class StoreVirtualMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) diff --git a/myems-api/core/tariff.py b/myems-api/core/tariff.py index d741b9cc..45c06afe 100644 --- a/myems-api/core/tariff.py +++ b/myems-api/core/tariff.py @@ -20,7 +20,7 @@ class TariffCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT t.id, t.name, t.uuid, " " ec.id AS energy_category_id, ec.name AS energy_category_name, " @@ -39,17 +39,15 @@ class TariffCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - valid_from = row['valid_from_datetime_utc'].replace(tzinfo=timezone.utc) + \ - timedelta(minutes=timezone_offset) - valid_through = row['valid_through_datetime_utc'].replace(tzinfo=timezone.utc) + \ - timedelta(minutes=timezone_offset) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "energy_category": {"id": row['energy_category_id'], - "name": row['energy_category_name']}, - "tariff_type": row['tariff_type'], - "unit_of_price": row['unit_of_price'], + valid_from = row[7].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset) + valid_through = row[8].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "energy_category": {"id": row[3], + "name": row[4]}, + "tariff_type": row[5], + "unit_of_price": row[6], "valid_from": valid_from.strftime('%Y-%m-%dT%H:%M:%S'), "valid_through": valid_through.strftime('%Y-%m-%dT%H:%M:%S')} @@ -63,9 +61,9 @@ class TariffCollection: rows_block = cursor.fetchall() if rows_block is not None and len(rows_block) > 0: for row_block in rows_block: - meta_data = {"start_amount": row_block['start_amount'], - "end_amount": row_block['end_amount'], - "price": row_block['price']} + meta_data = {"start_amount": row_block[0], + "end_amount": row_block[1], + "price": row_block[2]} meta_result['block'].append(meta_data) elif meta_result['tariff_type'] == 'timeofuse': @@ -78,10 +76,10 @@ class TariffCollection: rows_timeofuses = cursor.fetchall() if rows_timeofuses is not None and len(rows_timeofuses) > 0: for row_timeofuse in rows_timeofuses: - meta_data = {"start_time_of_day": str(row_timeofuse['start_time_of_day']), - "end_time_of_day": str(row_timeofuse['end_time_of_day']), - "peak_type": row_timeofuse['peak_type'], - "price": row_timeofuse['price']} + meta_data = {"start_time_of_day": str(row_timeofuse[0]), + "end_time_of_day": str(row_timeofuse[1]), + "peak_type": row_timeofuse[2], + "price": row_timeofuse[3]} meta_result['timeofuse'].append(meta_data) else: cursor.close() @@ -239,7 +237,7 @@ class TariffItem: description='API.INVALID_TARIFF_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT t.id, t.name, t.uuid, " " ec.id AS energy_category_id, ec.name AS energy_category_name, " @@ -260,18 +258,16 @@ class TariffItem: if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - valid_from = row['valid_from_datetime_utc'].replace(tzinfo=timezone.utc) + \ - timedelta(minutes=timezone_offset) - valid_through = row['valid_through_datetime_utc'].replace(tzinfo=timezone.utc) + \ - timedelta(minutes=timezone_offset) + valid_from = row[7].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset) + valid_through = row[8].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset) - result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "energy_category": {"id": row['energy_category_id'], - "name": row['energy_category_name']}, - "tariff_type": row['tariff_type'], - "unit_of_price": row['unit_of_price'], + result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "energy_category": {"id": row[3], + "name": row[4]}, + "tariff_type": row[5], + "unit_of_price": row[6], "valid_from": valid_from.strftime('%Y-%m-%dT%H:%M:%S'), "valid_through": valid_through.strftime('%Y-%m-%dT%H:%M:%S')} @@ -285,9 +281,9 @@ class TariffItem: rows_block = cursor.fetchall() if rows_block is not None and len(rows_block) > 0: for row_block in rows_block: - meta_data = {"start_amount": row_block['start_amount'], - "end_amount": row_block['end_amount'], - "price": row_block['price']} + meta_data = {"start_amount": row_block[0], + "end_amount": row_block[1], + "price": row_block[2]} result['block'].append(meta_data) elif result['tariff_type'] == 'timeofuse': @@ -299,10 +295,10 @@ class TariffItem: rows_timeofuses = cursor.fetchall() if rows_timeofuses is not None and len(rows_timeofuses) > 0: for row_timeofuse in rows_timeofuses: - meta_data = {"start_time_of_day": str(row_timeofuse['start_time_of_day']), - "end_time_of_day": str(row_timeofuse['end_time_of_day']), - "peak_type": row_timeofuse['peak_type'], - "price": row_timeofuse['price']} + meta_data = {"start_time_of_day": str(row_timeofuse[0]), + "end_time_of_day": str(row_timeofuse[1]), + "peak_type": row_timeofuse[2], + "price": row_timeofuse[3]} result['timeofuse'].append(meta_data) cursor.close() diff --git a/myems-api/core/tenant.py b/myems-api/core/tenant.py index 698d5e42..e4508920 100644 --- a/myems-api/core/tenant.py +++ b/myems-api/core/tenant.py @@ -20,7 +20,7 @@ class TenantCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_tenant_types ") @@ -30,9 +30,9 @@ class TenantCollection: tenant_type_dict = dict() if rows_tenant_types is not None and len(rows_tenant_types) > 0: for row in rows_tenant_types: - tenant_type_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + tenant_type_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -42,9 +42,9 @@ class TenantCollection: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -54,9 +54,9 @@ class TenantCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " buildings, floors, rooms, area, tenant_type_id, " @@ -75,33 +75,33 @@ class TenantCollection: result = list() if rows_spaces is not None and len(rows_spaces) > 0: for row in rows_spaces: - tenant_type = tenant_type_dict.get(row['tenant_type_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) + tenant_type = tenant_type_dict.get(row[7], None) + contact = contact_dict.get(row[14], None) + cost_center = cost_center_dict.get(row[15], None) - lease_start_datetime_local = row['lease_start_datetime_utc'].replace(tzinfo=timezone.utc) + \ + lease_start_datetime_local = row[11].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) - lease_end_datetime_local = row['lease_end_datetime_utc'].replace(tzinfo=timezone.utc) + \ + lease_end_datetime_local = row[12].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "buildings": row['buildings'], - "floors": row['floors'], - "rooms": row['rooms'], - "area": row['area'], + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "buildings": row[3], + "floors": row[4], + "rooms": row[5], + "area": row[6], "tenant_type": tenant_type, - "is_input_counted": bool(row['is_input_counted']), - "is_key_tenant": bool(row['is_key_tenant']), - "lease_number": row['lease_number'], + "is_input_counted": bool(row[8]), + "is_key_tenant": bool(row[9]), + "lease_number": row[10], "lease_start_datetime": lease_start_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), "lease_end_datetime": lease_end_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), - "is_in_lease": bool(row['is_in_lease']), + "is_in_lease": bool(row[13]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": 'tenant:' + row['uuid']} + "description": row[16], + "qrcode": 'tenant:' + row[2]} result.append(meta_result) cursor.close() @@ -316,7 +316,7 @@ class TenantItem: description='API.INVALID_TENANT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_tenant_types ") @@ -326,9 +326,9 @@ class TenantItem: tenant_type_dict = dict() if rows_tenant_types is not None and len(rows_tenant_types) > 0: for row in rows_tenant_types: - tenant_type_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + tenant_type_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_contacts ") @@ -338,9 +338,9 @@ class TenantItem: contact_dict = dict() if rows_contacts is not None and len(rows_contacts) > 0: for row in rows_contacts: - contact_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + contact_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -350,9 +350,9 @@ class TenantItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, " " buildings, floors, rooms, area, tenant_type_id," @@ -370,35 +370,35 @@ class TenantItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.TENANT_NOT_FOUND') else: - tenant_type = tenant_type_dict.get(row['tenant_type_id'], None) - contact = contact_dict.get(row['contact_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) + tenant_type = tenant_type_dict.get(row[7], None) + contact = contact_dict.get(row[14], None) + cost_center = cost_center_dict.get(row[15], None) timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) if config.utc_offset[0] == '-': timezone_offset = -timezone_offset - lease_start_datetime_local = row['lease_start_datetime_utc'].replace(tzinfo=timezone.utc) + \ + lease_start_datetime_local = row[11].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) - lease_end_datetime_local = row['lease_end_datetime_utc'].replace(tzinfo=timezone.utc) + \ + lease_end_datetime_local = row[12].replace(tzinfo=timezone.utc) + \ timedelta(minutes=timezone_offset) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "buildings": row['buildings'], - "floors": row['floors'], - "rooms": row['rooms'], - "area": row['area'], + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "buildings": row[3], + "floors": row[4], + "rooms": row[5], + "area": row[6], "tenant_type": tenant_type, - "is_input_counted": bool(row['is_input_counted']), - "is_key_tenant": bool(row['is_key_tenant']), - "lease_number": row['lease_number'], + "is_key_tenant": bool(row[8]), + "is_input_counted": bool(row[9]), + "lease_number": row[10], "lease_start_datetime": lease_start_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), "lease_end_datetime": lease_end_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'), - "is_in_lease": bool(row['is_in_lease']), + "is_in_lease": bool(row[13]), "contact": contact, "cost_center": cost_center, - "description": row['description'], - "qrcode": 'tenant:' + row['uuid']} + "description": row[16], + "qrcode": 'tenant:' + row[2]} resp.text = json.dumps(meta_result) @@ -728,7 +728,7 @@ class TenantMeterCollection: description='API.INVALID_TENANT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_tenants " @@ -747,9 +747,9 @@ class TenantMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_tenants t, tbl_tenants_meters tm, tbl_meters m " @@ -761,8 +761,8 @@ class TenantMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -912,7 +912,7 @@ class TenantOfflineMeterCollection: description='API.INVALID_TENANT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_tenants " @@ -931,9 +931,9 @@ class TenantOfflineMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_tenants s, tbl_tenants_offline_meters sm, tbl_offline_meters m " @@ -945,8 +945,8 @@ class TenantOfflineMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) @@ -1097,7 +1097,7 @@ class TenantPointCollection: description='API.INVALID_TENANT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_tenants " @@ -1116,9 +1116,9 @@ class TenantPointCollection: data_source_dict = dict() if rows_data_sources is not None and len(rows_data_sources) > 0: for row in rows_data_sources: - data_source_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + data_source_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT p.id, p.name, p.data_source_id " " FROM tbl_tenants t, tbl_tenants_points tp, tbl_points p " @@ -1130,8 +1130,8 @@ class TenantPointCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - data_source = data_source_dict.get(row['data_source_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "data_source": data_source} + data_source = data_source_dict.get(row[2], None) + meta_result = {"id": row[0], "name": row[1], "data_source": data_source} result.append(meta_result) resp.text = json.dumps(result) @@ -1451,7 +1451,7 @@ class TenantVirtualMeterCollection: description='API.INVALID_TENANT_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() cursor.execute(" SELECT name " " FROM tbl_tenants " @@ -1470,9 +1470,9 @@ class TenantVirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT m.id, m.name, m.uuid, m.energy_category_id " " FROM tbl_tenants t, tbl_tenants_virtual_meters tm, tbl_virtual_meters m " @@ -1484,8 +1484,8 @@ class TenantVirtualMeterCollection: result = list() if rows is not None and len(rows) > 0: for row in rows: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], + energy_category = energy_category_dict.get(row[3], None) + meta_result = {"id": row[0], "name": row[1], "uuid": row[2], "energy_category": energy_category} result.append(meta_result) diff --git a/myems-api/core/textmessage.py b/myems-api/core/textmessage.py index 2817b7bd..85283361 100644 --- a/myems-api/core/textmessage.py +++ b/myems-api/core/textmessage.py @@ -81,7 +81,8 @@ class TextMessageCollection: "recipient_mobile": row[2], "message": row[3], "created_datetime": row[4].timestamp() * 1000 if isinstance(row[4], datetime) else None, - "scheduled_datetime": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, + "scheduled_datetime": + row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, "acknowledge_code": row[6], "status": row[7]} result.append(meta_result) diff --git a/myems-api/core/user.py b/myems-api/core/user.py index 968288fa..ee6996f3 100644 --- a/myems-api/core/user.py +++ b/myems-api/core/user.py @@ -883,15 +883,13 @@ class Unlock: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_ID') - Id = id_ - cnx = mysql.connector.connect(**config.myems_user_db) cursor = cnx.cursor() query = (" SELECT failed_login_count " " FROM tbl_users " " WHERE id = %s ") - cursor.execute(query, (Id,)) + cursor.execute(query, (id_,)) row = cursor.fetchone() if row is None: cursor.close() @@ -907,13 +905,13 @@ class Unlock: update_user = (" UPDATE tbl_users " " SET failed_login_count = 0" " WHERE id = %s ") - cursor.execute(update_user, (Id, )) + cursor.execute(update_user, (id_, )) cnx.commit() query = (" SELECT failed_login_count " " FROM tbl_users " " WHERE id = %s ") - cursor.execute(query, (Id,)) + cursor.execute(query, (id_,)) row = cursor.fetchone() if row is None or row[0] != 0: cursor.close() @@ -925,4 +923,4 @@ class Unlock: resp.text = json.dumps("OK") resp.status = falcon.HTTP_200 write_log(user_uuid=admin_user_uuid, request_method='PUT', resource_type='UnlockUser', - resource_id=Id, request_body=None) \ No newline at end of file + resource_id=id_, request_body=None) diff --git a/myems-api/core/virtualmeter.py b/myems-api/core/virtualmeter.py index a7ebfd5a..3a302b20 100644 --- a/myems-api/core/virtualmeter.py +++ b/myems-api/core/virtualmeter.py @@ -19,7 +19,7 @@ class VirtualMeterCollection: @staticmethod def on_get(req, resp): cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -29,9 +29,9 @@ class VirtualMeterCollection: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_energy_items ") @@ -41,9 +41,9 @@ class VirtualMeterCollection: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -53,9 +53,9 @@ class VirtualMeterCollection: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, equation, energy_category_id, is_counted, cost_center_id, " " energy_item_id, description " @@ -67,18 +67,18 @@ class VirtualMeterCollection: result = list() if rows_virtual_meters is not None and len(rows_virtual_meters) > 0: for row in rows_virtual_meters: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "equation": row['equation'], + energy_category = energy_category_dict.get(row[4], None) + cost_center = cost_center_dict.get(row[6], None) + energy_item = energy_item_dict.get(row[7], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "equation": row[3], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, + "is_counted": True if row[5] else False, "cost_center": cost_center, "energy_item": energy_item, - "description": row['description'], + "description": row[8], "expression": {}} expression = dict() @@ -94,42 +94,42 @@ class VirtualMeterCollection: rows_variables = cursor.fetchall() if rows_variables is not None: for row_variable in rows_variables: - if row_variable['meter_type'].lower() == 'meter': + if row_variable[2].lower() == 'meter': query_meter = (" SELECT m.name " " FROM tbl_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) - elif row_variable['meter_type'].lower() == 'offline_meter': + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) + elif row_variable[2].lower() == 'offline_meter': query_meter = (" SELECT m.name " " FROM tbl_offline_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) - elif row_variable['meter_type'].lower() == 'virtual_meter': + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) + elif row_variable[2].lower() == 'virtual_meter': query_meter = (" SELECT m.name " " FROM tbl_virtual_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) meta_result['expression'] = expression result.append(meta_result) @@ -354,7 +354,7 @@ class VirtualMeterItem: description='API.INVALID_VIRTUAL_METER_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT id, name, uuid " " FROM tbl_energy_categories ") @@ -364,9 +364,9 @@ class VirtualMeterItem: energy_category_dict = dict() if rows_energy_categories is not None and len(rows_energy_categories) > 0: for row in rows_energy_categories: - energy_category_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_category_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, energy_category_id " " FROM tbl_energy_items ") @@ -376,9 +376,9 @@ class VirtualMeterItem: energy_item_dict = dict() if rows_energy_items is not None and len(rows_energy_items) > 0: for row in rows_energy_items: - energy_item_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + energy_item_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid " " FROM tbl_cost_centers ") @@ -388,9 +388,9 @@ class VirtualMeterItem: cost_center_dict = dict() if rows_cost_centers is not None and len(rows_cost_centers) > 0: for row in rows_cost_centers: - cost_center_dict[row['id']] = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid']} + cost_center_dict[row[0]] = {"id": row[0], + "name": row[1], + "uuid": row[2]} query = (" SELECT id, name, uuid, equation, energy_category_id, is_counted, cost_center_id, " " energy_item_id, description " @@ -402,18 +402,18 @@ class VirtualMeterItem: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.VIRTUAL_METER_NOT_FOUND') else: - energy_category = energy_category_dict.get(row['energy_category_id'], None) - cost_center = cost_center_dict.get(row['cost_center_id'], None) - energy_item = energy_item_dict.get(row['energy_item_id'], None) - meta_result = {"id": row['id'], - "name": row['name'], - "uuid": row['uuid'], - "equation": row['equation'], + energy_category = energy_category_dict.get(row[4], None) + cost_center = cost_center_dict.get(row[6], None) + energy_item = energy_item_dict.get(row[7], None) + meta_result = {"id": row[0], + "name": row[1], + "uuid": row[2], + "equation": row[3], "energy_category": energy_category, - "is_counted": True if row['is_counted'] else False, + "is_counted": True if row[5] else False, "cost_center": cost_center, "energy_item": energy_item, - "description": row['description'], + "description": row[8], "expression": {}} expression = dict() @@ -429,42 +429,42 @@ class VirtualMeterItem: rows_variables = cursor.fetchall() if rows_variables is not None: for row_variable in rows_variables: - if row_variable['meter_type'].lower() == 'meter': + if row_variable[2].lower() == 'meter': query_meter = (" SELECT m.name " " FROM tbl_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) - elif row_variable['meter_type'].lower() == 'offline_meter': + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) + elif row_variable[2].lower() == 'offline_meter': query_meter = (" SELECT m.name " " FROM tbl_offline_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) - elif row_variable['meter_type'].lower() == 'virtual_meter': + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) + elif row_variable[2].lower() == 'virtual_meter': query_meter = (" SELECT m.name " " FROM tbl_virtual_meters m " " WHERE m.id = %s ") - cursor.execute(query_meter, (row_variable['meter_id'],)) + cursor.execute(query_meter, (row_variable[3],)) row_meter = cursor.fetchone() if row_meter is not None: - expression['variables'].append({'id': row_variable['id'], - 'name': row_variable['name'], - 'meter_type': row_variable['meter_type'], - 'meter_id': row_variable['meter_id'], - 'meter_name': row_meter['name']}) + expression['variables'].append({'id': row_variable[0], + 'name': row_variable[1], + 'meter_type': row_variable[2], + 'meter_id': row_variable[3], + 'meter_name': row_meter[0]}) meta_result['expression'] = expression diff --git a/myems-api/core/webmessage.py b/myems-api/core/webmessage.py index fcf1545d..022412c8 100644 --- a/myems-api/core/webmessage.py +++ b/myems-api/core/webmessage.py @@ -68,7 +68,7 @@ class WebMessageCollection: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -84,7 +84,7 @@ class WebMessageCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -106,7 +106,7 @@ class WebMessageCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() @@ -169,7 +169,7 @@ class WebMessageStatusNewCollection: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -185,7 +185,7 @@ class WebMessageStatusNewCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -207,7 +207,7 @@ class WebMessageStatusNewCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() @@ -286,7 +286,7 @@ class WebMessageStatusNewCollection: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -302,7 +302,7 @@ class WebMessageStatusNewCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -324,7 +324,7 @@ class WebMessageStatusNewCollection: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() @@ -386,7 +386,7 @@ class WebMessageItem: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -402,7 +402,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -424,7 +424,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() @@ -506,7 +506,7 @@ class WebMessageItem: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -522,7 +522,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -544,7 +544,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() @@ -594,7 +594,7 @@ class WebMessageItem: description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') cnx = mysql.connector.connect(**config.myems_user_db) - cursor = cnx.cursor(dictionary=True) + cursor = cnx.cursor() query = (" SELECT utc_expires " " FROM tbl_sessions " @@ -610,7 +610,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_SESSION_PLEASE_RE_LOGIN') else: - utc_expires = row['utc_expires'] + utc_expires = row[0] if datetime.utcnow() > utc_expires: if cursor: cursor.close() @@ -632,7 +632,7 @@ class WebMessageItem: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_USER_PLEASE_RE_LOGIN') else: - user_id = row['id'] + user_id = row[0] if cursor: cursor.close() diff --git a/myems-api/core/wechatmessage.py b/myems-api/core/wechatmessage.py index 0ea65b0f..db82af60 100644 --- a/myems-api/core/wechatmessage.py +++ b/myems-api/core/wechatmessage.py @@ -83,8 +83,10 @@ class WechatMessageCollection(object): "recipient_openid": row[2], "message_template_id": row[3], "message_data": row[4], - "created_datetime_utc": row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, - "scheduled_datetime_utc": row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, + "created_datetime_utc": + row[5].timestamp() * 1000 if isinstance(row[5], datetime) else None, + "scheduled_datetime_utc": + row[6].timestamp() * 1000 if isinstance(row[6], datetime) else None, "acknowledge_code": row[7], "status": row[8]} result.append(meta_result)