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

Questions about conversion from SOS to SensorThings #79

Open
haayman opened this issue Jan 29, 2018 · 9 comments
Open

Questions about conversion from SOS to SensorThings #79

haayman opened this issue Jan 29, 2018 · 9 comments

Comments

@haayman
Copy link

haayman commented Jan 29, 2018

I'm trying to convert from SOS to SensorThings, but some things puzzle me.

Old situation:

What's the SensorThings equivalent for the timeseries/getData call?

  1. When I do this now (jan 29 2018 14:00) I get results up to the last hour, but when I look at http://data.smartemission.nl/gost/v1.0/Things?$expand=Datastreams/Observations the most recent measurement appears to be this morning 8:00. How is this different?
@justb4 justb4 self-assigned this Feb 6, 2018
@justb4
Copy link
Contributor

justb4 commented Feb 6, 2018

The SensorThings API is more navigation-oriented but has many other possibilities. As to start capturing some SmartEmission-specific use of STA and best-practices, I've started a Cookbook as a chapter in the documentation. Not yet finished but may give initial guidance:

http://smartplatform.readthedocs.io/en/latest/cookbook.html#sensorthings-api

The main three Entities to play with are Thing, Datastream and Observation. Often there is more than one way to get to the same data. It all depends on what your app is supposed to do, i.e. at which point in the user interaction what data needs to be available. Do you have a link to your app or its source?

Getting the last results (Observations) for a Station (Thing) is tricky. At least I did not find this could be effected using a single URL-query.

@justb4
Copy link
Contributor

justb4 commented Feb 7, 2018

I think the scenario can be realized with STA as follows, see also the SE STA Cookbook:

Get All Stations with Locations

Long version, with Datastreams and Locations.

http://data.smartemission.nl/gost/v1.0/Things?$expand=Locations,Datastreams

Compact version, only attributes relevant for plotting icons on map.

http://data.smartemission.nl/gost/v1.0/Things?$expand=Locations($select=location)&$select=id,name)

To get all Stations: repeat the @iot.nextLink URL in response to go through all Pages.
I've increased the page size to 100 Entities (was 20).

Get Last Observations Per Station

Get the last Observations for single Station (device id = 131):

http://data.smartemission.nl/gost/v1.0/Things(131)?$expand=Datastreams/Observations($top=1)

Get the Observations for last 48 hours, for single Station (device id = 131): need to look further into. To get all Observations of a specific hour let’s say between 11:00 and 12:00 on January 29, 2018:

http://data.smartemission.nl/gost/v1.0/Observations?$filter=phenomenonTime gt ‘2018-01-29T11:00:00.000Z’ and phenomenonTime le ‘2018-01-29T12:00:00.000Z’&$select=result,phenomenonTime,parameters

Note that we are using GOST STA v0.5. In the upcoming v0.6 many fixes went in for queries. e.g. specifying ISO 8601 time periods may work.

@haayman
Copy link
Author

haayman commented Feb 8, 2018

I'm comparing the SOS and SensorThings API and am quite surprised about the differences. Aren't they supposed to render the same result?

http://data.smartemission.nl/sos52n/api/v1/stations

http://data.smartemission.nl/gost/v1.0/Locations

What I notice that the according to Locations almost all sensors are in Helmond, 1 is in Bilthoven and 4 sensors are at [-2.048575,-2.048575]

@justb4
Copy link
Contributor

justb4 commented Feb 8, 2018

Yes, locations are supposed to be the same and I think they are. Have you read the Cookbook in particular the Paging feature, how objects from SE are mapped to STA Entities and how to query stations (via Things)? Querying on Locations is not the way. If I for example query for all stations (Things) in Zoetermeer (project_id eq '2001') I get coordinates in Zoetermeer like:

http://data.smartemission.nl/gost/v1.0/Things?$expand=Locations($select=location)&$select=id,properties,name&$filter=properties/project_id%20eq%20%272001%27

There are about 181 stations, many not active, many last seen in Helmond. Some give invalid GPS coordinates or no location at all. With STA: each time that sensors vals are updated, its Location is updated as well.

@justb4 justb4 added this to In progress in Smart City Living Lab Feb 8, 2018
@haayman
Copy link
Author

haayman commented Feb 9, 2018

I know about the paging. I'm doing these 2 requests (so without filtering on project_id's, because I don't know about those):

http://data.smartemission.nl/gost/v1.0/Things?$expand=Datastreams,Locations
and http://data.smartemission.nl/gost/v1.0/Things?$expand=Datastreams,Locations&$top=100&$skip=100

The results of these are attached to this post.
What I also notice that the responses tell there are 182 results, but actually there are only 26 results aftere these 2 calls. Maybe the count is wrong due to the $expand parameter?

Things2.txt
Things1.txt

@justb4
Copy link
Contributor

justb4 commented Feb 9, 2018

Confirmed: indeed if I request just the Things or Things with Locations I get all 182 Stations in two requests:
http://data.smartemission.nl/gost/v1.0/Things?$expand=Locations and then
http://data.smartemission.nl/gost/v1.0/Things?$expand=Locations&$top=100&$skip=100

It looks indeed like it counts all Entities returned when expanding both Locations and Datastreams. Will look further into...

@justb4
Copy link
Contributor

justb4 commented Feb 9, 2018

@haayman
Copy link
Author

haayman commented Feb 16, 2018

The workaround to keep increasing the $skip until no results are returned appears to work.
But this paging in combination with $expand creates a lot of problems/inefficiencies. See #90

@justb4
Copy link
Contributor

justb4 commented Feb 28, 2018

@haayman @Hans-Nouwens
gost/server#146 is for a large part fixed and now rolled out on SE production server, see my comment on what works and still needs fixing there: gost/server#146 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Smart City Living Lab
  
In progress
Development

No branches or pull requests

2 participants