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