Class: Twb::FieldCalculation

Inherits:
TabClass show all
Includes:
TabTool
Defined in:
lib/twb/fieldcalculation.rb

Constant Summary collapse

@@tableCalcs =
[ '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'
]

Constants included from TabTool

TabTool::TTDOCDIR

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docfiles, #funcdoc, #licensed, #logfilename, #logger, #loglevel, #metrics, #properties, #ttdocdir, #type

Attributes inherited from TabClass

#properties, #ttlogfilename, #type

Instance Method Summary collapse

Methods included from TabTool

#addDocFile, #alert, #docFile, #docFileMaxNameLen, #docfilesdoc, #emit, #emitCSV, #finis, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?

Methods inherited from TabClass

#docFile, #emit, #initialize, #setDocFileName

Constructor Details

This class inherits a constructor from Twb::TabClass

Instance Attribute Details

#calcFieldsObject (readonly)

Returns the value of attribute calcFields.



38
39
40
# File 'lib/twb/fieldcalculation.rb', line 38

def calcFields
  @calcFields
end

#captionObject (readonly)

Returns the value of attribute caption.



27
28
29
# File 'lib/twb/fieldcalculation.rb', line 27

def caption
  @caption
end

#classObject (readonly)

Returns the value of attribute class.



37
38
39
# File 'lib/twb/fieldcalculation.rb', line 37

def class
  @class
end

#commentsObject (readonly)

Returns the value of attribute comments.



39
40
41
# File 'lib/twb/fieldcalculation.rb', line 39

def comments
  @comments
end

#dataSourceObject (readonly)

Returns the value of attribute dataSource.



26
27
28
# File 'lib/twb/fieldcalculation.rb', line 26

def dataSource
  @dataSource
end

#fieldObject (readonly)

Returns the value of attribute field.



26
27
28
# File 'lib/twb/fieldcalculation.rb', line 26

def field
  @field
end

#fieldNodeObject (readonly)

Returns the value of attribute fieldNode.



26
27
28
# File 'lib/twb/fieldcalculation.rb', line 26

def fieldNode
  @fieldNode
end

#fieldsObject (readonly)

Returns the value of attribute fields.



38
39
40
# File 'lib/twb/fieldcalculation.rb', line 38

def fields
  @fields
end

#formulaObject (readonly)

Returns the value of attribute formula.



29
30
31
# File 'lib/twb/fieldcalculation.rb', line 29

def formula
  @formula
end

#formulaFlatObject (readonly)

Returns the value of attribute formulaFlat.



32
33
34
# File 'lib/twb/fieldcalculation.rb', line 32

def formulaFlat
  @formulaFlat
end

#formulaFlatResolvedObject (readonly)

Returns the value of attribute formulaFlatResolved.



33
34
35
# File 'lib/twb/fieldcalculation.rb', line 33

def formulaFlatResolved
  @formulaFlatResolved
end

#formulaLinesObject (readonly)

Returns the value of attribute formulaLines.



34
35
36
# File 'lib/twb/fieldcalculation.rb', line 34

def formulaLines
  @formulaLines
end

#formulaResolvedObject (readonly)

Returns the value of attribute formulaResolved.



31
32
33
# File 'lib/twb/fieldcalculation.rb', line 31

def formulaResolved
  @formulaResolved
end

#formulaResolvedLinesObject (readonly)

Returns the value of attribute formulaResolvedLines.



34
35
36
# File 'lib/twb/fieldcalculation.rb', line 34

def formulaResolvedLines
  @formulaResolvedLines
end

#formulaUCObject (readonly)

Returns the value of attribute formulaUC.



30
31
32
# File 'lib/twb/fieldcalculation.rb', line 30

def formulaUC
  @formulaUC
end

#has_formulaObject (readonly)

Returns the value of attribute has_formula.



28
29
30
# File 'lib/twb/fieldcalculation.rb', line 28

def has_formula
  @has_formula
end

#is_lodObject (readonly)

Returns the value of attribute is_lod.



36
37
38
# File 'lib/twb/fieldcalculation.rb', line 36

def is_lod
  @is_lod
end

#is_tableCalcObject (readonly)

Returns the value of attribute is_tableCalc.



35
36
37
# File 'lib/twb/fieldcalculation.rb', line 35

def is_tableCalc
  @is_tableCalc
end

#lodCodePosObject (readonly)

Returns the value of attribute lodCodePos.



36
37
38
# File 'lib/twb/fieldcalculation.rb', line 36

def lodCodePos
  @lodCodePos
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/twb/fieldcalculation.rb', line 27

def name
  @name
end

#nodeObject (readonly)

Returns the value of attribute node.



26
27
28
# File 'lib/twb/fieldcalculation.rb', line 26

def node
  @node
end

#remoteFieldsObject (readonly)

Returns the value of attribute remoteFields.



38
39
40
# File 'lib/twb/fieldcalculation.rb', line 38

def remoteFields
  @remoteFields
end

#scopeIsolationObject (readonly)

Returns the value of attribute scopeIsolation.



37
38
39
# File 'lib/twb/fieldcalculation.rb', line 37

def scopeIsolation
  @scopeIsolation
end

#ttlogfileObject

Returns the value of attribute ttlogfile.



41
42
43
# File 'lib/twb/fieldcalculation.rb', line 41

def ttlogfile
  @ttlogfile
end

#uinameObject (readonly)

Returns the value of attribute uiname.



27
28
29
# File 'lib/twb/fieldcalculation.rb', line 27

def uiname
  @uiname
end

#uuidObject (readonly)

Returns the value of attribute uuid.



39
40
41
# File 'lib/twb/fieldcalculation.rb', line 39

def uuid
  @uuid
end

Instance Method Details

#attribText(node, attribute) ⇒ Object

def assessTableCalc formula

@@tableCalcs.any? { |tc| string.include?(tc) }

end



129
130
131
# File 'lib/twb/fieldcalculation.rb', line 129

def attribText(node, attribute)
  node.attribute(attribute).nil? ? nil : node.attribute(attribute).text
end

#enlineResolvedFormulaObject



190
191
# File 'lib/twb/fieldcalculation.rb', line 190

def enlineResolvedFormula
end

#flattenFormula(lines) ⇒ Object



202
203
204
205
206
207
208
209
# File 'lib/twb/fieldcalculation.rb', line 202

def flattenFormula lines
  formula = ''
  lines.each do |line|
      # line.strip

      formula += ' ' + line.gsub(/\/\/.*/, '') # unless line =~ /^[ ]*\/\//

  end
  return formula # .strip

end

#flattenResolvedFormulaObject



197
198
199
200
# File 'lib/twb/fieldcalculation.rb', line 197

def flattenResolvedFormula
  formula = formulaResolved
  formula.gsub(/\n/, ' ')
end

#getComments(lines) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/twb/fieldcalculation.rb', line 212

def getComments lines
  comments = ''
  lines.each do |line|
    if line =~ /\/\// then
      comments += ' ' + line.gsub(/^.*\/\//,'// ')
    end
  end
  return comments.strip
end

#idObject

def initLogger(logfile=nil)

logfilename   = docFile(logfile.nil? ? @ttlogfile : logfile)
@logger       = Logger.new(logfilename)
@logger.level = Logger::DEBUG

end



117
118
119
# File 'lib/twb/fieldcalculation.rb', line 117

def id
    @id ||= @id = @formulaFlat.hash + calcField.hash
end

#parseFormFieldsObject



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/twb/fieldcalculation.rb', line 155

def parseFormFields
  # puts "--parseFormFields"

  @fields     = Set.new    
  @calcFields = Set.new
  formula = @formulaFlat
  if !formula.nil? && formula.include?('[') && formula.include?(']')
      fields   = Set.new
      # noSqLits =  formula.gsub( /'[\[\.\]]+'/, ' ')

      quotes   =  formula.gsub('"',"'")
      noSqLits =   quotes.gsub( /'[\[\.\]]+'/, ' ')
      flatForm = noSqLits.gsub( /\n/, ' ')
      stripFrt = flatForm.gsub( /^[^\[]*[\[]/    , '['      )
      stripBck = stripFrt.gsub( /\][^\]]+$/      , ']'      )
      stripMid = stripBck.gsub( /\][^\]]{2,}\[/  , ']]..[[' )
      stripCom = stripMid.gsub( /\][ ]*,[ ]*\[/  , ']]..[[' )
      stripFns = stripMid.gsub( /\][ ]*[\*\/+\-><,=][ ]*\[/  , ']]..[[' )
      fields   = stripFns.split(']..[')
      emit "::self::: #{self} :: #{__LINE__} :: fields:'#{fields.inspect}'" 
      fields.each do |field|
        emit "::self::: #{self} :: #{__LINE__} :: field:'#{field}'" 
        cf = CalculationField.new( field.gsub(/^\[|\]$/, ''), @dataSource )
        @calcFields.add cf
        @fields.add field.gsub(/^\[|\]$/, '')
      end
  end
  return @calcFields
end

#resolveFormulaObject



137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/twb/fieldcalculation.rb', line 137

def resolveFormula
  # puts "\ndef resolveFormula:\n--\n#{@formula}"

  formula = @formula
  parseFormFields # - extracts the fields from the formula; as persisted they're the internal names

  @calcFields.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