Commit 3b3f30d6 authored by alain's avatar alain 🐙
Browse files

filter out things without datastreams

parent 622c2f62
......@@ -9,6 +9,12 @@
`gem install csv`
`gem install redis`
`gem install rack`
`gem install rack-cors`
## to start
`brew services start redis`
......
......@@ -37,14 +37,14 @@ get '/sensor/:type' do
end
body = nil
if($redis.exists uri)
if($redis.exists uri )
body = $redis.get uri
puts "cache hit"
else
pages = []
getPageRecursive(pages,uri,false)
things = pages.map{|page|page["value"]}.flatten
things = pages.map{|page|page["value"]}.flatten.select{|thing|thing["Datastreams"] != nil}
result = things.map{|thing|
ds_list = thing["Datastreams"]
......@@ -145,10 +145,12 @@ end
def getPageRecursive(pages,uri,filter)
#start = Time.now
response = RestClient.get uri
page = JSON.parse(response)
nextLink = page["@iot.nextLink"]
nextLink = "#{nextLink}&$select=phenomenonTime,result" if(filter and nextLink != nil and not nextLink.empty?)
pages << page
#puts "#{uri}: #{Time.now - start} s"
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