Merged in develop (pull request #37)

Version 0.3.5 release
master
Ensar Sarajcic 2018-10-30 20:48:08 +00:00
commit 4e1669cb42
5 changed files with 34 additions and 11 deletions

View File

@ -115,7 +115,8 @@ class DeviceRecordingQueryResource(ProtectedResource):
def post(self, args, device_id):
validate_device_ownership(device_id)
try:
return devices.run_custom_query(device_id, args), 200
return {'content':
devices.run_custom_query(device_id, args)}, 200
except ValueError as e:
abort(400, message=str(e), status='error')

View File

@ -17,4 +17,10 @@ responses:
200:
description: Success
schema:
type: object
required:
- content
properties:
content:
type: array

View File

@ -284,7 +284,13 @@ def run_custom_query(device_id, request):
resulting_query = jsonql.run_query_on(Recording.query.with_entities(),
recording_field_provider,
**request)
print("Resulting query: " + str(resulting_query))
result = resulting_query.filter(Recording.device_id == device_id).all()
print("RESULT: " + str(result))
return result
final_query = resulting_query.filter(Recording.device_id == device_id)
resulting_columns = final_query.column_descriptions
result = final_query.all()
formatted_result = []
for row in result:
formatted_row = {}
for idx, col in enumerate(row):
formatted_row[resulting_columns[idx]['name']] = col
formatted_result.append(formatted_row)
return formatted_result

View File

@ -2,7 +2,7 @@ from app.core import db
GROUPS = ['sum', 'avg', 'count']
FILTERS = ['$gt', '$lt', '$eq']
PERIODS = ['year', 'month', 'week', 'day']
PERIODS = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']
def run_query_on(query_object, field_provider, **kwargs):
@ -12,9 +12,20 @@ def run_query_on(query_object, field_provider, **kwargs):
print('Starting with args: ' + str(kwargs))
if selections is not None:
if groups is not None:
for group in groups.keys():
entities.append(
get_group(
field_provider(group),
groups[group]
).label(
'group_' + str(group) # + '_' + groups[group]
)
)
for selection in selections.keys():
entities.append(get_column(selections[selection],
field_provider(selection)))
field_provider(selection)).label(selection))
print('New entities: ' + str(entities))
query_object = query_object.with_entities(*entities)
@ -29,8 +40,7 @@ def run_query_on(query_object, field_provider, **kwargs):
if groups is not None:
for group in groups.keys():
query_object = query_object.group_by(
get_group(field_provider(group), groups[group]))
query_object = query_object.group_by('group_' + str(group))
return query_object

View File

@ -2,7 +2,7 @@ import os
# App configuration
DEBUG = os.environ['DEBUG']
APP_VERSION = '0.3.4'
APP_VERSION = '0.3.5'
# Define the application directory
BASE_DIR = os.path.abspath(os.path.dirname(__file__))