Class: Twb::FieldCalculation
- Includes:
- TabTool
- Defined in:
- lib/twb/fieldcalculation.rb
Constant Summary collapse
- @@tableCalcs =
attr_accessor :ttlogfile
[ 'FIRST', 'INDEX', 'LAST', 'SIZE', 'LOOKUP', 'PREVIOUS_VALUE', 'RANK', 'RANK_DENSE', 'RANK_MODIFIED', 'RANK_PERCENTILE', 'RANK_UNIQUE', 'RUNNING_AVG', 'RUNNING_COUNT', 'RUNNING_MAX', 'RUNNING_MIN', 'RUNNING_SUM', 'SCRIPT_BOOL', 'SCRIPT_INT', 'SCRIPT_REAL', 'SCRIPT_STR', 'TOTAL', 'WINDOW_SUM', 'WINDOW_AVG', 'WINDOW_COUNT', 'WINDOW_MIN', 'WINDOW_MEDIAN', 'WINDOW_MAX', 'WINDOW_PERCENTILE', 'WINDOW_STDEV', 'WINDOW_STDEVP', 'WINDOW_CORR', 'WINDOW_COVAR', 'WINDOW_COVARP', 'WINDOW_VAR', 'WINDOW_VARP' ]
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#class ⇒ Object
readonly
Returns the value of attribute class.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#dataSource ⇒ Object
readonly
Returns the value of attribute dataSource.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#fieldNode ⇒ Object
readonly
Returns the value of attribute fieldNode.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
-
#formulaFlat ⇒ Object
readonly
Returns the value of attribute formulaFlat.
-
#formulaFlatResolved ⇒ Object
readonly
Returns the value of attribute formulaFlatResolved.
-
#formulaLines ⇒ Object
readonly
Returns the value of attribute formulaLines.
-
#formulaLinesCount ⇒ Object
readonly
Returns the value of attribute formulaLinesCount.
-
#formulaResolved ⇒ Object
readonly
Returns the value of attribute formulaResolved.
-
#formulaResolvedLines ⇒ Object
readonly
Returns the value of attribute formulaResolvedLines.
-
#formulaUC ⇒ Object
readonly
Returns the value of attribute formulaUC.
-
#has_formula ⇒ Object
readonly
Returns the value of attribute has_formula.
-
#is_lod ⇒ Object
readonly
Returns the value of attribute is_lod.
-
#is_tableCalc ⇒ Object
readonly
Returns the value of attribute is_tableCalc.
-
#lodCodePos ⇒ Object
readonly
Returns the value of attribute lodCodePos.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#referencedFields ⇒ Object
readonly
Returns the value of attribute referencedFields.
-
#remoteFields ⇒ Object
readonly
Returns the value of attribute remoteFields.
-
#scopeIsolation ⇒ Object
readonly
Returns the value of attribute scopeIsolation.
-
#uiname ⇒ Object
readonly
Returns the value of attribute uiname.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Attributes included from TabTool
#alerts, #docDir, #docfiles, #funcdoc, #licensed, #logfilename, #logger, #loglevel, #metrics, #properties, #ttdocdir, #type
Attributes inherited from TabClass
#properties, #ttlogfile, #ttlogfilename, #type
Instance Method Summary collapse
- #attribText(node, attribute) ⇒ Object
- #enlineResolvedFormula ⇒ Object
- #flattenFormula(lines) ⇒ Object
- #flattenResolvedFormula ⇒ Object
- #getComments(lines) ⇒ Object
- #id ⇒ Object
-
#initialize(calcField, datasource = nil) ⇒ FieldCalculation
constructor
A new instance of FieldCalculation.
- #resolveFormula ⇒ Object
Methods included from TabTool
#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig
Methods inherited from TabClass
#docFile, #emit, #setDocFileName
Constructor Details
#initialize(calcField, datasource = nil) ⇒ FieldCalculation
Returns a new instance of FieldCalculation.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/twb/fieldcalculation.rb', line 57 def initialize(calcField, datasource=nil) raise ArgumentError.new("FieldCalculation must be initialized with a CalculatedField, has been provided with a #{calcField.class}") if calcField.class != Twb::CalculatedField init # initLogger @field = calcField calcNode = calcField.node @istableCalc = false # @localEmit = false emit "FieldCalculation calcNode.nil? :: #{calcNode.nil?} " unless calcNode.nil? @node = calcNode.at_xpath('./calculation') @fieldNode = calcField.node @dataSource = datasource @class = attribText(@node, 'class') @remoteFields = {} if 'categorical-bin'.eql? @class @name = @node.attribute('column').text.gsub(/^\[|\]$/,'') # assumes the column attribute exists @caption = attribText(@fieldNode, 'caption') uiname = if datasource.nil? @name else datasource.fieldUIName(@name) end @uiname = "#{uiname} <<group>>" @has_formula = true @formula = "grouped <<[#{uiname}]>> values" @formulaLines = [ @formula ] @formulaFlat = @formula @comments = [ ] @is_lod = false else @caption = calcField. @name = calcField.name @uiname = calcField.uiname #-- @scopeIsolation = attribText(@node, 'scope-isolation') #-- Formula -- @has_formula = @node.has_attribute?('formula') if @has_formula @formula = @node.attribute('formula').text.gsub(/\r\n/,"\n") emit "\n-- init: #{@formula}" @formulaUC = @formula.upcase @formulaLines = formula.split(/\n|\r\n/) @formulaFlat = flattenFormula(@formulaLines) @comments = getComments(@formulaLines) @lodCodePos = @formula =~ /^[ ]*{[ ]*(fixed|include|exclude)[ ]*/i @is_lod = !lodCodePos.nil? && @lodCodePos >= 0 @is_tableCalc = @@tableCalcs.any? { |tc| @formulaUC.include?(tc) } #assessTableCalc @formula # puts "#{@lodCodePos} \t #{@is_lod} \t #{@is_lod.class} \t => #{@formula}" end end end end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
28 29 30 |
# File 'lib/twb/fieldcalculation.rb', line 28 def @caption end |
#class ⇒ Object (readonly)
Returns the value of attribute class.
38 39 40 |
# File 'lib/twb/fieldcalculation.rb', line 38 def class @class end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
40 41 42 |
# File 'lib/twb/fieldcalculation.rb', line 40 def comments @comments end |
#dataSource ⇒ Object (readonly)
Returns the value of attribute dataSource.
27 28 29 |
# File 'lib/twb/fieldcalculation.rb', line 27 def dataSource @dataSource end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
27 28 29 |
# File 'lib/twb/fieldcalculation.rb', line 27 def field @field end |
#fieldNode ⇒ Object (readonly)
Returns the value of attribute fieldNode.
27 28 29 |
# File 'lib/twb/fieldcalculation.rb', line 27 def fieldNode @fieldNode end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
39 40 41 |
# File 'lib/twb/fieldcalculation.rb', line 39 def fields @fields end |
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
30 31 32 |
# File 'lib/twb/fieldcalculation.rb', line 30 def formula @formula end |
#formulaFlat ⇒ Object (readonly)
Returns the value of attribute formulaFlat.
33 34 35 |
# File 'lib/twb/fieldcalculation.rb', line 33 def formulaFlat @formulaFlat end |
#formulaFlatResolved ⇒ Object (readonly)
Returns the value of attribute formulaFlatResolved.
34 35 36 |
# File 'lib/twb/fieldcalculation.rb', line 34 def formulaFlatResolved @formulaFlatResolved end |
#formulaLines ⇒ Object (readonly)
Returns the value of attribute formulaLines.
35 36 37 |
# File 'lib/twb/fieldcalculation.rb', line 35 def formulaLines @formulaLines end |
#formulaLinesCount ⇒ Object (readonly)
Returns the value of attribute formulaLinesCount.
35 36 37 |
# File 'lib/twb/fieldcalculation.rb', line 35 def formulaLinesCount @formulaLinesCount end |
#formulaResolved ⇒ Object (readonly)
Returns the value of attribute formulaResolved.
32 33 34 |
# File 'lib/twb/fieldcalculation.rb', line 32 def formulaResolved @formulaResolved end |
#formulaResolvedLines ⇒ Object (readonly)
Returns the value of attribute formulaResolvedLines.
35 36 37 |
# File 'lib/twb/fieldcalculation.rb', line 35 def formulaResolvedLines @formulaResolvedLines end |
#formulaUC ⇒ Object (readonly)
Returns the value of attribute formulaUC.
31 32 33 |
# File 'lib/twb/fieldcalculation.rb', line 31 def formulaUC @formulaUC end |
#has_formula ⇒ Object (readonly)
Returns the value of attribute has_formula.
29 30 31 |
# File 'lib/twb/fieldcalculation.rb', line 29 def has_formula @has_formula end |
#is_lod ⇒ Object (readonly)
Returns the value of attribute is_lod.
37 38 39 |
# File 'lib/twb/fieldcalculation.rb', line 37 def is_lod @is_lod end |
#is_tableCalc ⇒ Object (readonly)
Returns the value of attribute is_tableCalc.
36 37 38 |
# File 'lib/twb/fieldcalculation.rb', line 36 def is_tableCalc @is_tableCalc end |
#lodCodePos ⇒ Object (readonly)
Returns the value of attribute lodCodePos.
37 38 39 |
# File 'lib/twb/fieldcalculation.rb', line 37 def lodCodePos @lodCodePos end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/twb/fieldcalculation.rb', line 28 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
27 28 29 |
# File 'lib/twb/fieldcalculation.rb', line 27 def node @node end |
#referencedFields ⇒ Object (readonly)
Returns the value of attribute referencedFields.
39 40 41 |
# File 'lib/twb/fieldcalculation.rb', line 39 def referencedFields @referencedFields end |
#remoteFields ⇒ Object (readonly)
Returns the value of attribute remoteFields.
39 40 41 |
# File 'lib/twb/fieldcalculation.rb', line 39 def remoteFields @remoteFields end |
#scopeIsolation ⇒ Object (readonly)
Returns the value of attribute scopeIsolation.
38 39 40 |
# File 'lib/twb/fieldcalculation.rb', line 38 def scopeIsolation @scopeIsolation end |
#uiname ⇒ Object (readonly)
Returns the value of attribute uiname.
28 29 30 |
# File 'lib/twb/fieldcalculation.rb', line 28 def uiname @uiname end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
40 41 42 |
# File 'lib/twb/fieldcalculation.rb', line 40 def uuid @uuid end |
Instance Method Details
#attribText(node, attribute) ⇒ Object
119 120 121 |
# File 'lib/twb/fieldcalculation.rb', line 119 def attribText(node, attribute) node.attribute(attribute).nil? ? nil : node.attribute(attribute).text end |
#enlineResolvedFormula ⇒ Object
154 155 |
# File 'lib/twb/fieldcalculation.rb', line 154 def enlineResolvedFormula end |
#flattenFormula(lines) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/twb/fieldcalculation.rb', line 166 def flattenFormula lines formula = '' lines.each do |line| # line.strip formula += ' ' + line.gsub(/\/\/.*/, '') # unless line =~ /^[ ]*\/\// end return formula.strip end |
#flattenResolvedFormula ⇒ Object
161 162 163 164 |
# File 'lib/twb/fieldcalculation.rb', line 161 def flattenResolvedFormula formula = formulaResolved formula.gsub(/\n/, ' ') end |
#getComments(lines) ⇒ Object
176 177 178 179 180 181 182 183 184 |
# File 'lib/twb/fieldcalculation.rb', line 176 def getComments lines comments = '' lines.each do |line| if line =~ /\/\// then comments += ' ' + line.gsub(/^.*\/\//,'// ') end end return comments.strip end |
#id ⇒ Object
111 112 113 |
# File 'lib/twb/fieldcalculation.rb', line 111 def id @id ||= @id = @formulaFlat.hash + calcField.hash end |
#resolveFormula ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/twb/fieldcalculation.rb', line 127 def resolveFormula # puts "\ndef resolveFormula:\n--\n#{@formula}" formula = @formula # parseFormFields # - extracts the fields from the formula; as persisted they're the internal names referencedFields.each do |calcField| # if calcField.techUIdiff # # puts ":::: #{calcField.techCode} // #{calcField.uiCode}" # formula = formula.gsub(calcField.techCode,calcField.uiCode) # # puts ":--: #{formula}" # end end return formula end |