Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adds year/month/hour to data export

  • Loading branch information...
commit ebdfc5dc7160346f7ac2a36dc37bdd5e35112dd4 1 parent bb9b920
Aaron Parecki authored

Showing 2 changed files with 32 additions and 10 deletions. Show diff stats Hide diff stats

  1. 34  import.rb
  2. 8  setup.txt
34  import.rb
@@ -5,28 +5,42 @@
5 5
 require 'ffi-geos'
6 6
 require 'sqlite3'
7 7
 
8  
-geoloqi = Geoloqi::Session.new :access_token => ''
  8
+geoloqi = Geoloqi::Session.new :access_token => '3e8-3c900cebb9494ca52ed973ed126f3c1dfa81081d'
9 9
 
10 10
 wkt_reader = Geos::WktReader.new
11 11
 wkb_writer = Geos::WkbWriter.new
12  
-db = SQLite3::Database.new('history.db')
  12
+db = SQLite3::Database.new('history.sqlite')
13 13
 
14  
-db.execute("CREATE TABLE IF NOT EXISTS 'history' (OGC_FID INTEGER PRIMARY KEY AUTOINCREMENT,GEOMETRY BLOB)")
  14
+db.execute("CREATE TABLE IF NOT EXISTS 'history' (OGC_FID INTEGER PRIMARY KEY AUTOINCREMENT, GEOMETRY BLOB, 'year' INTEGER, 'month' INTEGER, 'dayofweek' INTEGER, 'hour' INTEGER)")
15 15
 
  16
+db.execute('PRAGMA synchronous = OFF')
16 17
 
17  
-startDate = 1317793332
  18
+batch = 1000
  19
+startDate = DateTime.new 2010, 06, 01, 0, 0, 0, -0.00555555556
18 20
 
19  
-begin
20  
-  result = geoloqi.execute 'get'.to_sym, 'location/history?count=100000&after=' + startDate.to_s
21  
-  history = JSON.parse(result.body)
22  
-  #puts history['points']
  21
+# DateTime.new(year, month, day, hour, min, seconds, offset)
  22
+offset = Rational(-480, 60 * 60 * 24) # Convert a UTC offset measured in minutes to one measured in a fraction of a day.
  23
+
  24
+
  25
+
  26
+lastDate = startDate.to_time.to_i
23 27
 
  28
+puts 'Retrieving next batch of points from: ' + lastDate.to_s 
  29
+result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
  30
+history = JSON.parse(result.body)
  31
+
  32
+begin
24 33
   history['points'].each do |p|
25 34
     puts p['date']
26 35
     point = wkt_reader.read 'POINT(' + p['location']['position']['longitude'].to_s + ' ' + p['location']['position']['latitude'].to_s + ')'
27  
-    db.execute('INSERT INTO history (GEOMETRY) VALUES (?)', SQLite3::Blob.new(wkb_writer.write point))
  36
+    date = Time.at(p['date_ts'])
  37
+    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)
  38
+    lastDate = p['date']
28 39
   end
29 40
 
30  
-  startDate += 86400
  41
+  puts 'Retrieving next batch of points from: ' + lastDate.to_s 
  42
+  result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
  43
+  history = JSON.parse(result.body)
  44
+
31 45
 end while history['points'].length > 0
32 46
 
8  setup.txt
@@ -17,5 +17,13 @@ sudo apt-add-repository ppa:developmentseed/mapbox
17 17
 sudo apt-get update
18 18
 sudo apt-get install libmapnik2 libmapnik2-dev mapnik2-utils python-mapnik2
19 19
 
  20
+sudo apt-get install gdal-bin
  21
+
  22
+
  23
+# Install mapnik ruby bindings
  24
+git clone git://github.com/mapnik/Ruby-Mapnik.git
  25
+cd Ruby-Mapnik
  26
+git checkout public_members
  27
+gem install hoe rake-compiler ZenTest
20 28
 
21 29
 

0 notes on commit ebdfc5d

Please sign in to comment.
Something went wrong with that request. Please try again.