From f9b72c6997174cd961c9dbb883cb4eae46ec135e Mon Sep 17 00:00:00 2001 From: "13621160019@163.com" <13621160019@163.com> Date: Fri, 7 May 2021 09:00:13 +0800 Subject: [PATCH] added is_virtual to point in myems-api --- myems-api/MyEMS.postman_collection.json | 181 +++++++++++++++++++++++- myems-api/core/datasource.py | 25 ++-- myems-api/core/point.py | 28 +++- 3 files changed, 214 insertions(+), 20 deletions(-) diff --git a/myems-api/MyEMS.postman_collection.json b/myems-api/MyEMS.postman_collection.json index 045dfc1e..250b4ad0 100644 --- a/myems-api/MyEMS.postman_collection.json +++ b/myems-api/MyEMS.postman_collection.json @@ -3400,7 +3400,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\"data\":{\"name\":\"ModbusPoint2\", \"data_source_id\":1, \"object_type\": \"ENERGY_VALUE\", \"units\":\"kWh\", \"high_limit\":999999999, \"low_limit\":0, \"ratio\":1,\"is_trend\":true, \"address\":\"{\\\"slave_id\\\":1, \\\"function_code\\\":3, \\\"offset\\\":1, \\\"number_of_registers\\\":2, \\\"data_format\\\":\\\"float\\\"}\", \"description\":null}}" + "raw": "{\"data\":{\"name\":\"ModbusPoint2\", \"data_source_id\":1, \"object_type\": \"ENERGY_VALUE\", \"units\":\"kWh\", \"high_limit\":999999999, \"low_limit\":0, \"ratio\":1,\"is_trend\":true, \"is_virtual\":false, \"address\":\"{\\\"slave_id\\\":1, \\\"function_code\\\":3, \\\"offset\\\":1, \\\"number_of_registers\\\":2, \\\"data_format\\\":\\\"float\\\"}\", \"description\":null}}" }, "url": { "raw": "{{base_url}}/points", @@ -3439,7 +3439,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\"data\":{\"name\":\"ModbusPoint1\", \"data_source_id\":1, \"object_type\": \"ENERGY_VALUE\", \"units\":\"kWh\", \"high_limit\":999999999, \"low_limit\":0, \"ratio\":100, \"is_trend\":true, \"address\":\"{\\\"slave_id\\\":1, \\\"function_code\\\":3, \\\"offset\\\":1, \\\"number_of_registers\\\":2, \\\"data_format\\\":\\\"float\\\"}\", \"description\":null}}" + "raw": "{\"data\":{\"name\":\"ModbusPoint1\", \"data_source_id\":1, \"object_type\": \"ENERGY_VALUE\", \"units\":\"kWh\", \"high_limit\":999999999, \"low_limit\":0, \"ratio\":100, \"is_trend\":true, \"is_virtual\":false, \"address\":\"{\\\"slave_id\\\":1, \\\"function_code\\\":3, \\\"offset\\\":1, \\\"number_of_registers\\\":2, \\\"data_format\\\":\\\"float\\\"}\", \"description\":null}}" }, "url": { "raw": "{{base_url}}/points/1", @@ -7079,6 +7079,98 @@ }, "response": [] }, + { + "name": "GET Combined Equipment Efficiency Report", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{base_url}}/reports/combinedequipmentefficiency?combinedequipmentid=1000001&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00", + "host": [ + "{{base_url}}" + ], + "path": [ + "reports", + "combinedequipmentefficiency" + ], + "query": [ + { + "key": "combinedequipmentid", + "value": "1000001" + }, + { + "key": "periodtype", + "value": "daily" + }, + { + "key": "baseperiodstartdatetime", + "value": "2020-08-01T00:00:00" + }, + { + "key": "baseperiodenddatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodstartdatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodenddatetime", + "value": "2020-10-01T00:00:00" + } + ] + } + }, + "response": [] + }, + { + "name": "GET Combined Equipment Efficiency Report (Quick Mode)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{base_url}}/reports/combinedequipmentefficiency?combinedequipmentid=1000001&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00&quickmode=true", + "host": [ + "{{base_url}}" + ], + "path": [ + "reports", + "combinedequipmentefficiency" + ], + "query": [ + { + "key": "combinedequipmentid", + "value": "1000001" + }, + { + "key": "periodtype", + "value": "daily" + }, + { + "key": "baseperiodstartdatetime", + "value": "2020-08-01T00:00:00" + }, + { + "key": "baseperiodenddatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodstartdatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodenddatetime", + "value": "2020-10-01T00:00:00" + }, + { + "key": "quickmode", + "value": "true" + } + ] + } + }, + "response": [] + }, { "name": "GET Dashboard", "request": { @@ -7749,6 +7841,47 @@ { "key": "reportingperiodenddatetime", "value": "2020-09-11T00:00:00" + }, + { + "key": "", + "value": null, + "disabled": true + } + ] + } + }, + "response": [] + }, + { + "name": "GET Meter Trend Report (Quick Mode)", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{base_url}}/reports/metertrend?meterid=6&reportingperiodstartdatetime=2020-09-10T00:00:00&reportingperiodenddatetime=2020-09-11T00:00:00&quickmode=true", + "host": [ + "{{base_url}}" + ], + "path": [ + "reports", + "metertrend" + ], + "query": [ + { + "key": "meterid", + "value": "6" + }, + { + "key": "reportingperiodstartdatetime", + "value": "2020-09-10T00:00:00" + }, + { + "key": "reportingperiodenddatetime", + "value": "2020-09-11T00:00:00" + }, + { + "key": "quickmode", + "value": "true" } ] } @@ -8646,6 +8779,50 @@ } }, "response": [] + }, + { + "name": "GET Equipment Efficiency Report Copy", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{base_url}}/reports/equipmentefficiency?equipmentid=1&periodtype=daily&baseperiodstartdatetime=2020-08-01T00:00:00&baseperiodenddatetime=2020-09-01T00:00:00&reportingperiodstartdatetime=2020-09-01T00:00:00&reportingperiodenddatetime=2020-10-01T00:00:00", + "host": [ + "{{base_url}}" + ], + "path": [ + "reports", + "equipmentefficiency" + ], + "query": [ + { + "key": "equipmentid", + "value": "1" + }, + { + "key": "periodtype", + "value": "daily" + }, + { + "key": "baseperiodstartdatetime", + "value": "2020-08-01T00:00:00" + }, + { + "key": "baseperiodenddatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodstartdatetime", + "value": "2020-09-01T00:00:00" + }, + { + "key": "reportingperiodenddatetime", + "value": "2020-10-01T00:00:00" + } + ] + } + }, + "response": [] } ] }, diff --git a/myems-api/core/datasource.py b/myems-api/core/datasource.py index 6f91284b..b1611a87 100644 --- a/myems-api/core/datasource.py +++ b/myems-api/core/datasource.py @@ -323,7 +323,7 @@ class DataSourcePointCollection: description='API.INVALID_DATA_SOURCE_ID') cnx = mysql.connector.connect(**config.myems_system_db) - cursor = cnx.cursor() + cursor = cnx.cursor(dictionary=True) cursor.execute(" SELECT name " " FROM tbl_data_sources " @@ -338,7 +338,7 @@ class DataSourcePointCollection: # Get points of the data source # NOTE: there is no uuid in tbl_points query_point = (" SELECT id, name, object_type, " - " units, high_limit, low_limit, ratio, is_trend, address, description " + " units, high_limit, low_limit, ratio, is_trend, is_virtual, address, description " " FROM tbl_points " " WHERE data_source_id = %s " " ORDER BY name ") @@ -347,16 +347,17 @@ class DataSourcePointCollection: if rows_point is not None and len(rows_point) > 0: for row in rows_point: - meta_result = {"id": row[0], - "name": row[1], - "object_type": row[2], - "units": row[3], - "high_limit": row[4], - "low_limit": row[5], - "ratio": float(row[6]), - "is_trend": True if row[7] else False, - "address": row[8], - "description": row[9]} + meta_result = {"id": row['id'], + "name": row['name'], + "object_type": row['object_type'], + "units": row['units'], + "high_limit": row['high_limit'], + "low_limit": row['low_limit'], + "ratio": float(row['ratio']), + "is_trend": bool(row['is_trend']), + "is_virtual": bool(row['is_virtual']), + "address": row['address'], + "description": row['description']} result.append(meta_result) cursor.close() diff --git a/myems-api/core/point.py b/myems-api/core/point.py index 4d935589..3a1bf934 100644 --- a/myems-api/core/point.py +++ b/myems-api/core/point.py @@ -31,7 +31,7 @@ class PointCollection: "uuid": row['uuid']} query = (" SELECT id, name, data_source_id, object_type, units, " - " high_limit, low_limit, ratio, is_trend, address, description " + " high_limit, low_limit, ratio, is_trend, is_virtual, address, description " " FROM tbl_points ") cursor.execute(query) rows = cursor.fetchall() @@ -50,7 +50,8 @@ class PointCollection: "high_limit": row['high_limit'], "low_limit": row['low_limit'], "ratio": float(row['ratio']), - "is_trend": row['is_trend'], + "is_trend": bool(row['is_trend']), + "is_virtual": bool(row['is_virtual']), "address": row['address'], "description": row['description']} result.append(meta_result) @@ -122,6 +123,12 @@ class PointCollection: description='API.INVALID_IS_TREND_VALUE') is_trend = new_values['data']['is_trend'] + if 'is_virtual' not in new_values['data'].keys() or \ + not isinstance(new_values['data']['is_virtual'], bool): + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_IS_VIRTUAL_VALUE') + is_virtual = new_values['data']['is_virtual'] + if 'address' not in new_values['data'].keys() or \ not isinstance(new_values['data']['address'], str) or \ len(str.strip(new_values['data']['address'])) == 0: @@ -159,8 +166,8 @@ class PointCollection: add_value = (" INSERT INTO tbl_points (name, data_source_id, " " object_type, units, high_limit, low_limit, ratio, " - " is_trend, address, description) " - " VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ") + " is_trend, is_virtual, address, description) " + " VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ") cursor.execute(add_value, (name, data_source_id, object_type, @@ -169,6 +176,7 @@ class PointCollection: low_limit, ratio, is_trend, + is_virtual, address, description)) new_id = cursor.lastrowid @@ -211,7 +219,7 @@ class PointItem: "uuid": row['uuid']} query = (" SELECT id, name, data_source_id, object_type, units, " - " high_limit, low_limit, ratio, is_trend, address, description " + " high_limit, low_limit, ratio, is_trend, is_virtual, address, description " " FROM tbl_points " " WHERE id = %s ") cursor.execute(query, (id_,)) @@ -232,6 +240,7 @@ class PointItem: "low_limit": row['low_limit'], "ratio": float(row['ratio']), "is_trend": bool(row['is_trend']), + "is_virtual": bool(row['is_virtual']), "address": row['address'], "description": row['description']} resp.body = json.dumps(result) @@ -443,6 +452,12 @@ class PointItem: description='API.INVALID_IS_TREND_VALUE') is_trend = new_values['data']['is_trend'] + if 'is_virtual' not in new_values['data'].keys() or \ + not isinstance(new_values['data']['is_virtual'], bool): + raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', + description='API.INVALID_IS_VIRTUAL_VALUE') + is_virtual = new_values['data']['is_virtual'] + if 'address' not in new_values['data'].keys() or \ not isinstance(new_values['data']['address'], str) or \ len(str.strip(new_values['data']['address'])) == 0: @@ -491,7 +506,7 @@ class PointItem: " SET name = %s, data_source_id = %s, " " object_type = %s, units = %s, " " high_limit = %s, low_limit = %s, ratio = %s, " - " is_trend = %s, address = %s, description = %s " + " is_trend = %s, is_virtual = %s, address = %s, description = %s " " WHERE id = %s ") cursor.execute(update_row, (name, data_source_id, @@ -501,6 +516,7 @@ class PointItem: low_limit, ratio, is_trend, + is_virtual, address, description, id_,))