Class: Twb::Analysis::CalculatedFieldsAnalyzer

Inherits:
Object
  • Object
show all
Includes:
Graph, TabTool
Defined in:
lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb

Constant Summary collapse

@@ttlogfile =
'CalculatedFieldsAnalyzer.ttlog'
@@gvDotLocation =
'C:\\tech\\graphviz\\Graphviz2.38\\bin\\dot.exe'
@@processName =
'.CalculatedFields'
@@calcFieldsCSVFileName =
'CalculatedFields.csv'
@@calcFieldsCSVFileHeader =
['Record #',
 'Workbook',
 # 'Workbook Modified',
 'Data Source',   'Data Source Caption', 'Data Source Name (tech)',
 'Field Name',    'Field Caption',       'Field Name (tech)',
 'Data Source + Field Name (tech)',
 'Data Type',     'Role',  'Type',
 'Class',
 'Scope Isolation',
 'Formula # Chars',
 'Formula # Lines',
 'Formula',
 'Formula (tech)',
 'Formula Comments',
 'Formula LOD?'
]
@@calcLinesCSVFileName =
'CalculatedFieldsFormulaLines.csv'
@@calcLinesCSVFileHeader =
['Calc Field #',
 'Workbook',
 # 'Workbook Modified',
 'Data Source',   'Data Source Caption', 'Data Source Name (tech)',
 'Field Name',    'Field Caption',       'Field Name (tech)',
 'Formula',       'Formula Line #',      'Formula Line'
]
@@formFieldsCSVFileName =
'CalculatedFieldsReferenced.csv'
@@formFieldsCSVFileHeader =
['Record #',
   'Workbook',
   # 'Workbook Modified',
   'Data Source',
   'Field - Calculated',
   'Formula (tech)',
   'Formula',
   'Field - Referenced (tech)',
   'Field - Referenced',
   'Data Source + Field - Referenced',
   'Table'
]

Instance Attribute Summary collapse

Attributes included from Graph

#edges, #nodes

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #properties, #type, #uuid

Instance Method Summary collapse

Methods included from TabTool

#addDocFile, #alert, #closeDocFiles, #config, #docFile, #docFileMaxNameLen, #docfilesdoc, #docfilesdocto_s, #emit, #emitCSV, #finis, #hasConfig, #init, #initCSV, #initDocDir, #initLogger, #license=, #licensed?, #loadConfig

Constructor Details

#initialize(**args) ⇒ CalculatedFieldsAnalyzer

DOTHEADER


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 88

def initialize(**args)
    emit "initialize CalculatedFieldsAnalyzer args #{args}"
    @args      = args
    @recordDir = !@args.nil? && @args[:recordDir] == true
    @ttdocdir  = @args[:ttdocdir]
    @csvAdd    = @args[:csvMode] == :add
    @csvMode   = @csvAdd ? 'a' : 'w'
    init
    @funcdoc = {:class=>self.class, :blurb=>'Analyze Calculated Fields', :description=>'Calculated fields can be complex, this tool provides robust coverage.',}
    #-- CSV records collectors
    @csvFormulaFields    = Set.new
    @csvFormulaLines     = Set.new
    #-- Counters setup --
    @twbCount              = 0
    @dataSourcesCount      = 0
    @calculatedFieldsCount = 0
    @referencedFieldsCount = 0
    #--
    @referencedFields     = SortedSet.new
    #--
    twbdirLabel = @recordDir.nil? ? nil : 'Workbook Dir'
    @csvCF   = initCSV(@@calcFieldsCSVFileName, 'Calculated fields and their formulas.',                      @@calcFieldsCSVFileHeader )
    @csvCFLs = initCSV(@@calcLinesCSVFileName,  "Calculated fields and their formulas' individual lines.",    @@calcLinesCSVFileHeader  )
    @csvFF   = initCSV(@@formFieldsCSVFileName, 'Calculated fields and the fields their formulas reference.', @@formFieldsCSVFileHeader )
    # TODO migrate addition of 'Workbook Dir' to CSV header to TabTool
    #--
    @localEmit  = false
    @imageFiles = Array.new
    #--
    @doGraph = config(:dograph)
end

Instance Attribute Details

#calculatedFieldsCountObject (readonly)

Returns the value of attribute calculatedFieldsCount


29
30
31
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 29

def calculatedFieldsCount
  @calculatedFieldsCount
end

#metricsObject (readonly)

Returns the value of attribute metrics


29
30
31
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 29

def metrics
  @metrics
end

#referencedFieldsCountObject (readonly)

Returns the value of attribute referencedFieldsCount


29
30
31
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 29

def referencedFieldsCount
  @referencedFieldsCount
end

#ttdocdirObject

Returns the value of attribute ttdocdir


30
31
32
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 30

def ttdocdir
  @ttdocdir
end

Instance Method Details

#loadMetricsObject


154
155
156
157
158
159
160
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 154

def loadMetrics
  @metrics = {
               '# of Data Sources'      => @dataSourcesCount,
               '# of Calculated Fields' => @calculatedFieldsCount,
               '# of Referenced Fields' => @referencedFieldsCount,
             }
end

#processTWB(workbook) ⇒ Object


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/twb/analysis/calculatedfields/calculatedfieldsanalyzer.rb', line 120

def processTWB workbook
  @twb = workbook.is_a?(String) ? Twb::Workbook.new(workbook) : workbook
  throw Exception unless @twb.is_a? Twb::Workbook
  emit  "- Workbook: #{workbook}"
  emit  "   version: #{@twb.version}"
  @twbDir   = @twb.dir #File.dirname(File.expand_path(workbook))
  @modTime  = @twb.modtime
  @edges    = Set.new
  #-- processing
  dss = @twb.datasources
  # puts "    # data sources: #{dss.length}"
  @twbRootFields = Set.new
  @twbFields = Hash.new { |h,k| h[k] = [] }
  @nodes     = Set.new
  dss.each do |ds|
    @dataSourcesCount += 1
    # puts "\t\t - #{ds.uiname}  \t\t #{ds.calculatedFields.length}"
    next if ds.Parameters?  # don't process the Parameters data source - Parameters' fields aren't Calculated fields for our purposes
    # dataSourceNode = Twb::Util::Graphnode.new(name: ds.uiname, id: ds.id, type: ds, properties: {workbook: workbook})
    # @nodes.add dataSourceNode
    # ds.calculatedFields.each do |calcField|
    # end
    processDataSource ds
  end
  # mapTwb
  emitGml
  @twbCount += 1
  finis
end