diff --git a/importers/moves/README.md b/importers/moves/README.md index 2fd0b54..4158469 100644 --- a/importers/moves/README.md +++ b/importers/moves/README.md @@ -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` diff --git a/importers/moves/run.rb b/importers/moves/steps.rb similarity index 97% rename from importers/moves/run.rb rename to importers/moves/steps.rb index e0dc1c2..4769472 100644 --- a/importers/moves/run.rb +++ b/importers/moves/steps.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" + diff --git a/importers/moves/uclan_gym.rb b/importers/moves/uclan_gym.rb new file mode 100644 index 0000000..96e8957 --- /dev/null +++ b/importers/moves/uclan_gym.rb @@ -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" + diff --git a/importers/swarm/README.md b/importers/swarm/README.md index 892c075..c8fd885 100644 --- a/importers/swarm/README.md +++ b/importers/swarm/README.md @@ -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 diff --git a/importers/swarm/airports.rb b/importers/swarm/airports.rb index d00d0a5..6c09cbe 100644 --- a/importers/swarm/airports.rb +++ b/importers/swarm/airports.rb @@ -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) diff --git a/importers/swarm/gyms.rb b/importers/swarm/gyms.rb new file mode 100644 index 0000000..d963be4 --- /dev/null +++ b/importers/swarm/gyms.rb @@ -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)