RADAR-base / RADAR-RestApi

RESTful interface to access near real-time data
Apache License 2.0
2 stars 0 forks source link

Volume api #80

Closed nivemaham closed 6 years ago

nivemaham commented 6 years ago

Implements aggregated distinct data points for given sources and sourceDataName, which is also referred as Volume API. The system checks whether any records available in calculated intervals based on the value of key.timeStart. Closes #39 Closes #T Sample request /api/aggregate/radar/sub-1/distinct?timeWindow=TEN_MIN&startTime=2018-02-22T16:46:29.206Z&endTime=2018-02-22T17:46:29.206Z

{
   "sources":[
      {
         "sourceId":"03d28e5c-e005-46d4-a9b3-279c27fbbc83",
         "sourceDataName":[
            "EMPATICA_E4_v1_ACCELEROMETER",
            "EMPATICA_E4_v1_BATTERY"
         ]
      }
   ]
}

Sample response body.

{
   "projectName":"radar",
   "subjectId":"sub-1",
   "maximumCount":2,
   "timeFrame":{
      "startDateTime":"2018-02-22T17:40:28.671Z",
      "endDateTime":"2018-02-22T18:40:28.671Z"
   },
   "timeWindow":"TEN_MIN",
   "statistic":"AGGREGATED_DATA_POINTS",
   "sources":[
      {
         "sourceId":"03d28e5c-e005-46d4-a9b3-279c27fbbc83",
         "sourceDataName":[
            "EMPATICA_E4_v1_BATTERY",
            "EMPATICA_E4_v1_ACCELEROMETER"
         ]
      }
   ],
   "aggregatedDataItemList":[
      {
         "count":2,
         "timeFrame":{
            "startDateTime":"2018-02-22T17:40:28.671Z",
            "endDateTime":"2018-02-22T17:50:28.671Z"
         }
      },
      {
         "count":2,
         "timeFrame":{
            "startDateTime":"2018-02-22T17:50:28.671Z",
            "endDateTime":"2018-02-22T18:00:28.671Z"
         }
      },
      {
         "count":2,
         "timeFrame":{
            "startDateTime":"2018-02-22T18:00:28.671Z",
            "endDateTime":"2018-02-22T18:10:28.671Z"
         }
      },
      {
         "count":1,
         "timeFrame":{
            "startDateTime":"2018-02-22T18:10:28.671Z",
            "endDateTime":"2018-02-22T18:20:28.671Z"
         }
      },
      {
         "count":1,
         "timeFrame":{
            "startDateTime":"2018-02-22T18:20:28.671Z",
            "endDateTime":"2018-02-22T18:30:28.671Z"
         }
      },
      {
         "count":1,
         "timeFrame":{
            "startDateTime":"2018-02-22T18:30:28.671Z",
            "endDateTime":"2018-02-22T18:40:28.671Z"
         }
      }
   ]
}

@blootsvoets @herkulano Please suggest if you require any changes.

herkulano commented 6 years ago

It would be nice if it was structured with the header and dataset.

{
  "header": {
    "projectName": "radar",
    "subjectId": "sub-1",
    "maximumCount": 2,
    "timeFrame": {
      "startDateTime": "2018-02-22T17:40:28.671Z",
      "endDateTime": "2018-02-22T18:40:28.671Z"
    },
    "timeWindow": "TEN_MIN",
    "statistic": "AGGREGATED_DATA_POINTS",
    "sources": [
      {
        "sourceId": "03d28e5c-e005-46d4-a9b3-279c27fbbc83",
        "sourceDataName": [
          "EMPATICA_E4_v1_BATTERY",
          "EMPATICA_E4_v1_ACCELEROMETER"
        ]
      }
    ]
  },
  "dataset": [
    {
      "count": 2,
      "timeFrame": {
        "startDateTime": "2018-02-22T17:40:28.671Z",
        "endDateTime": "2018-02-22T17:50:28.671Z"
      }
    },
    {
      "count": 2,
      "timeFrame": {
        "startDateTime": "2018-02-22T17:50:28.671Z",
        "endDateTime": "2018-02-22T18:00:28.671Z"
      }
    },
    {
      "count": 2,
      "timeFrame": {
        "startDateTime": "2018-02-22T18:00:28.671Z",
        "endDateTime": "2018-02-22T18:10:28.671Z"
      }
    },
    {
      "count": 1,
      "timeFrame": {
        "startDateTime": "2018-02-22T18:10:28.671Z",
        "endDateTime": "2018-02-22T18:20:28.671Z"
      }
    },
    {
      "count": 1,
      "timeFrame": {
        "startDateTime": "2018-02-22T18:20:28.671Z",
        "endDateTime": "2018-02-22T18:30:28.671Z"
      }
    },
    {
      "count": 1,
      "timeFrame": {
        "startDateTime": "2018-02-22T18:30:28.671Z",
        "endDateTime": "2018-02-22T18:40:28.671Z"
      }
    }
  ]
}
blootsvoets commented 6 years ago

Perhaps, if sourceDataName will stay unique, filter as follows:

"sources":[
      {
         "sourceId":"03d28e5c-e005-46d4-a9b3-279c27fbbc83",
         "sourceData":[
           {"name": "EMPATICA_E4_v1_ACCELEROMETER"},
           {"type": "BATTERY"}
         ]
      }
   ]

and in the response list the actual sourceData that were selected:

"sources":[
      {
         "sourceId":"03d28e5c-e005-46d4-a9b3-279c27fbbc83",
         "sourceData":[
           {"name": "EMPATICA_E4_v1_ACCELEROMETER", "type": "ACCELEROMETER"},
           {"name": "EMPATICA_E4_v1_BATTERY", "type": "BATTERY"}
         ]
      }
   ]

I think from the original DataItem, the endDateTime was implied from the startDateTime and the timeWindow. In that case, a single entry could look like

    {
      "count": 1,
      "startDateTime": "2018-02-22T18:20:00Z"
    },

and the client can figure out that the endDateTime is 2018-02-22T18:30:00Z.

nivemaham commented 6 years ago

Alright. I will change the structure.

nivemaham commented 6 years ago
{
   "header":{
      "projectName":"radar",
      "subjectId":"sub-1",
      "maximumCount":2,
      "timeFrame":{
         "startDateTime":"2018-02-26T13:38:03.894Z",
         "endDateTime":"2018-02-26T14:38:03.894Z"
      },
      "timeWindow":"TEN_MIN",
      "statistic":"AGGREGATED_DATA_POINTS",
      "sources":[
         {
            "sourceId":"03d28e5c-e005-46d4-a9b3-279c27fbbc83",
            "sourceData":[
               {
                  "name":"EMPATICA_E4_v1_BATTERY",
                  "type":"BATTERY"
               },
               {
                  "name":"EMPATICA_E4_v1_ACCELEROMETER",
                  "type":"ACCELEROMETER"
               }
            ]
         }
      ]
   },
   "dataset":[
      {
         "value":2,
         "startDateTime":"2018-02-26T13:38:03.894Z"
      },
      {
         "value":2,
         "startDateTime":"2018-02-26T13:48:03.894Z"
      },
      {
         "value":2,
         "startDateTime":"2018-02-26T13:58:03.894Z"
      },
      {
         "value":1,
         "startDateTime":"2018-02-26T14:08:03.894Z"
      },
      {
         "value":1,
         "startDateTime":"2018-02-26T14:18:03.894Z"
      },
      {
         "value":1,
         "startDateTime":"2018-02-26T14:28:03.894Z"
      }
   ]
}

Edited: sample renamed to value