Skip to content

Commit

Permalink
Merge pull request #114 from synergylabs/develop
Browse files Browse the repository at this point in the history
- Fixes installation issue on 18.04
- Fixes app_subscription API
- Fixes time-series API
  • Loading branch information
sud335 authored Jun 2, 2022
2 parents 0c472bd + 364790f commit ef5db54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion buildingdepot/DataService/app/rest_api/app_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 19 additions & 8 deletions buildingdepot/DataService/app/rest_api/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get(self, name):
if fields:
fields = fields.split(';')
original_fields = fields
fields = '"' + '", "'.join(fields) + '"'
else:
fields = '*'

Expand All @@ -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)) + '\''

Expand All @@ -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)

Expand Down Expand Up @@ -164,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'],
Expand All @@ -184,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:
Expand Down
1 change: 1 addition & 0 deletions pip_packages.list
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ sphinxcontrib-websupport==1.1.2
typing==3.7.4.1
uWSGI==2.0.18
validate-email==1.2
firebase-admin==2.18.0

0 comments on commit ef5db54

Please sign in to comment.