Last active
May 29, 2019 10:49
-
-
Save deadroxy/dcdc7dba04be3126e4eaaa9a620be7c4 to your computer and use it in GitHub Desktop.
rake task to import motiv sleepevent data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :motiv do | |
# Import sleep data from Motiv ZMTVSLEEPEVENT Table | |
# To obtain this data in CSV format... | |
# First dump your Motiv DataModel from the iOS app using iExplorer | |
# Then open the sqlite file in DB Browser and export the table to CSV | |
task :import_sleepevents_for_user, [:filename, :email] => :environment do |task, args| | |
require 'csv' | |
user = User.find_by_email(args[:email]) | |
puts "Adding sleeps for #{user.email}" | |
file = File.read(args[:filename]) | |
csv = CSV.parse(file, :headers => true) | |
csv.each do |row| | |
s = Sleep.create!(start: Time.at(row["ZUTCSTART"].to_i), end: Time.at(row["ZUTCEND"].to_i), user: user) | |
puts "Added sleep from #{s.start} to #{s.end}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment