Skip to content

Commit

Permalink
Simple statistics implemented and displayed while the pomodoro is run…
Browse files Browse the repository at this point in the history
…ning and during the break.
  • Loading branch information
reborg committed Feb 19, 2009
1 parent f029222 commit 4c51bbb
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 49 deletions.
6 changes: 3 additions & 3 deletions history/20090219.todo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
TODAY PLANNED 12:
- @basicmetrics new controller actions to query kirbydb and return yesterday and today pomodoros 3 => 4
- @basicmetrics show today's pomodoros worked so far, yesterday's total in timer mode/break mode 1
- @basicmetrics show today's pomodoros worked so far, yesterday's total in timer mode/break mode 1 => 3
- @stopbutton I created a Stop button while on break. I just don't want to show Submit or Void. If no other better ideas, this is the only timer one can decide to interrupt the timer. 1
- @marketing following dr.nic instructions for choc-top plus macruby embedding to packagize and possible embed macruby 8

DONE:
DONE 6:
- @planning 1 => 1
- @basicmetrics new controller actions to query kirbydb and return yesterday and today pomodoros 3 => 5

NOT DONE:

Expand Down
30 changes: 23 additions & 7 deletions lib/pomodori/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def start
@main_app = application :name => "Hotcocoa" do |app|
app.delegate = self
main_window.will_close { exit }
main_window << input_box.disable(" ...running")
main_window << input_box.render

bottom_view << countdown_field.start(POMODORO, method(:on_25_mins_done))
bottom_view << submit_button.render

main_window << bottom_view
update_metrics_for_pomodoro
end
end

Expand Down Expand Up @@ -55,24 +56,21 @@ def pomodori_controller
def on_click_submit_button
@on_click_submit_button ||= Proc.new do
pomodori_controller.create(:text => input_box.render.to_s)
input_box.disable(" ...break")
submit_button.label = "Stop"
update_metrics_for_break
countdown_field.start(BREAK, method(:on_5_mins_done))
end
end

def on_click_void_button
@on_click_void_button ||= Proc.new do
input_box.disable("Pomodoro aborted. Break.")
submit_button.label = "Stop"
update_metrics_for_break
countdown_field.start(BREAK, method(:on_5_mins_done))
end
end

def on_5_mins_done
ring
input_box.disable(" ...running")
submit_button.label = "Void"
update_metrics_for_pomodoro
submit_button.action = on_click_void_button
countdown_field.start(POMODORO, method(:on_25_mins_done))
end
Expand All @@ -84,11 +82,29 @@ def on_25_mins_done
submit_button.action = on_click_submit_button
end

def update_metrics_for_break
input_box.disable(format_metrics("break"))
submit_button.label = "Stop"
end

def update_metrics_for_pomodoro
input_box.disable(format_metrics("pomodoro"))
submit_button.label = "Void"
end

def ring
bell = sound(
:file => File.join(NSBundle.mainBundle.resourcePath.fileSystemRepresentation, 'bell.aif'),
:by_reference => true)
bell.play if bell
end

private

def format_metrics(title)
"Now running #{title.upcase}\n" +
"Yesterday's pomodoros #{pomodori_controller.yesterday_pomodoros}\n" +
"Today's pomodoros so far #{pomodori_controller.today_pomodoros}"
end

end
2 changes: 1 addition & 1 deletion lib/pomodori/countdown_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def render
@render ||= label(:frame => @frame.to_a,
:text => time,
:layout => {:expand => :width, :start => false},
:font => font(:system => 30))
:font => font(:name => "Monaco", :size => 26))
end

private
Expand Down
8 changes: 8 additions & 0 deletions lib/pomodori/pomodori_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ def create(params)
storage.save(pomodoro)
end

def yesterday_pomodoros
storage.yesterday_pomodoros.size
end

def today_pomodoros
storage.today_pomodoros.size
end

def storage
@storage ||= KirbyStorage.new
end
Expand Down
6 changes: 4 additions & 2 deletions lib/pomodori/text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ def frame
end

def render
@render ||= text_field(:frame => frame.to_a)
@render ||= text_field(:frame => frame.to_a, :font => font(:name => "Monaco", :size => 11))
end

def disable(message = "")
# FIXME: touching alignment is the only way I found
# to change also the rest of the properties.
render.text_align = NSCenterTextAlignment
render.text_align = NSLeftTextAlignment
render.setDrawsBackground(false)
render.setBordered(false)
render.setSelectable(false)
Expand All @@ -27,7 +30,6 @@ def disable(message = "")
end

def enable
render.text_align = NSLeftTextAlignment
render.setDrawsBackground(true)
render.setBordered(true)
render.setSelectable(true)
Expand Down
38 changes: 27 additions & 11 deletions pomodori.app/Contents/Resources/lib/pomodori/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Dir.glob(File.join(File.dirname(__FILE__), '**/*.rb')).each {|f| require f}

class Application
POMODORO = 25 * 60
BREAK = 5 * 60
# POMODORO = 5
# BREAK = 3
# POMODORO = 25 * 60
# BREAK = 5 * 60
POMODORO = 5
BREAK = 3
attr_accessor :input_box, :countdown_field, :main_window
attr_accessor :bottom_view, :submit_button, :main_app
attr_accessor :on_click_submit_button, :on_click_void_button
Expand All @@ -16,12 +16,13 @@ def start
@main_app = application :name => "Hotcocoa" do |app|
app.delegate = self
main_window.will_close { exit }
main_window << input_box.disable(" ...running")
main_window << input_box.render

bottom_view << countdown_field.start(POMODORO, method(:on_25_mins_done))
bottom_view << submit_button.render

main_window << bottom_view
update_metrics_for_pomodoro
end
end

Expand Down Expand Up @@ -55,24 +56,21 @@ def pomodori_controller
def on_click_submit_button
@on_click_submit_button ||= Proc.new do
pomodori_controller.create(:text => input_box.render.to_s)
input_box.disable(" ...break")
submit_button.label = "Stop"
update_metrics_for_break
countdown_field.start(BREAK, method(:on_5_mins_done))
end
end

def on_click_void_button
@on_click_void_button ||= Proc.new do
input_box.disable("Pomodoro aborted. Break.")
submit_button.label = "Stop"
update_metrics_for_break
countdown_field.start(BREAK, method(:on_5_mins_done))
end
end

def on_5_mins_done
ring
input_box.disable(" ...running")
submit_button.label = "Void"
update_metrics_for_pomodoro
submit_button.action = on_click_void_button
countdown_field.start(POMODORO, method(:on_25_mins_done))
end
Expand All @@ -84,11 +82,29 @@ def on_25_mins_done
submit_button.action = on_click_submit_button
end

def update_metrics_for_break
input_box.disable(format_metrics("break"))
submit_button.label = "Stop"
end

def update_metrics_for_pomodoro
input_box.disable(format_metrics("pomodoro"))
submit_button.label = "Void"
end

def ring
bell = sound(
:file => File.join(NSBundle.mainBundle.resourcePath.fileSystemRepresentation, 'bell.aif'),
:by_reference => true)
bell.play if bell
end

private

def format_metrics(title)
"Now running #{title.upcase}\n" +
"Yesterday's pomodoros #{pomodori_controller.yesterday_pomodoros}\n" +
"Today's pomodoros so far #{pomodori_controller.today_pomodoros}"
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def render
@render ||= label(:frame => @frame.to_a,
:text => time,
:layout => {:expand => :width, :start => false},
:font => font(:system => 30))
:font => font(:name => "Monaco", :size => 26))
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ def create(params)
storage.save(pomodoro)
end

def yesterday_pomodoros
storage.yesterday_pomodoros.size
end

def today_pomodoros
storage.today_pomodoros.size
end

def storage
@storage ||= KirbyStorage.new
end
Expand Down
6 changes: 4 additions & 2 deletions pomodori.app/Contents/Resources/lib/pomodori/text_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ def frame
end

def render
@render ||= text_field(:frame => frame.to_a)
@render ||= text_field(:frame => frame.to_a, :font => font(:name => "Monaco", :size => 11))
end

def disable(message = "")
# FIXME: touching alignment is the only way I found
# to change also the rest of the properties.
render.text_align = NSCenterTextAlignment
render.text_align = NSLeftTextAlignment
render.setDrawsBackground(false)
render.setBordered(false)
render.setSelectable(false)
Expand All @@ -27,7 +30,6 @@ def disable(message = "")
end

def enable
render.text_align = NSLeftTextAlignment
render.setDrawsBackground(true)
render.setBordered(true)
render.setSelectable(true)
Expand Down
2 changes: 1 addition & 1 deletion script/console
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
echo "Loading Pomodori Interactive Console"
macirb --simple-prompt script/init.rb
macirb -r script/init.rb --simple-prompt
1 change: 1 addition & 0 deletions test/all_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def self.suite
suite << ApplicationTest.suite
suite << On25MinsTimerTest.suite
suite << OnClickTheSubmitButtonTest.suite
suite << DisplayStatisticsTest.suite
return suite
end
end
38 changes: 38 additions & 0 deletions test/pomodori/display_statistics_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'pomodori/application'

class DisplayStatisticsTest < Test::Unit::TestCase

def setup
@application = Application.new
controller = mock('controller')
@application.expects(:pomodori_controller).at_least(1).returns(controller)
controller.stubs(:yesterday_pomodoros).returns(10)
controller.stubs(:today_pomodoros).returns(5)
end

def test_changes_button_label_for_break
@application.update_metrics_for_break
assert_equal("Stop", @application.submit_button.title)
end

def test_label_shows_statistics_for_break
@application.update_metrics_for_break
assert_match(/BREAK/, @application.input_box.render.to_s)
assert_match(/10/, @application.input_box.render.to_s)
assert_match(/5/, @application.input_box.render.to_s)
end

def test_changes_button_label_for_pomodoro
@application.update_metrics_for_pomodoro
assert_equal("Void", @application.submit_button.title)
end

def test_label_shows_statistics_for_pomodoro
@application.update_metrics_for_pomodoro
assert_match(/POMODORO/, @application.input_box.render.to_s)
assert_match(/10/, @application.input_box.render.to_s)
assert_match(/5/, @application.input_box.render.to_s)
end

end
11 changes: 0 additions & 11 deletions test/pomodori/kirby_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def setup
@path = File.dirname(__FILE__) + "/../work"
create_db(@path)
@kirby_storage = KirbyStorage.new(@path)
Time.stubs(:now).returns(Time.local(2009, "feb", 18, "5", "25"))
end

def test_retrieves_table_for_instances_or_class
Expand All @@ -33,16 +32,6 @@ def test_returns_all_pomodoros_by_date
assert_equal(5, @kirby_storage.find_all_by_date(Pomodoro, date).size)
end

def test_returns_all_yesterdays_pomodoros
bulk_import_test_data
assert_equal(10, @kirby_storage.yesterday_pomodoros.size)
end

def test_returns_all_todays_pomodoros
bulk_import_test_data
assert_equal(6, @kirby_storage.today_pomodoros.size)
end

def teardown
wipe_dir(@path)
end
Expand Down
11 changes: 1 addition & 10 deletions test/pomodori/on_click_the_submit_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class OnClickTheSubmitButtonTest < Test::Unit::TestCase

def setup
@application = Application.new
@application.stubs(:update_metrics_for_break)
end

def test_it_starts_the_break
Expand All @@ -21,14 +22,4 @@ def test_creates_a_pomodoro
@application.on_click_submit_button.call
end

# def test_changes_label_to_break
# @application.on_click_submit_button.call
# assert_equal(" ...break", @application.input_box.render.to_s)
# end

# def test_changes_button_to_stop
# @application.on_click_submit_button.call
# assert_equal("Stop", @application.submit_button.render.title)
# end

end

0 comments on commit 4c51bbb

Please sign in to comment.