class Twb::Analysis::CategoricalColorCodingAnalyzer

Attributes

localEmit[RW]

Public Class Methods

new() click to toggle source
# 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

Public Instance Methods

metrics() click to toggle source
# 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) click to toggle source
# 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