Skip to content

Commit ef5db54

Browse files
authored
Merge pull request #114 from synergylabs/develop
- Fixes installation issue on 18.04 - Fixes app_subscription API - Fixes time-series API
2 parents 0c472bd + 364790f commit ef5db54

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

buildingdepot/DataService/app/rest_api/app_subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def post(self):
6868
except Exception as e:
6969
print "Failed to end RabbitMQ session" + str(e)
7070

71-
return jsonify(responses.success_true)
71+
return jsonify(responses.success_true)
7272

7373
return jsonify(responses.application_does_not_exist)
7474

buildingdepot/DataService/app/rest_api/timeseries.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def get(self, name):
5959
if fields:
6060
fields = fields.split(';')
6161
original_fields = fields
62-
fields = '"' + '", "'.join(fields) + '"'
6362
else:
6463
fields = '*'
6564

@@ -75,20 +74,26 @@ def get(self, name):
7574
fields = ','.join(allowed_fields)
7675
name = r.get('parent:{}'.format(name))
7776

77+
if not fields:
78+
return jsonify(responses.no_allowed_fields)
79+
7880
if resolution:
79-
if fields == '*':
80-
return jsonify('TODO: Fields are not supported with resolution')
8181
try:
82-
query = 'select mean(*) from "' + name + '" where (time>\'' + timestamp_to_time_string(
82+
if fields is not '*' and fields:
83+
fields = '/(' + '|'.join(fields.split(',')) + ')-*/'
84+
query = 'select mean('+fields+') from "' + name + '" where (time>\'' + timestamp_to_time_string(
8385
float(start_time)) \
8486
+ '\' and time<\'' + timestamp_to_time_string(
8587
float(end_time)) + '\')' + " GROUP BY time(" + resolution + ")"
88+
# print('\n\n' + '{s:{c}^{n}}'.format(s=' InfluxDB Query ', n=100, c='#'))
89+
# print(query)
90+
# print('#' * 100 + '\n\n')
8691
data = influx.query(query)
8792
except influxdb.exceptions.InfluxDBClientError:
8893
return jsonify(responses.resolution_high)
8994
else:
90-
if fields is not '*':
91-
fields = '"' + '", "'.join(fields.split(',')) + '"'
95+
if fields is not '*' and fields:
96+
fields = '/(' + '|'.join(fields.split(',')) + ')-*/'
9297
query = 'select ' + fields + ' from "' + name + '" where time>\'' + timestamp_to_time_string(float(start_time)) \
9398
+ '\' and time<\'' + timestamp_to_time_string(float(end_time)) + '\''
9499

@@ -104,6 +109,7 @@ def get(self, name):
104109
# print (data.raw)
105110
# print ('#' * 100 + '\n\n')
106111
response.update({'data': data.raw})
112+
del response["data"]["statement_id"]
107113

108114
return jsonify(response)
109115

@@ -164,7 +170,10 @@ def post(self):
164170
if type(sample[key]) is list:
165171
length = len(sample[key])
166172
for i in range(length):
167-
sample.update({"%s-%d" % (key, i): sample[key][i]})
173+
if isinstance(sample[key][i], basestring):
174+
sample.update({"%s-%d" % (key, i): sample[key][i]})
175+
else:
176+
sample.update({"%s-%d" % (key, i): float(sample[key][i])})
168177
del sample[key]
169178
dic = {
170179
'measurement': sensor['sensor_id'],
@@ -184,7 +193,9 @@ def post(self):
184193
if view_fields:
185194
fields = [field.strip() for field in view_fields.split(',')]
186195
view_dic = dict(dic)
187-
view_fields = {k: v for k, v in dic['fields'].items() if k in fields }
196+
# view_fields = {k: v for k, v in dic['fields'].items() if k in fields }
197+
view_fields = {k: v for k, v in dic['fields'].items() if k.rsplit('-',1)[0] in fields }
198+
188199
view_dic.update({'fields': view_fields})
189200
if apps[view]:
190201
if not pubsub:

pip_packages.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ sphinxcontrib-websupport==1.1.2
3535
typing==3.7.4.1
3636
uWSGI==2.0.18
3737
validate-email==1.2
38+
firebase-admin==2.18.0

0 commit comments

Comments
 (0)