opendata - SPARQL group by a substring and average -


i querying large data set (temperatures recorded hourly 20 years) , i'd rather summary, e.g. daily temperatures.

an example query here: http://www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid=hu5rbc7w

prefix opensheff: <uri://opensheffield.org/properties#>  select ?time ?temp {     ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/weather_mast/weather_mast.ic> ;        opensheff:rawvalue ?temp ;        <http://purl.oclc.org/net/ssnx/ssn#endtime> ?time .   filter (str(?time) > "2011-09-24") } order asc(?time) 

and results this:

time                temp "2011-09-24t00:00z" 12.31 "2011-09-24t01:00z" 11.68 "2011-09-24t02:00z" 11.92 "2011-09-24t03:00z" 11.59 

now group part of date string, daily average temperature:

time            temp "2011-09-24"    12.3  # or whatever "2011-09-23"    11.7 "2011-09-22"    11.9 "2011-09-21"    11.6 

so, how group substring of ?time ?

eventually solved it. running here:

http://www.boisvert.me.uk/opendata/sparql_aq+.html?pasteid=j8m0qk6s

code: prefix opensheff:

select ?d avg(?temp) ?day_temp {     ?m opensheff:sensor <uri://opensheffield.org/datagrid/sensors/weather_mast/weather_mast.ic> ;        opensheff:rawvalue ?temp ;        <http://purl.oclc.org/net/ssnx/ssn#endtime> ?time .     bind( substr(?time, 1, 10) ?d ) . } group ?d order asc(?d) 

we use bind set new variable substring required, , grouping , averaging variable simple enough.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -