Class: Laborantin::Analysis

Inherits:
Object
  • Object
show all
Extended by:
Metaprog::Describable, Metaprog::MultiName
Defined in:
lib/laborantin/core/analysis.rb

Overview

An Analysis is a handy way to reload and filter the various scenarii that were run. You can easily filter on them.

Constant Summary collapse

@@all =
[]

Constants included from Metaprog::MultiName

Metaprog::MultiName::AVAILABLE_NAMES

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Metaprog::Describable

#description

Attributes included from Metaprog::MultiName

#cli_name, #fs_name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metaprog::MultiName

set_name

Class Attribute Details

.analysesObject

An array



41
42
43
# File 'lib/laborantin/core/analysis.rb', line 41

def analyses
  @analyses
end

.selectorsObject

A hash with two items, this might change later but KISS for now.



38
39
40
# File 'lib/laborantin/core/analysis.rb', line 38

def selectors
  @selectors
end

Instance Attribute Details

#environmentsObject

An array of the Environments that could be loaded from the result directory.



100
101
102
# File 'lib/laborantin/core/analysis.rb', line 100

def environments
  @environments
end

#scenariiObject (readonly)

An array of the Scenarii that could be loaded from the result directory.



103
104
105
# File 'lib/laborantin/core/analysis.rb', line 103

def scenarii
  @scenarii
end

Class Method Details

.allObject



94
95
96
# File 'lib/laborantin/core/analysis.rb', line 94

def all
  @@all
end

.analyze(str, params = {}, &blk) ⇒ Object

Adds an analysis to this class. str is a description of the added analysis params is a hash of parameters for this analysis, specifically, the :type parameters allows you to differenciate the kind of analysis for repors TODO: more info on that, tells that we can directly use Analysis.plot and Analysis.table methods



61
62
63
# File 'lib/laborantin/core/analysis.rb', line 61

def analyze(str, params = {}, &blk) 
  @analyses << {:str => str, :params => params, :blk => blk} 
end

.inherited(klass) ⇒ Object



87
88
89
90
91
92
# File 'lib/laborantin/core/analysis.rb', line 87

def inherited(klass)
  @@all << klass
  klass.select(:environments,[Laborantin::Environment])
  klass.select(:scenarii,[Laborantin::Scenario])
  klass.analyses = []
end

.plot(title, args, &blk) ⇒ Object



65
66
67
68
69
# File 'lib/laborantin/core/analysis.rb', line 65

def plot(title, args, &blk)
    args ||= {}
    hash = args.merge({:type => :plot})
    analyze(title, hash, &blk)
end

.plotsObject



77
78
79
# File 'lib/laborantin/core/analysis.rb', line 77

def plots
  analyses.select{|a| a[:params][:type] == :plots}
end

.select(sym, ary = [], &blk) ⇒ Object

Add a selector to filter for the analysis only the runs that pass the selector.

  • sym objects (sym currently must be :environments or

:scenarii).

  • ary is a set of classes, only runs of this classes will be loaded

  • if a block is passed, only the instances for which the block is

evaluated as true will be selected (the block must take one parameter: the tested instance)



50
51
52
53
# File 'lib/laborantin/core/analysis.rb', line 50

def select(sym, ary=[], &blk) 
  @selectors ||= {} 
  @selectors[sym] = {:klasses => ary, :blk => blk} 
end

.table(title, args, &blk) ⇒ Object



71
72
73
74
75
# File 'lib/laborantin/core/analysis.rb', line 71

def table(title, args, &blk)
    args ||= {}
    hash = args.merge({:type => :table})
    analyze(title, hash, &blk)
end

.tablesObject



81
82
83
# File 'lib/laborantin/core/analysis.rb', line 81

def tables
  analyses.select{|a| a[:params][:type] == :tables}
end

Instance Method Details

#analyzeObject

TODO : recode this, maybe as nothing to do here



106
107
108
109
110
111
112
# File 'lib/laborantin/core/analysis.rb', line 106

def analyze 
  self.class.analyses.each do |a|
    puts "(#{a[:str]})"
    instance_eval &a[:blk]
    puts "done"
  end
end

#create_output_dirObject



130
131
132
# File 'lib/laborantin/core/analysis.rb', line 130

def create_output_dir
  FileUtils.mkdir_p(output_dirpath) unless File.directory?(output_dirpath)
end

#output(name, mode = 'r') ⇒ Object



138
139
140
141
142
143
# File 'lib/laborantin/core/analysis.rb', line 138

def output(name, mode='r')
  create_output_dir
  File.open(output_path(name), mode) do |f|
    yield f
  end
end

#output_dirnameObject



122
123
124
# File 'lib/laborantin/core/analysis.rb', line 122

def output_dirname
  self.class.cli_name
end

#output_dirpathObject



126
127
128
# File 'lib/laborantin/core/analysis.rb', line 126

def output_dirpath
  File.join('.', 'reports', output_dirname)
end

#output_path(name) ⇒ Object



134
135
136
# File 'lib/laborantin/core/analysis.rb', line 134

def output_path(name)
  File.join(output_dirpath, name)
end

#report(tpl_path = nil) ⇒ Object

TODO: more flexible



115
116
117
118
119
120
# File 'lib/laborantin/core/analysis.rb', line 115

def report(tpl_path=nil)
  tpl = ERB.new(File.read(tpl_path))
  File.open("reports/#{self.class.name}.html", 'w') do |f|
    f.puts tpl.result(binding)
  end
end

#table(name, struct) ⇒ Object



145
146
147
# File 'lib/laborantin/core/analysis.rb', line 145

def table(name, struct)
  Table.new(name, struct, self.output_path(name))
end