Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move grouptag to /data route and remove own route #842

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 54 additions & 19 deletions packages/api/lib/controllers/measurementsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
* @apiName getDataMulti
* @apiParam {String} boxId Comma separated list of senseBox IDs.
* @apiParam {String} phenomenon the name of the phenomenon you want to download the data for.
* @apiParam {String} grouptag the name of the phenomenon you want to download the data for.
* @apiParam {RFC3339Date} [from-date] Beginning date of measurement data (default: 2 days ago from now)
* @apiParam {RFC3339Date} [to-date] End date of measurement data (default: now)
* @apiUse SeparatorParam
Expand All @@ -235,17 +236,22 @@
* @apiParam {Boolean=true,false} [download=true] Set the `content-disposition` header to force browsers to download instead of displaying.
*/
const getDataMulti = async function getDataMulti (req, res) {
const { boxId, bbox, exposure, delimiter, columns, fromDate, toDate, phenomenon, download, format } = req._userParams;
const { boxId, bbox, exposure, delimiter, columns, fromDate, toDate, phenomenon, download, format, grouptag } = req._userParams;

// build query
const queryParams = {
'sensors.title': phenomenon
};
// const queryParams = {
// 'sensors.title': phenomenon
// };
const queryParams = {};

if (phenomenon) {
queryParams['sensors.title'] = phenomenon;
}

if (boxId && bbox) {
return Promise.reject(new BadRequestError('please specify only boxId or bbox'));
return Promise.reject(new BadRequestError('please specify only boxId or bbox or grouptag'));
} else if (!boxId && !bbox) {
return Promise.reject(new BadRequestError('please specify either boxId or bbox'));
return Promise.reject(new BadRequestError('please specify either boxId or bbox or grouptag'));
}

if (boxId) {
Expand All @@ -257,6 +263,11 @@
queryParams['exposure'] = { '$in': exposure };
}

if (grouptag) {
const queryTags = grouptag.split(',');
queryParams['grouptag'] = { '$all': queryTags };
}

try {
let stream = await Box.findMeasurementsOfBoxesStream({
query: queryParams,
Expand Down Expand Up @@ -306,7 +317,7 @@
* @apiParam {String} grouptag The grouptag to search by.
* @apiParam {String=json} format=json
*/
const getDataByGroupTag = async function getDataByGroupTag (req, res) {

Check failure on line 320 in packages/api/lib/controllers/measurementsController.js

View workflow job for this annotation

GitHub Actions / 🔬 Lint code

'getDataByGroupTag' is assigned a value but never used
const { grouptag, format } = req._userParams;
const queryTags = grouptag.split(',');
// build query
Expand Down Expand Up @@ -512,10 +523,21 @@
retrieveParameters([
{ predef: 'sensorId', required: true },
{ name: 'format', defaultValue: 'json', allowedValues: ['json', 'csv'] },
{ name: 'download', defaultValue: 'false', allowedValues: ['true', 'false'] },
{
name: 'download',
defaultValue: 'false',
allowedValues: ['true', 'false']
},
{ predef: 'delimiter' },
{ name: 'outliers', allowedValues: ['mark', 'replace'] },
{ name: 'outlierWindow', dataType: 'Integer', aliases: ['outlier-window'], defaultValue: 15, min: 1, max: 50 },
{
name: 'outlierWindow',
dataType: 'Integer',
aliases: ['outlier-window'],
defaultValue: 15,
min: 1,
max: 50
},
{ predef: 'toDate' },
{ predef: 'fromDate' }
]),
Expand All @@ -524,27 +546,40 @@
],
getDataMulti: [
retrieveParameters([
{ name: 'boxId', aliases: ['senseboxid', 'senseboxids', 'boxid', 'boxids'], dataType: ['id'] },
{ name: 'phenomenon', required: true },
{
name: 'boxId',
aliases: ['senseboxid', 'senseboxids', 'boxid', 'boxids'],
dataType: ['id']
},
{ name: 'grouptag', required: false },
{ name: 'phenomenon', required: false },
{ predef: 'delimiter' },
{ name: 'exposure', allowedValues: Box.BOX_VALID_EXPOSURES, dataType: ['String'] },
{
name: 'exposure',
allowedValues: Box.BOX_VALID_EXPOSURES,
dataType: ['String']
},
{ predef: 'columnsGetDataMulti' },
{ predef: 'bbox' },
{ predef: 'toDate' },
{ predef: 'fromDate' },
{ name: 'download', defaultValue: 'true', allowedValues: ['true', 'false'] },
{
name: 'download',
defaultValue: 'true',
allowedValues: ['true', 'false']
},
{ name: 'format', defaultValue: 'csv', allowedValues: ['csv', 'json'] }
]),
validateFromToTimeParams,
getDataMulti
],
getDataByGroupTag: [
retrieveParameters([
{ name: 'grouptag', required: true },
{ name: 'format', defaultValue: 'json', allowedValues: ['json'] }
]),
getDataByGroupTag
],
// getDataByGroupTag: [
// retrieveParameters([
// { name: 'grouptag', required: true },
// { name: 'format', defaultValue: 'json', allowedValues: ['json'] }
// ]),
// getDataByGroupTag
// ],
getLatestMeasurements: [
retrieveParameters([
{ predef: 'boxId', required: true },
Expand Down
2 changes: 1 addition & 1 deletion packages/api/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const routes = {
{ path: `${statisticsPath}/descriptive`, method: 'get', handler: statisticsController.descriptiveStatisticsHandler, reference: 'api-Statistics-descriptive' },
{ path: `${boxesPath}`, method: 'get', handler: boxesController.getBoxes, reference: 'api-Boxes-getBoxes' },
{ path: `${boxesPath}/data`, method: 'get', handler: measurementsController.getDataMulti, reference: 'api-Measurements-getDataMulti' },
{ path: `${boxesPath}/data/bytag`, method: 'get', handler: measurementsController.getDataByGroupTag, reference: 'api-Measurements-getDataByGroupTag' },
// { path: `${boxesPath}/data/bytag`, method: 'get', handler: measurementsController.getDataByGroupTag, reference: 'api-Measurements-getDataByGroupTag' },
{ path: `${boxesPath}/:boxId`, method: 'get', handler: boxesController.getBox, reference: 'api-Boxes-getBox' },
{ path: `${boxesPath}/:boxId/sensors`, method: 'get', handler: measurementsController.getLatestMeasurements, reference: 'api-Measurements-getLatestMeasurements' },
{ path: `${boxesPath}/:boxId/sensors/:sensorId`, method: 'get', handler: measurementsController.getLatestMeasurements, reference: 'api-Measurements-getLatestMeasurementOfSensor' },
Expand Down
Loading