Class: Laborantin::Analysis

Inherits:
Object
  • Object
show all
Extended by:
Metaprog::Describable, Metaprog::MultiName
Includes:
Metaprog::Dependencies, Metaprog::Exports, Metaprog::Selector
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

Attributes included from Metaprog::Selector

#environments, #scenarii

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metaprog::MultiName

set_name

Methods included from Metaprog::Exports

#export, #exports, #load_exports, #plots, #save_exports

Methods included from Metaprog::Dependencies

included

Methods included from Metaprog::Selector

included, #load_environments, #load_prior_results, #load_scenarii, #select_instance?

Constructor Details

#initialize(command = nil) ⇒ Analysis

Just loads the environments and scenarii from the resultdir.



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

def initialize(command = nil)
  @command = command
  load_prior_results
end

Class Attribute Details

.analysesObject

An array



44
45
46
# File 'lib/laborantin/core/analysis.rb', line 44

def analyses
  @analyses
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

Class Method Details

.allObject



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

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



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

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

.inherited(klass) ⇒ Object



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

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

Instance Method Details

#analyzeObject

TODO : recode this, maybe as nothing to do here



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

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

#create_output_dirObject



96
97
98
# File 'lib/laborantin/core/analysis.rb', line 96

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

#export_file(mode = 'r', &blk) ⇒ Object



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

def export_file(mode='r', &blk)
  output('exports.yaml', mode, &blk) 
end

#export_pathObject



119
120
121
# File 'lib/laborantin/core/analysis.rb', line 119

def export_path
  output_path('exports.yaml')
end

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



104
105
106
107
108
109
# File 'lib/laborantin/core/analysis.rb', line 104

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

#output_dirnameObject



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

def output_dirname
  self.class.cli_name
end

#output_dirpathObject



92
93
94
# File 'lib/laborantin/core/analysis.rb', line 92

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

#output_path(name) ⇒ Object



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

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

#report(tpl_path = nil) ⇒ Object

TODO: more flexible



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

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

#runnerObject



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

def runner
  command.runner if command
end

#table(name, struct) ⇒ Object



111
112
113
# File 'lib/laborantin/core/analysis.rb', line 111

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