Class: OpenTox::SubTask

Inherits:
Object
  • Object
show all
Defined in:
lib/task.rb

Overview

Convenience class to split a (sub)task into subtasks

example: a crossvalidation is split into creating datasets and performing the validations creating the dataset is 1/3 of the work, perform the validations is 2/3: Task.as_task do |task|

create_datasets( SubTask.new(task, 0, 33) )
perfom_validations( SubTask.new(task, 33, 100) )

end inside the create_datasets / perform_validations you can use subtask.progress(<val>) with vals from 0-100

note that you can split a subtask into further subtasks

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, min, max) ⇒ SubTask

Returns a new instance of SubTask.



312
313
314
315
316
317
318
319
320
# File 'lib/task.rb', line 312

def initialize(task, min, max)
  raise "not a task or subtask" if task!=nil and !(task.is_a?(Task) or task.is_a?(SubTask)) 
  raise "invalid max ("+max.to_s+"), min ("+min.to_s+") params" unless 
    min.is_a?(Numeric) and max.is_a?(Numeric) and min >= 0 and max <= 100 and max > min 
  @task = task
  @min = min
  @max = max
  @delta = max - min
end

Class Method Details

.create(task, min, max) ⇒ Object

convenience method to handle null tasks



323
324
325
326
327
328
329
# File 'lib/task.rb', line 323

def self.create(task, min, max)
  if task
    SubTask.new(task, min, max)
  else
    nil
  end
end

Instance Method Details

#progress(pct) ⇒ Object



335
336
337
338
339
# File 'lib/task.rb', line 335

def progress(pct)
  raise "no numeric >= 0 and <= 100 : '"+pct.to_s+"'" unless pct.is_a?(Numeric) and pct>=0 and pct<=100
  #puts "subtask := "+pct.to_s+" -> task := "+(@min + @delta * pct.to_f * 0.01).to_s
  @task.progress( @min + @delta * pct.to_f * 0.01 )
end

#running?Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/task.rb', line 341

def running?()
  @task.running?
end

#waiting_for(task_uri) ⇒ Object



331
332
333
# File 'lib/task.rb', line 331

def waiting_for(task_uri)
  @task.waiting_for(task_uri)
end