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 Dir',
 '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 Length',
 'Formula',
 'Formula (tech)',
 'Formula Comments',
 'Formula LOD?'
]
@@calcLinesCSVFileName =
'CalculatedFieldFormulaLines.csv'
@@calcLinesCSVFileHeader =
['Calc Field #',
 'Workbook',      'Workbook Dir',
 '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 =
['Rec #',
   'Workbook',   'Workbook Dir',
   'Data Source',
   'Field - Calculated',
   'Formula (tech)',
   'Formula',
   'Field - Referenced (tech)',
   'Field - Referenced',
   'Data Source + Field - Referenced',
   'Table'
]
@@dotHeader =
"  digraph g {\n      graph [rankdir=\"LR\" splines=line];\n      node  [shape=\"box\"  width=\"2\"];\n\n"

Instance Attribute Summary collapse

Attributes included from Graph

#edges, #nodes

Attributes included from TabTool

#alerts, #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

Returns a new instance of CalculatedFieldsAnalyzer.



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
110
111
# File 'lib/twb/analysis/CalculatedFields/CalculatedFieldsAnalyzer.rb', line 84

def initialize(**args)
    @args = args
    @csvAdd  = args[:csvMode] == :add
    @csvMode = @csvAdd ? 'a' : 'w'
    # emit true, "@csvAdd : #{@csvAdd}" 

    # emit true, "@csvMode: #{@csvMode}" 

    init
    @funcdoc = {:class=>self.class, :blurb=>'Analyze Calculated Fields', :description=>'Calculated fields can be complex, this tool provides robust coverage.',}
    #-- CSV records collectors

    @csvCalculatedFields = []
    @csvFormulaFields    = []
    @csvFormulaLines     = []
    #-- Counters setup --

    @twbCount              = 0
    @calculatedFieldsCount = 0
    @referencedFieldsCount = 0
    #--

    @referencedFields     = SortedSet.new
    #--

    @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)
    #--

    @localEmit  = false
    @imageFiles = []
    #--

    @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



145
146
147
148
149
150
151
# File 'lib/twb/analysis/CalculatedFields/CalculatedFieldsAnalyzer.rb', line 145

def loadMetrics
  @metrics = {
               '# of Workbooks'         => @twbCount,
               '# of Calculated Fields' => @calculatedFieldsCount,
               '# of Referenced Fields' => @referencedFieldsCount,
             }
end

#processTWB(workbook) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/twb/analysis/CalculatedFields/CalculatedFieldsAnalyzer.rb', line 113

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))

  @edges    = Set.new
  #-- processing

  dss = @twb.datasources
  # puts "    # data sources: #{dss.length}"

  @twbRootFields = Set.new
  @twbFields = {}
  @nodes     = Set.new
  dss.each do |ds|
    # 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