Merge branch 'develop'
commit
d17c1ddbe2
|
@ -19,7 +19,7 @@ class CombinedEquipmentCollection:
|
||||||
@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 CombinedEquipmentCollection:
|
||||||
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['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, "
|
||||||
" is_input_counted, is_output_counted, "
|
" is_input_counted, is_output_counted, "
|
||||||
|
@ -44,15 +44,15 @@ class CombinedEquipmentCollection:
|
||||||
result = list()
|
result = list()
|
||||||
if rows_combined_equipments is not None and len(rows_combined_equipments) > 0:
|
if rows_combined_equipments is not None and len(rows_combined_equipments) > 0:
|
||||||
for row in rows_combined_equipments:
|
for row in rows_combined_equipments:
|
||||||
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": 'combinedequipment:' + row['uuid']}
|
"qrcode": 'combinedequipment:' + row[2]}
|
||||||
result.append(meta_result)
|
result.append(meta_result)
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
@ -164,7 +164,7 @@ class CombinedEquipmentItem:
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_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 CombinedEquipmentItem:
|
||||||
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['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, "
|
||||||
" is_input_counted, is_output_counted, "
|
" is_input_counted, is_output_counted, "
|
||||||
|
@ -192,15 +192,15 @@ class CombinedEquipmentItem:
|
||||||
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND',
|
||||||
description='API.COMBINED_EQUIPMENT_NOT_FOUND')
|
description='API.COMBINED_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": 'combinedequipment:' + row['uuid']}
|
"qrcode": 'combinedequipment:' + row[2]}
|
||||||
|
|
||||||
resp.text = json.dumps(meta_result)
|
resp.text = json.dumps(meta_result)
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ class CombinedEquipmentItem:
|
||||||
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_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
" WHERE id = %s ", (id_,))
|
" WHERE id = %s ", (id_,))
|
||||||
|
@ -419,12 +419,12 @@ class CombinedEquipmentItem:
|
||||||
" (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()
|
||||||
|
|
||||||
|
@ -439,8 +439,8 @@ class CombinedEquipmentItem:
|
||||||
" 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()
|
||||||
|
@ -457,8 +457,8 @@ class CombinedEquipmentItem:
|
||||||
" 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()
|
||||||
|
@ -475,8 +475,8 @@ class CombinedEquipmentItem:
|
||||||
" 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()
|
||||||
|
@ -494,24 +494,24 @@ class CombinedEquipmentItem:
|
||||||
" 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[2]) + ","
|
||||||
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), "
|
||||||
|
|
||||||
|
@ -713,7 +713,7 @@ class CombinedEquipmentParameterCollection:
|
||||||
description='API.INVALID_COMBINED_EQUIPMENT_ID')
|
description='API.INVALID_COMBINED_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_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
|
@ -732,8 +732,8 @@ 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['id'],
|
point_dict[row['id']] = {"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 ")
|
||||||
|
@ -743,10 +743,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 ")
|
||||||
|
@ -756,10 +756,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 ")
|
||||||
|
@ -769,10 +769,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 "
|
||||||
|
@ -789,35 +789,35 @@ class CombinedEquipmentParameterCollection:
|
||||||
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,
|
||||||
|
@ -892,7 +892,7 @@ class CombinedEquipmentParameterCollection:
|
||||||
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_combined_equipments "
|
" FROM tbl_combined_equipments "
|
||||||
|
@ -943,10 +943,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 ")
|
||||||
|
@ -956,10 +956,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 ")
|
||||||
|
@ -969,10 +969,10 @@ class CombinedEquipmentParameterCollection:
|
||||||
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 \
|
||||||
|
|
Loading…
Reference in New Issue