From 8552741d17c85f8a75768fb808d768f5856c1d5e Mon Sep 17 00:00:00 2001 From: Sudershan Date: Tue, 14 Dec 2021 19:57:14 -0500 Subject: [PATCH 1/6] Minor bug fixes --- .../DataService/app/rest_api/timeseries.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/buildingdepot/DataService/app/rest_api/timeseries.py b/buildingdepot/DataService/app/rest_api/timeseries.py index 9f926fc8..623cd46b 100755 --- a/buildingdepot/DataService/app/rest_api/timeseries.py +++ b/buildingdepot/DataService/app/rest_api/timeseries.py @@ -59,7 +59,6 @@ def get(self, name): if fields: fields = fields.split(';') original_fields = fields - fields = '"' + '", "'.join(fields) + '"' else: fields = '*' @@ -75,20 +74,26 @@ def get(self, name): fields = ','.join(allowed_fields) name = r.get('parent:{}'.format(name)) + if not fields: + return jsonify(responses.no_allowed_fields) + if resolution: - if fields == '*': - return jsonify('TODO: Fields are not supported with resolution') try: - query = 'select mean(*) from "' + name + '" where (time>\'' + timestamp_to_time_string( + if fields is not '*' and fields: + fields = '/(' + '|'.join(fields.split(',')) + ')-*/' + query = 'select mean('+fields+') from "' + name + '" where (time>\'' + timestamp_to_time_string( float(start_time)) \ + '\' and time<\'' + timestamp_to_time_string( float(end_time)) + '\')' + " GROUP BY time(" + resolution + ")" + print('\n\n' + '{s:{c}^{n}}'.format(s=' InfluxDB Query ', n=100, c='#')) + print(query) + print('#' * 100 + '\n\n') data = influx.query(query) except influxdb.exceptions.InfluxDBClientError: return jsonify(responses.resolution_high) else: - if fields is not '*': - fields = '"' + '", "'.join(fields.split(',')) + '"' + if fields is not '*' and fields: + fields = '/(' + '|'.join(fields.split(',')) + ')-*/' query = 'select ' + fields + ' from "' + name + '" where time>\'' + timestamp_to_time_string(float(start_time)) \ + '\' and time<\'' + timestamp_to_time_string(float(end_time)) + '\'' @@ -104,6 +109,7 @@ def get(self, name): # print (data.raw) # print ('#' * 100 + '\n\n') response.update({'data': data.raw}) + del response["data"]["statement_id"] return jsonify(response) From b5e54037832ab3d00dcee75377f22fc7a65fee58 Mon Sep 17 00:00:00 2001 From: Sudershan Date: Tue, 14 Dec 2021 19:59:41 -0500 Subject: [PATCH 2/6] bug fixes --- buildingdepot/DataService/app/rest_api/timeseries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildingdepot/DataService/app/rest_api/timeseries.py b/buildingdepot/DataService/app/rest_api/timeseries.py index 623cd46b..c2470931 100755 --- a/buildingdepot/DataService/app/rest_api/timeseries.py +++ b/buildingdepot/DataService/app/rest_api/timeseries.py @@ -85,9 +85,9 @@ def get(self, name): float(start_time)) \ + '\' and time<\'' + timestamp_to_time_string( float(end_time)) + '\')' + " GROUP BY time(" + resolution + ")" - print('\n\n' + '{s:{c}^{n}}'.format(s=' InfluxDB Query ', n=100, c='#')) - print(query) - print('#' * 100 + '\n\n') + # print('\n\n' + '{s:{c}^{n}}'.format(s=' InfluxDB Query ', n=100, c='#')) + # print(query) + # print('#' * 100 + '\n\n') data = influx.query(query) except influxdb.exceptions.InfluxDBClientError: return jsonify(responses.resolution_high) From 2e27e8f62e89ac096e0d7136246372c017162289 Mon Sep 17 00:00:00 2001 From: Sudershan Date: Fri, 24 Dec 2021 18:51:54 -0500 Subject: [PATCH 3/6] minor bug fixes --- buildingdepot/DataService/app/rest_api/app_subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildingdepot/DataService/app/rest_api/app_subscription.py b/buildingdepot/DataService/app/rest_api/app_subscription.py index 7135062f..6f409603 100755 --- a/buildingdepot/DataService/app/rest_api/app_subscription.py +++ b/buildingdepot/DataService/app/rest_api/app_subscription.py @@ -68,7 +68,7 @@ def post(self): except Exception as e: print "Failed to end RabbitMQ session" + str(e) - return jsonify(responses.success_true) + return jsonify(responses.success_true) return jsonify(responses.application_does_not_exist) From 639104d859fa18e9f3d02751c8c143648ad5f661 Mon Sep 17 00:00:00 2001 From: Sudershan Date: Wed, 1 Jun 2022 19:33:27 -0400 Subject: [PATCH 4/6] updates pip_package list --- pip_packages.list | 1 + 1 file changed, 1 insertion(+) diff --git a/pip_packages.list b/pip_packages.list index 9d04a43f..0bfeefce 100644 --- a/pip_packages.list +++ b/pip_packages.list @@ -35,3 +35,4 @@ sphinxcontrib-websupport==1.1.2 typing==3.7.4.1 uWSGI==2.0.18 validate-email==1.2 +firebase-admin==5.2.0 From a99e2256aac7a53d785729be9ed58b8c6ee8b739 Mon Sep 17 00:00:00 2001 From: Sudershan Date: Wed, 1 Jun 2022 19:52:51 -0400 Subject: [PATCH 5/6] updates pip_package list --- pip_packages.list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pip_packages.list b/pip_packages.list index 0bfeefce..1a7e22f8 100644 --- a/pip_packages.list +++ b/pip_packages.list @@ -35,4 +35,4 @@ sphinxcontrib-websupport==1.1.2 typing==3.7.4.1 uWSGI==2.0.18 validate-email==1.2 -firebase-admin==5.2.0 +firebase-admin==2.18.0 From 364790fbeaee319b082e899cfee523eaeb89e46a Mon Sep 17 00:00:00 2001 From: Sudershan Date: Wed, 1 Jun 2022 21:15:20 -0400 Subject: [PATCH 6/6] bug fixes for timeseries API --- buildingdepot/DataService/app/rest_api/timeseries.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/buildingdepot/DataService/app/rest_api/timeseries.py b/buildingdepot/DataService/app/rest_api/timeseries.py index c2470931..5a8d91ba 100755 --- a/buildingdepot/DataService/app/rest_api/timeseries.py +++ b/buildingdepot/DataService/app/rest_api/timeseries.py @@ -170,7 +170,10 @@ def post(self): if type(sample[key]) is list: length = len(sample[key]) for i in range(length): - sample.update({"%s-%d" % (key, i): sample[key][i]}) + if isinstance(sample[key][i], basestring): + sample.update({"%s-%d" % (key, i): sample[key][i]}) + else: + sample.update({"%s-%d" % (key, i): float(sample[key][i])}) del sample[key] dic = { 'measurement': sensor['sensor_id'], @@ -190,7 +193,9 @@ def post(self): if view_fields: fields = [field.strip() for field in view_fields.split(',')] view_dic = dict(dic) - view_fields = {k: v for k, v in dic['fields'].items() if k in fields } + # view_fields = {k: v for k, v in dic['fields'].items() if k in fields } + view_fields = {k: v for k, v in dic['fields'].items() if k.rsplit('-',1)[0] in fields } + view_dic.update({'fields': view_fields}) if apps[view]: if not pubsub: