diff --git a/myems-api/core/equipment.py b/myems-api/core/equipment.py
index 8a3c42477824efec2d21bf8e4a931bd0b8841fe0..629e40a3d246a8e5e6a06616368f10486a373ba6 100644
--- a/myems-api/core/equipment.py
+++ b/myems-api/core/equipment.py
@@ -51,13 +51,12 @@ class EquipmentCollection:
result = list()
if rows_equipments is not None and len(rows_equipments) > 0:
for row in rows_equipments:
- cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]),
- "cost_center": cost_center,
+ "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6],
"camera_url": row[7],
"description": row[8],
@@ -225,13 +224,12 @@ class EquipmentItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND')
else:
- cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]),
- "cost_center": cost_center,
+ "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6],
"camera_url": row[7],
"description": row[8],
@@ -1332,9 +1330,10 @@ class EquipmentMeterCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
result.append(meta_result)
@@ -1530,9 +1529,10 @@ class EquipmentOfflineMeterCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
result.append(meta_result)
@@ -1729,9 +1729,10 @@ class EquipmentVirtualMeterCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
result.append(meta_result)
@@ -1916,7 +1917,9 @@ class EquipmentCommandCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2]}
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2]}
result.append(meta_result)
resp.text = json.dumps(result)
@@ -2098,13 +2101,12 @@ class EquipmentExport:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND')
else:
- cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]),
- "cost_center": cost_center,
+ "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6],
"camera_url": row[7],
"description": row[8],
@@ -2124,7 +2126,9 @@ class EquipmentExport:
command_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- result = {"id": row[0], "name": row[1], "uuid": row[2]}
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2]}
command_result.append(result)
meta_result['commands'] = command_result
@@ -2150,9 +2154,10 @@ class EquipmentExport:
meter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
meter_result.append(result)
meta_result['meters'] = meter_result
@@ -2166,9 +2171,10 @@ class EquipmentExport:
offlinemeter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
offlinemeter_result.append(result)
meta_result['offline_meters'] = offlinemeter_result
@@ -2182,9 +2188,10 @@ class EquipmentExport:
virtualmeter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
virtualmeter_result.append(result)
meta_result['virtual_meters'] = virtualmeter_result
@@ -2686,13 +2693,12 @@ class EquipmentClone:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.EQUIPMENT_NOT_FOUND')
else:
- cost_center = cost_center_dict.get(row[5], None)
meta_result = {"id": row[0],
"name": row[1],
"uuid": row[2],
"is_input_counted": bool(row[3]),
"is_output_counted": bool(row[4]),
- "cost_center": cost_center,
+ "cost_center": cost_center_dict.get(row[5], None),
"svg": row[6],
"camera_url": row[7],
"description": row[8],
@@ -2712,7 +2718,9 @@ class EquipmentClone:
command_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- result = {"id": row[0], "name": row[1], "uuid": row[2]}
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2]}
command_result.append(result)
meta_result['commands'] = command_result
@@ -2738,9 +2746,10 @@ class EquipmentClone:
meter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
meter_result.append(result)
meta_result['meters'] = meter_result
@@ -2754,9 +2763,10 @@ class EquipmentClone:
offlinemeter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
offlinemeter_result.append(result)
meta_result['offline_meters'] = offlinemeter_result
@@ -2770,9 +2780,10 @@ class EquipmentClone:
virtualmeter_result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- energy_category = energy_category_dict.get(row[3], None)
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "energy_category": energy_category,
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "energy_category": energy_category_dict.get(row[3], None),
"is_output": bool(row[4])}
virtualmeter_result.append(result)
meta_result['virtual_meters'] = virtualmeter_result
diff --git a/myems-api/core/gateway.py b/myems-api/core/gateway.py
index 9b90ee35f63629f2062d47728b4410bed2cd8b86..7555b1632eb3b997922d690ad6dafdc41cc37fb0 100644
--- a/myems-api/core/gateway.py
+++ b/myems-api/core/gateway.py
@@ -43,7 +43,9 @@ class GatewayCollection:
last_seen_datetime = last_seen_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
else:
last_seen_datetime = None
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2],
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
"token": row[3],
"last_seen_datetime": last_seen_datetime,
"description": row[5]
diff --git a/myems-api/core/point.py b/myems-api/core/point.py
index 52ce077f4ae613475ee27d98a1378cc6fd52f26a..a1693e6a1cd0d952cc97ba7a13cf7bdaadfaac4a 100644
--- a/myems-api/core/point.py
+++ b/myems-api/core/point.py
@@ -47,10 +47,9 @@ class PointCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- data_source = data_source_dict.get(row[2], None)
meta_result = {"id": row[0],
"name": row[1],
- "data_source": data_source,
+ "data_source": data_source_dict.get(row[2], None),
"object_type": row[3],
"units": row[4],
"high_limit": row[5],
@@ -273,10 +272,9 @@ class PointItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND')
- data_source = data_source_dict.get(row[2], None)
result = {"id": row[0],
"name": row[1],
- "data_source": data_source,
+ "data_source": data_source_dict.get(row[2], None),
"object_type": row[3],
"units": row[4],
"high_limit": row[5],
@@ -909,10 +907,9 @@ class PointExport:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND')
- data_source = data_source_dict.get(row[2], None)
result = {"id": row[0],
"name": row[1],
- "data_source": data_source,
+ "data_source": data_source_dict.get(row[2], None),
"object_type": row[3],
"units": row[4],
"high_limit": row[5],
@@ -1143,10 +1140,9 @@ class PointClone:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.POINT_NOT_FOUND')
- data_source = data_source_dict.get(row[2], None)
result = {"id": row[0],
"name": row[1],
- "data_source": data_source,
+ "data_source": data_source_dict.get(row[2], None),
"object_type": row[3],
"units": row[4],
"high_limit": row[5],
diff --git a/myems-api/core/rule.py b/myems-api/core/rule.py
index a5dde5460e1db56738dd78b8ad5c853598e2e3fc..7028ee0091188c99729f84449b593a5389db1af0 100644
--- a/myems-api/core/rule.py
+++ b/myems-api/core/rule.py
@@ -56,9 +56,14 @@ class RuleCollection:
else:
next_run_datetime = None
- meta_result = {"id": row[0], "name": row[1], "uuid": row[2],
- "category": row[3], "fdd_code": row[4], "priority": row[5],
- "channel": row[6], "expression": row[7],
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "category": row[3],
+ "fdd_code": row[4],
+ "priority": row[5],
+ "channel": row[6],
+ "expression": row[7],
"message_template": row[8].replace("
", ""),
"is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime,
@@ -248,9 +253,14 @@ class RuleItem:
else:
next_run_datetime = None
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "category": row[3], "fdd_code": row[4], "priority": row[5],
- "channel": row[6], "expression": row[7],
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "category": row[3],
+ "fdd_code": row[4],
+ "priority": row[5],
+ "channel": row[6],
+ "expression": row[7],
"message_template": row[8].replace("
", ""),
"is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime,
@@ -523,9 +533,14 @@ class RuleExport:
else:
next_run_datetime = None
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "category": row[3], "fdd_code": row[4], "priority": row[5],
- "channel": row[6], "expression": row[7],
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "category": row[3],
+ "fdd_code": row[4],
+ "priority": row[5],
+ "channel": row[6],
+ "expression": row[7],
"message_template": row[8].replace("
", ""),
"is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime,
@@ -722,9 +737,14 @@ class RuleClone:
else:
next_run_datetime = None
- result = {"id": row[0], "name": row[1], "uuid": row[2],
- "category": row[3], "fdd_code": row[4], "priority": row[5],
- "channel": row[6], "expression": row[7],
+ result = {"id": row[0],
+ "name": row[1],
+ "uuid": row[2],
+ "category": row[3],
+ "fdd_code": row[4],
+ "priority": row[5],
+ "channel": row[6],
+ "expression": row[7],
"message_template": row[8].replace("
", ""),
"is_enabled": bool(row[9]),
"last_run_datetime": last_run_datetime,
diff --git a/myems-api/core/timezone.py b/myems-api/core/timezone.py
index 3bd52e18880ea654272015d3d39cde0086ee331b..aa17ee0796e1368d812dd5d1356a82e49e9c3057 100644
--- a/myems-api/core/timezone.py
+++ b/myems-api/core/timezone.py
@@ -36,7 +36,10 @@ class TimezoneCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- meta_result = {"id": row[0], "name": row[1], "description": row[2], "utc_offset": row[3]}
+ meta_result = {"id": row[0],
+ "name": row[1],
+ "description": row[2],
+ "utc_offset": row[3]}
result.append(meta_result)
resp.text = json.dumps(result)
@@ -78,7 +81,10 @@ class TimezoneItem:
raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
description='API.TIMEZONE_NOT_FOUND')
- result = {"id": row[0], "name": row[1], "description": row[2], "utc_offset": row[3]}
+ result = {"id": row[0],
+ "name": row[1],
+ "description": row[2],
+ "utc_offset": row[3]}
cursor.close()
cnx.close()
diff --git a/myems-api/core/user.py b/myems-api/core/user.py
index f382d811e0e9a57d6afbb3d88a51774d74b2f6e2..024a8aab6c6cd39bb53b980367e916b95dfa057c 100644
--- a/myems-api/core/user.py
+++ b/myems-api/core/user.py
@@ -44,10 +44,6 @@ class UserCollection:
result = list()
if rows is not None and len(rows) > 0:
for row in rows:
- account_expiration_datetime_local = row[9].replace(tzinfo=timezone.utc) + \
- timedelta(minutes=timezone_offset)
- password_expiration_datetime_local = row[10].replace(tzinfo=timezone.utc) + \
- timedelta(minutes=timezone_offset)
meta_result = {"id": row[0],
"name": row[1],
"display_name": row[2],
@@ -59,9 +55,9 @@ class UserCollection:
"id": row[7],
"name": row[8]} if row[7] is not None else None,
"account_expiration_datetime":
- account_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'),
+ (row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"password_expiration_datetime":
- password_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'),
+ (row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"is_locked": True if row[11] >= config.maximum_failed_login_count else False}
result.append(meta_result)
@@ -255,9 +251,6 @@ class UserItem:
if config.utc_offset[0] == '-':
timezone_offset = -timezone_offset
- account_expiration_datetime_local = row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)
- password_expiration_datetime_local = row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)
-
result = {"id": row[0],
"name": row[1],
"display_name": row[2],
@@ -269,9 +262,9 @@ class UserItem:
"id": row[7],
"name": row[8]} if row[7] is not None else None,
"account_expiration_datetime":
- account_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'),
+ (row[9].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"password_expiration_datetime":
- password_expiration_datetime_local.strftime('%Y-%m-%dT%H:%M:%S'),
+ (row[10].replace(tzinfo=timezone.utc) + timedelta(minutes=timezone_offset)).strftime('%Y-%m-%dT%H:%M:%S'),
"is_locked": True if row[11] >= config.maximum_failed_login_count else False}
resp.text = json.dumps(result)