« All Posts

My Solution for Quantified Self: Prompted Data Aggregation

#!/Users/jonathancutrell/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
require 'yaml'
y = YAML::load_file(File.join(__dir__, "stretchr.yml"))
if (rand(10).to_f/10.0).round == 1
    @msgs = y["msgs"]
    @msg = @msgs.sample
    ret = `osascript -e 'set question to display dialog "#{@msg}" buttons {"Nope", "Did it"}'`
    ans = ret.split(":")[1]
else
    @questions = y["questions"]
    @msg = @questions.sample
    ret=`osascript -e 'set question to display dialog "#{@msg}" default answer ""' -e 'text returned of result' 2>/dev/null`
    ans = ret
end
@answers = y["answers"]
@answers[@msg] ||= []
@answers[@msg]<< [ ans, Time.now ]
File.open('stretchr.yml', 'w+') do |file|
  puts file.write(y.to_yaml)
end
---
msgs:
- Stand up and stretch.
- Live healthy, think healthy
- Tell your wife you love her.
- Do something to show appreciation to your coworkers and employees.
- Text a family member.
- Value, now. Stop doing things that don't matter.
- Have you kissed your wife today?
questions:
- Is your desk clean?
- Have you had 10 minutes of quiet thinking time today?
- What word are you thinking of right now?
- Who was the last person you spoke to?
- Is Hacker News open?
- What are you building now for tomorrow?
- Text a family member.
- What have you eaten today?
- On a scale from 1 to 10, how energetic are you?
- On a scale from 1 to 10, how productive do you feel today?
- How many hours did you sleep last night?
answers: {}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.jcutrell.stretchr</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/jonathancutrell/stretchr.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>480</integer>
</dict>
</plist>
require 'yaml'
require 'json'
y = YAML::load_file(File.join(__dir__, "stretchr.yml")) # I think this may be v>=2.0
puts y.to_json