Class: Mddb::Runner
- Inherits:
-
Object
- Object
- Mddb::Runner
- Defined in:
- lib/mddb/runner.rb
Instance Method Summary collapse
- #calculations(frame) ⇒ Object
- #fine? ⇒ Boolean
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #run(start, finish) ⇒ Object
- #stats_on ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
3 4 5 6 7 8 9 10 |
# File 'lib/mddb/runner.rb', line 3 def initialize begin @klasses = Frame.associations.keys.map {|k| k.to_s.classify} rescue @klasses = [] end @stats = false end |
Instance Method Details
#calculations(frame) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mddb/runner.rb', line 42 def calculations(frame) model_count = @klasses.count @klasses.each_with_index do |k,i| objects = Object.const_get(k).where(:fid => frame).all object_count = objects.count complete = 0 failed = 0 calcs = objects.first.list_calculations objects.each do |o| begin o.run complete += 1 print("\r Models (#{i+1}/#{model_count}) => #{k} Completed #{complete}/#{object_count} Failed: #{failed}") if @stats rescue failed += 1 print("\r Models (#{i+1}/#{model_count}) => #{k} Completed #{complete}/#{object_count} Failed: #{failed}") if @stats end end puts " Models (#{i+1}/#{model_count}) => #{k} Completed #{complete}/#{object_count} Failed: #{failed}" unless @stats print("\n") if @stats end begin puts " Running Frame Calculations" frames = Frame.where(:fid => frame).all frames.each {|f| f.run} rescue puts " Failed" end end |
#fine? ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/mddb/runner.rb', line 16 def fine? if @klasses.empty? puts "No models belong to frame, aborting." false else true end end |
#run(start, finish) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mddb/runner.rb', line 25 def run (start, finish) if self.fine? unless start == 0 or finish == 0 (start..finish).each do |f| puts "Running => Frame #{f}" self.calculations(f) end else fids = Frame.all.map {|f| f.fid} fids.each do |f| puts "Running => Frame #{f}" self.calculations(f) end end end end |
#stats_on ⇒ Object
12 13 14 |
# File 'lib/mddb/runner.rb', line 12 def stats_on @stats = true end |