Class: Experiment::Notify

Inherits:
Object
  • Object
show all
Extended by:
DRb::DRbUndumped, ProgressBar
Defined in:
lib/experiment/notify.rb

Overview

This class is responsible for UI goodness in letting you know about the progress of your experiments

Defined Under Namespace

Modules: ProgressBar

Class Method Summary collapse

Methods included from ProgressBar

elapsed, eta, format_time, get_width, inc, show, show_if_needed, stat

Class Method Details

.completed(experiment, msg = "") ⇒ Object

Called when experiment completed. Shows a Growl notification on OSX. The message can be expanded by overriding the result_line method in the experiment class



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/experiment/notify.rb', line 42

def completed(experiment, msg = "")
  if @growl
    begin
      `G_TITLE="Experiment Complete" #{File.dirname(__FILE__)}/../../bin/growl.sh -nosticky "Experimental condition #{experiment} complete. #{msg}"`
    rescue
      # probably not on OSX
    end
  end
  m = "Condition #{experiment} complete. #{msg}"
  puts m + " " * @terminal_width
  @curent_experiment = nil
end

.cv_done(experiment, num) ⇒ Object

called after a crossvalidation has completed



56
57
58
59
60
# File 'lib/experiment/notify.rb', line 56

def cv_done(experiment, num)
  @cv_prog[experiment][num] ||= 0
  inc(1 - @cv_prog[experiment][num])
  #@cv_prog = 0
end

.doneObject

Wrap up



63
64
65
66
67
# File 'lib/experiment/notify.rb', line 63

def done
  @current = @total
  @finished_p = true
  #show
end

.init(total, out = STDERR, growl = true, mode = :normal) ⇒ Object

initialize display



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/experiment/notify.rb', line 12

def init(total, out = STDERR, growl = true, mode = :normal)
  @curent_experiment = ""
  @current_cv = 0
  @cv_prog = {}
  @total = total
  @out = out
  @terminal_width = 80
  @bar_mark = "o"
  @current = 0
  @previous = 0
  @finished_p = false
  @start_time = Time.now
  @previous_time = @start_time
  @growl = growl
  @mode = mode
  show if @mode == :normal && @out
end

.started(experiment) ⇒ Object

Called when starting work on a particular experiment



31
32
33
34
35
36
# File 'lib/experiment/notify.rb', line 31

def started(experiment)
  @curent_experiment = experiment
  @current_cv = 1
  @cv_prog[experiment] = []
  show_if_needed
end

.step(experiment, cv, num) ⇒ Object

Use this in experiment after each (potentially time consuming) task The argument should be a fraction (0 < num < 1) which tells how big a portion the task was of the complete run (eg. your calls should sum up to 1).



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/experiment/notify.rb', line 73

def step(experiment, cv, num)
  if @mode == :normal
    if num > 1
      num = num / 100
    end
    inc(num)
    @cv_prog[experiment][cv] ||= 0
    @cv_prog[experiment][cv] += num
  else
    @mode.notify.step(experiment, cv, num)
  end
end