Commits

Don Park  committed ea7c82f

show the most recent observation

  • Participants
  • Parent commits 50b5815

Comments (0)

Files changed (3)

File sinatra/lib/geomena/couch.rb

   end
 
   def self.last
-    @@db.view('observations/createdat')["rows"]
-    JSON.parse(result)["rows"]
+    @@db.view('observations/bycreatedat', :limit => 1, :descending => true)["rows"].first["value"]
   end
 
   def self.log(essid, note)

File sinatra/lib/geomena/web.rb

     end
     
     get '/' do
-      erb :index, :locals => {:ocount => GCouch.count}
+      erb :index, :locals => {:ocount => GCouch.count, :aplast => GCouch.last}
     end
     
     get '/api' do

File sinatra/views/index.erb

   </div>
 
   <p id="ocount">
-   There are <%= ocount %> observations in the database.
+   There are <%= ocount %> observations in the database. <br/>
+   Mostly recently "<a href="/ap/<%=aplast["mac"]%>"><%=aplast["essid"]%></a>" was observed  at 
+    <script>
+      var localtime = new Date();
+      <% time = Time.parse(aplast["created_at"]) %>
+      localtime.setUTCFullYear(<%=time.year%>);
+      localtime.setUTCMonth(<%=time.month%>);
+      localtime.setUTCDate(<%=time.day%>);
+      localtime.setUTCHours(<%=time.hour%>);
+      localtime.setUTCMinutes(<%=time.min%>);
+      localtime.setUTCSeconds(<%=time.sec%>);
+      var hours = ""+localtime.getHours();
+      if (hours > 12) { hours = hours - 12; ampm = "pm"} else {ampm = "am"}
+      var minutes = ""+localtime.getMinutes();
+      if (minutes.length == 1) { minutes = "0"+minutes }
+      document.write(""+localtime.getFullYear()+"-"+
+                       localtime.getMonth()+"-"+
+                       localtime.getDate()+" "+
+                       hours + ":" + minutes + ampm );
+    </script>
   </p>
 
   <div id="browsersetupbox">