FraunhoferIOSB / FROST-Server

A Complete Server implementation of the OGC SensorThings API
https://fraunhoferiosb.github.io/FROST-Server/
GNU Lesser General Public License v3.0
194 stars 70 forks source link

Filter Observation by Time Interval #17

Closed sudhamani1983 closed 6 years ago

sudhamani1983 commented 7 years ago

We are looking for support to filter Observation for a time interval (phenomeonTimeStart and phenomenonTimeEnd time of an observation).

We need record within the given filter value, but not.

Below is my url: http://localhost:8080/SensorThingsService/v1.0/Datastreams(32)/Observations?$filter=phenomenontime ge 2017-08-14T02:45:00.000Z and phenomenontime lt 2017-09-30T01:10:00.000Z&$select=result,phenomenonTime

Result :

{ "@iot.count": 2, "value": [ { "phenomenonTime": "2017-08-15T03:00:00.000Z/2017-08-15T04:00:00.000Z", "result": 62 }, { "phenomenonTime": "2017-08-15T01:42:00.000Z/2017-08-15T02:55:00.000Z", "result": 67 } ] }

Original Data in Table: observationdata ng…]()

Below Observation records available for Datastream Id 32 : { "phenomenonTime": "2017-09-30T01:00:00.000Z/2017-09-30T02:00:00.000Z", "result": 58 }, { "phenomenonTime": "2017-08-15T03:00:00.000Z/2017-08-15T04:00:00.000Z", "result": 62 }, { "phenomenonTime": "2017-08-15T01:42:00.000Z/2017-08-15T02:55:00.000Z", "result": 67 }, { "phenomenonTime": "2017-08-14T01:42:00.000Z/2017-08-14T02:55:00.000Z", "result": 71 }

hylkevds commented 7 years ago

I'm not entirely sure what you mean, but you are correct in that the current API does not have a good way of dealing with time intervals. I've also posted this as an issue on the Github account of the SensorThings API, in the issue: https://github.com/opengeospatial/sensorthings/issues/2

Is what you want to do one of the following?

These operators are not part of the standard yet, but we are discussing adding them to the standard. We have already implemented them:

/v1.0/Datastreams(32)/Observations?$filter=overlaps(phenomenontime,2017-08-14T02:45:00.000Z/2017-09-30T01:10:00.000Z)&$select=result,phenomenonTime

/v1.0/Datastreams(32)/Observations?$filter=during(phenomenontime,2017-08-14T02:45:00.000Z/2017-09-30T01:10:00.000Z)&$select=result,phenomenonTime

The lt and gt operators can be used to simulate the first, by doing an inverse query: return all the observations that have a phenomenonTime that is not smaller than the start of the given interval and that is not larger than the end of the given interval.

The during function can be simulated using the lt and gt operators by simply taking all the observations that have a phenomenonTime that is larger than the start of the given interval and that is smaller than the end of the given interval.

mjacoby commented 7 years ago

It seems like your query is wrong (at least for the result you expect) because you are mixing up time zones (+00 in the query but +08 in the data). So actually, the query is working as expected but I assume you may want to change your query to

http://localhost:8080/SensorThingsService/v1.0/Datastreams(32)/Observations?$filter=phenomenontime ge 2017-08-14T02:45:00.000+08:00 and phenomenontime lt 2017-09-30T01:10:00.000+08:00&$select=result,phenomenonTime

sudhamani1983 commented 7 years ago

Overlaps function helps for my requirement. Thanks.