Commit f14df515 authored by taco@waag.org's avatar taco@waag.org
Browse files

paging url bug fix

parent 528bbe41
......@@ -33,9 +33,10 @@ get '/sensor/:type' do
puts "cache hit"
else
pages = []
getPageRecursive(pages,uri)
getPageRecursive(pages,uri,false)
things = pages.map{|page|page["value"]}.flatten
result = things.map{|thing|
ds_list = thing["Datastreams"]
x = nil
......@@ -98,7 +99,7 @@ def retrieveSensorData(params)
date_end = params[:end]
uri = "#{$base_url}/Things?$filter=name%20eq%20%27HLL_hl_device_#{id}%27&$expand=Datastreams($filter=contains(name,%27#{type}%27))"
body = nil
if($redis.exists uri)
body = $redis.get uri
......@@ -116,7 +117,7 @@ def retrieveSensorData(params)
all_pages = ds_ids.map.with_index{|id,index|
page_uri = "#{$base_url}/Datastreams(#{id})/Observations?$orderby=phenomenonTime%20asc&$filter=date(phenomenonTime)%20gt%20date(%27#{date_start}%27)%20and%20date(phenomenonTime)%20lt%20date(%27#{date_end}%27)&$select=phenomenonTime,result"
pages = []
getPageRecursive(pages,page_uri)
getPageRecursive(pages,page_uri,true)
all_values = []
pages.each do|page|
......@@ -133,10 +134,11 @@ end
def getPageRecursive(pages,uri)
def getPageRecursive(pages,uri,filter)
response = RestClient.get uri
page = JSON.parse(response)
nextLink = page["@iot.nextLink"]
nextLink = nextLink + "&$select=phenomenonTime,result" if(filter)
pages << page
getPageRecursive(pages,nextLink +"&$select=phenomenonTime,result") if (nextLink != nil and not nextLink.empty?)
getPageRecursive(pages,nextLink,filter) if (nextLink != nil and not nextLink.empty?)
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment