Permalink
Browse files

Adds year/month/hour to data export

  • Loading branch information...
1 parent bb9b920 commit ebdfc5dc7160346f7ac2a36dc37bdd5e35112dd4 @aaronpk committed Dec 15, 2011
Showing with 32 additions and 10 deletions.
  1. +24 −10 import.rb
  2. +8 −0 setup.txt
View
34 import.rb
@@ -5,28 +5,42 @@
require 'ffi-geos'
require 'sqlite3'
-geoloqi = Geoloqi::Session.new :access_token => ''
+geoloqi = Geoloqi::Session.new :access_token => '3e8-3c900cebb9494ca52ed973ed126f3c1dfa81081d'
wkt_reader = Geos::WktReader.new
wkb_writer = Geos::WkbWriter.new
-db = SQLite3::Database.new('history.db')
+db = SQLite3::Database.new('history.sqlite')
-db.execute("CREATE TABLE IF NOT EXISTS 'history' (OGC_FID INTEGER PRIMARY KEY AUTOINCREMENT,GEOMETRY BLOB)")
+db.execute("CREATE TABLE IF NOT EXISTS 'history' (OGC_FID INTEGER PRIMARY KEY AUTOINCREMENT, GEOMETRY BLOB, 'year' INTEGER, 'month' INTEGER, 'dayofweek' INTEGER, 'hour' INTEGER)")
+db.execute('PRAGMA synchronous = OFF')
-startDate = 1317793332
+batch = 1000
+startDate = DateTime.new 2010, 06, 01, 0, 0, 0, -0.00555555556
-begin
- result = geoloqi.execute 'get'.to_sym, 'location/history?count=100000&after=' + startDate.to_s
- history = JSON.parse(result.body)
- #puts history['points']
+# DateTime.new(year, month, day, hour, min, seconds, offset)
+offset = Rational(-480, 60 * 60 * 24) # Convert a UTC offset measured in minutes to one measured in a fraction of a day.
+
+
+
+lastDate = startDate.to_time.to_i
+puts 'Retrieving next batch of points from: ' + lastDate.to_s
+result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
+history = JSON.parse(result.body)
+
+begin
history['points'].each do |p|
puts p['date']
point = wkt_reader.read 'POINT(' + p['location']['position']['longitude'].to_s + ' ' + p['location']['position']['latitude'].to_s + ')'
- db.execute('INSERT INTO history (GEOMETRY) VALUES (?)', SQLite3::Blob.new(wkb_writer.write point))
+ date = Time.at(p['date_ts'])
+ db.execute('INSERT INTO history (GEOMETRY, year, month, dayofweek, hour) VALUES (?,?,?,?,?)', SQLite3::Blob.new(wkb_writer.write point), date.year, date.month, date.wday, date.hour)
+ lastDate = p['date']
end
- startDate += 86400
+ puts 'Retrieving next batch of points from: ' + lastDate.to_s
+ result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
+ history = JSON.parse(result.body)
+
end while history['points'].length > 0
View
8 setup.txt
@@ -17,5 +17,13 @@ sudo apt-add-repository ppa:developmentseed/mapbox
sudo apt-get update
sudo apt-get install libmapnik2 libmapnik2-dev mapnik2-utils python-mapnik2
+sudo apt-get install gdal-bin
+
+
+# Install mapnik ruby bindings
+git clone git://github.com/mapnik/Ruby-Mapnik.git
+cd Ruby-Mapnik
+git checkout public_members
+gem install hoe rake-compiler ZenTest

0 comments on commit ebdfc5d

Please sign in to comment.