Add more importers

This commit is contained in:
Felix Krause
2019-07-13 17:56:49 -04:00
parent d98b6e510f
commit 8564119e9b
6 changed files with 95 additions and 9 deletions
+9 -1
View File
@@ -1,3 +1,11 @@
# Moves
Copy the `daily` folder of `geojson` and run `bundle exec ruby run.rb`
Copy the `daily` folder of `geojson` and run
## Steps
`bundle exec ruby steps.rb`
## Gym for UCLAN
`bundle exec ruby uclan_gym.rb`
@@ -4,6 +4,7 @@ require 'date'
csv = "Date;dailySteps"
all_files = Dir["daily/activities/*"]
# Get all steps
puts "parsing #{all_files.count} days of data"
all_files.each do |file|
day = JSON.parse(File.read(file))
@@ -26,3 +27,4 @@ puts csv
File.write("steps.csv", csv)
puts "Finished #{all_files.count} days"
+27
View File
@@ -0,0 +1,27 @@
require 'json'
require 'date'
csv = "Date;gym"
all_files = Dir["daily/places/*"]
# Get all steps
puts "parsing #{all_files.count} days of data"
all_files.each do |file|
day = JSON.parse(File.read(file))
date = file.match(/places\_(\d+)\./)[1]
parsed_date = Date.strptime(date, "%Y%m%d")
day["features"].each do |feature|
place = feature["properties"]["place"]
if place["name"].to_s.include?("Sports Centre")
csv << "\n#{parsed_date.strftime("%d.%m.%Y")};1"
end
end
end
puts csv
File.write("gym.csv", csv)
puts "Finished #{all_files.count} days, #{csv.split("\n").count - 1} entries"
+1
View File
@@ -9,5 +9,6 @@ e.g. did I fly a given day (based on if I was at an airport)
1. Request a new archive via the Swarm mobile app (this might take a while)
1. Copy the latest `checkins.json` into this folder
1. `bundle install`
1. Update the `start_date` in `airports.rb` to be the timestamp of the last `airport` entry
1. `bundle exec ruby airports.rb`
1. Drag & drop `airports.csv` into FxLifeSheet
+24 -8
View File
@@ -2,22 +2,38 @@ require 'json'
checkins = JSON.parse(File.read("checkins.json"))
airports = checkins["items"].keep_if do |checkin|
v_name = checkin["venue"]["name"].downcase
matched = v_name.downcase.include?("airport")
regex_matched = v_name =~ /\([A-Z]{3}\)/
start_date = Time.at(1553385600000 / 1000)
(regex_matched || matched) && !v_name.include?("railway") && !v_name.include?("austria center") && !v_name.include?("bahnhof")
airports = checkins["items"].keep_if do |checkin|
if checkin["venue"].nil? || checkin["venue"]["name"].nil?
# I got one of these, maybe it's an offline checkin
# => {"id"=>"5ab798546fa81f002b1a1acf",
# "createdAt"=>1521981524,
# "type"=>"checkin",
# "timeZoneOffset"=>480,
# "comments"=>{"count"=>0}}
false
else
v_name = checkin["venue"]["name"].downcase
matched = v_name.downcase.include?("airport")
regex_matched = v_name =~ /\([A-Z]{3}\)/
(regex_matched || matched) && !v_name.include?("railway") && !v_name.include?("austria center") && !v_name.include?("bahnhof")
end
end
puts airports.collect { |a| a["venue"]["name"]}.uniq.join("\n")
# puts airports.collect { |a| a["venue"]["name"]}.uniq.join("\n")
csv = "Date;airport"
airports.each do |airport|
csv += "\n#{Time.at(airport["createdAt"]).strftime("%d.%m.%Y")};1"
parsed_time = Time.at(airport["createdAt"])
next if (parsed_time - start_date) < 24 * 60 * 60
puts "#{parsed_time - start_date}"
csv += "\n#{parsed_time.strftime("%d.%m.%Y")};1"
end
puts csv
puts airports.count
puts "Total over all time #{airports.count}"
puts "Total since #{start_date}: #{csv.split("\n").count - 1}"
File.write("airports.csv", csv)
+32
View File
@@ -0,0 +1,32 @@
require 'json'
checkins = JSON.parse(File.read("checkins.json"))
gyms = checkins["items"].keep_if do |checkin|
if checkin["venue"].nil? || checkin["venue"]["name"].nil?
# I got one of these, maybe it's an offline checkin
# => {"id"=>"5ab798546fa81f002b1a1acf",
# "createdAt"=>1521981524,
# "type"=>"checkin",
# "timeZoneOffset"=>480,
# "comments"=>{"count"=>0}}
false
else
v_name = checkin["venue"]["name"].downcase
matched = v_name.downcase.include?("sports centre")
end
end
puts gyms.collect { |a| a["venue"]["name"]}.uniq.join("\n")
csv = "Date;airport"
gyms.each do |airport|
parsed_time = Time.at(airport["createdAt"])
csv += "\n#{parsed_time.strftime("%d.%m.%Y")};1"
end
puts csv
puts "Total over all time #{gyms.count}"
puts "Total since #{start_date}: #{csv.split("\n").count - 1}"
File.write("gyms.csv", csv)