Class: Twb::Analysis::CategoricalColorCodingAnalyzer

Inherits:
Object
  • Object
show all
Includes:
TabTool
Defined in:
lib/twb/analysis/datasources/categoricalcolorcodinganalyzer.rb

Instance Attribute Summary collapse

Attributes included from TabTool

#alerts, #docDir, #docfiles, #funcdoc, #id, #licensed, #logfilename, #logger, #loglevel, #properties, #ttdocdir, #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

#initializeCategoricalColorCodingAnalyzer

Returns a new instance of CategoricalColorCodingAnalyzer.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/twb/analysis/datasources/categoricalcolorcodinganalyzer.rb', line 28

def initialize
  init
  @funcdoc    = {:class=>self.class, :blurb=>"Analyze Fields' values categorical color coding from Tableau Workbooks.", :description=>nil,}
  #--
  docFileName = docFile('CategoricalColorMappings.csv')
  $csv  = CSV.open(docFileName,'w')
  $csv  << ['Workbook', 'Workbook Dir', 'Data Source', 'Field Code', 'Field Tech', 'Field', 'Value', 'Colour']
  addDocFile docFileName, "Workbooks, Data Sources, Fields, and the Fields' members' categorical color codings."
  #--
  @twbCnt    = 0
  @dscnt     = 0
  @fieldsCnt = 0
end

Instance Attribute Details

#localEmitObject

Returns the value of attribute localEmit.



26
27
28
# File 'lib/twb/analysis/datasources/categoricalcolorcodinganalyzer.rb', line 26

def localEmit
  @localEmit
end

Instance Method Details

#metricsObject



42
43
44
45
46
47
48
# File 'lib/twb/analysis/datasources/categoricalcolorcodinganalyzer.rb', line 42

def metrics
  {
    # '# of Workbooks'         => @twbcount,
    '# of data sources'      => @dscnt,
    '# of Worksheet Fields'  => @fieldsCnt
  }
end

#processTWB(twb) ⇒ Object



50
51
52
53
54
55
56
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
# File 'lib/twb/analysis/datasources/categoricalcolorcodinganalyzer.rb', line 50

def processTWB twb
  @twb = twb
  twbName  = twb.name
  twbDir   = twb.dir
  emit "   -- #{twbName}"
  @twbCnt += 1
  @twbDomainsLoaded = false
  # <style>
  #   <style-rule element='mark'>
  #     <encoding attr='color' field='[none:Calculation_267401288043974656:nk]' type='palette'>
  #       <map to='#1f77b4'>
  #         <bucket>&quot;Consistently Meets Expectations&quot;</bucket>
  twb.datasources.each do |ds|
      dsName = ds.uiname
      puts "\t - #{dsName}"
      coloredFields = ds.node.xpath('.//style/style-rule/encoding[@attr="color"]')
      # puts "\t   #{coloredFields.length} \t #{coloredFields.class} \t #{coloredFields.nil?}"
      coloredFields.each do |cf|
          puts "Attributes: #{cf.attributes}"
          fieldCode = cf['field']
          fieldTech = fieldCode.sub(/^\[/,'').sub(/\]$/,'').sub(/^(none|attr|usr):/,'').sub(/:nk$/,'')
          fieldUI   = ds.fieldUIName fieldTech
          # puts "\t   - #{field}"
          maps  = cf.xpath('./map')
          maps.each do |map|
              puts "MAP\n---\n#{map}\n--"
              color  = map['to']
              value  = ''
              values = map.xpath('.//bucket')
              unless values.nil?
                if values.length == 1
                  value = values.first.text.gsub(/^"/,'').gsub(/"$/,'')
                else
                  values.each do |bv| 
                    value += "::#{bv.text}"
                  end
                end
              end
              # puts "\t     - #{color}  ->  #{value}"
              $csv << [twbName, twbDir, dsName, fieldCode, fieldTech, fieldUI, value, color]
              puts "VALUE: #{value}"
          end
      end
  end
end