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

[Question] Possibility to retrieve All Most Recent Observations per Datastream (for given ObservedProperty)? #1107

Open
rduivenvoorde opened this issue Aug 22, 2022 · 3 comments

Comments

@rduivenvoorde
Copy link

I've been fiddling around a lot now, starting with Datastreams, then Observations and then to Things.

But I fail to efficiently receive a list of "All Most Recent Observations per Datastream (for given ObservedProperty)"

My goal: on a map with locations: show the latest measurement/observation for a Datastream (eg the SO2 measurements).

I thought to have it with:

https://airquality-frost.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Datastreams?$count=true&$top=1&$filter=ObservedProperty/name eq 'SO2'&$expand=ObservedProperty,Thing/Locations,Observations&$orderby=phenomenonTime desc

BUT that appeared to be the Dataset-phenomenonTime which is actually a period ...

Another try was to find All observation in All datastreams of last 24 hours and order them, but that also seems wrong:

https://airquality-frost.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Datastreams/Observations?$count=true&$filter=Datastream/ObservedProperty/name eq 'SO2'and phenomenonTime gt now() sub duration'PT24H'&$orderby=phenomenonTime desc&$expand=Datastream

Anybody a hint?

(or is this a question I should not ask from Frost, because there are so many Observations and ordering those is a headache?)

@rduivenvoorde
Copy link
Author

Via "Give me EVERYTHING!' in https://fraunhoferiosb.github.io/FROST-Server/sensorthingsapi/requestingData/STA-Example-Queries.html, I got:

https://airquality-frost.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things?$count=true&$select=name,description,@iot.id
  &$expand=
    Locations
      ($select=name,description,location,@iot.id)
    ,Datastreams
      ($select=name,description,@iot.id
      ;$expand=
        Sensor
          ($select=name,description,@iot.id)
        ,ObservedProperty
          ($select=name,description,@iot.id)
        ,Observations
          ($select=result,phenomenonTime,@iot.id
          ;$orderby=phenomenonTime%20desc
          ;$top=2
          )
      )&$filter=Datastreams/ObservedProperty/name eq 'SO2'

But that still has a lot of overhead... because always ALL Datastreams per Things are returned.

We can get rid of Location and Sensor:

https://airquality-frost.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Things?$count=true&$select=name,description,@iot.id
  &$expand=Datastreams
      ($select=name,description,@iot.id
      ;$expand=ObservedProperty
          ($select=name,description,@iot.id)
        ,Observations
          ($select=result,phenomenonTime,@iot.id
          ;$orderby=phenomenonTime%20desc
          ;$top=2
          )
      )&$filter=Datastreams/ObservedProperty/name eq 'SO2'

But my feeling is that retrieving Datastreams would be more efficient, but I'm not able to create a performing query with those...

@rduivenvoorde
Copy link
Author

This returns the right amount of Datastreams (1864), added $top=2000 so I'd return all in one go), but I'm not convinced that these are the latest SO2 observations for every Datastream:

https://airquality-frost.k8s.ilt-dmz.iosb.fraunhofer.de/v1.1/Datastreams?$count=true&$filter=ObservedProperty/name eq 'SO2'&$expand=ObservedProperty
          ($select=name,description,@iot.id)
        ,Observations
          ($select=result,phenomenonTime,@iot.id
          ;$orderby=phenomenonTime%20desc
          ;$top=1
          )
        ,Thing/Locations&$resultFormat=GeoJSON&$top=2000

@hylkevds
Copy link
Member

hylkevds commented Sep 7, 2022

That last query should return the latest SO2 Observations.
It may be that our importer is having issues, or that the EEA service that we harvest has issues, so the service may be a bit behind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants