Top Level Namespace

Defined Under Namespace

Modules: Flow, Graph, TabTool, Twb Classes: CodedField, HashToHTMLList, There

Instance Method Summary collapse

Instance Method Details

#emit(stuff) ⇒ Object



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

def emit stuff
    $pFile.puts stuff
           puts stuff if $localEmit
end

#initObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/twb/countNodes.rb', line 5

def init
  system 'cls'
  $pFile = File.open('sqlFromTwbDc.txt','w')

  sqiCSV = 'TWBFieldsByType.csv'
  $fieldsCSV = CSV.open(sqiCSV, 'w')
  $fieldsCSV    << [
                    'TWB', 
                    'Data Connection - UI', 
                    'Field Name', 
                    'Field Type', 
                   ]
  $path    = if ARGV.empty? then '**/*.twb' else ARGV[0] end
  emit " "
  emit " Generating SQL Create Table code for Tableau Workbook Data Connections (TWDCs)."
  emit " Each TWDC will have it's own *.sql file containing the SQL code.\n "
  emit " Looking for Workbooks matching: '#{$path}'  - from: #{ARGV[0]}\n\n "
end

#localColumns(dataSource) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/twb/findDSFields.rb', line 80

def localColumns dataSource
  emit "\t localColumns  " #connClass: '%s'" % [connClass]
  colNodes = dataSource.xpath('./column')
  emit "  colNodes.size: #{colNodes.size}"
  fields = {}
  colNodes.each do |node|
    calcField = !node.at_xpath('./calculation').nil?
    caption   = node.attribute('caption')
    name      = node.attribute('name').text.gsub(/^\[/,'').gsub(/\]$/,'')
    type      = node.attribute('datatype')
    emit "  \t    name: %s\n \t    type: %s\n \t caption: %s" % [name, type, caption]
    caption   = name if caption.nil?
    emit "  \t caption: %s  \n " % [caption]
    fields[caption] = {'type' => type, 'calcField' => calcField}
  end
  return fields
end

#metaDataRecords(dataSource) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/twb/findDSFields.rb', line 67

def metaDataRecords dataSource
  emit "\t metaDataRecords  " #connClass: '%s'" % [connClass]
  mdNodes = dataSource.xpath('./connection/metadata-records/metadata-record[@class="column"]')
  emit "  mdNodes.size: #{mdNodes.size}"
  fields = {}
  mdNodes.each do |node|
    name = node.xpath('./local-name').text.gsub(/^\[/,'').gsub(/\]$/,'')
    type = node.xpath('./local-type').text
    fields[name] = {'type' => type}
  end
  return fields
end

#method_nameObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/twb/countNodes.rb', line 24

def method_name
    datasources     = {}
    dataSourcesNode  = doc.at_xpath('//workbook/datasources')
    dataSourcesNodes = doc.xpath('//workbook/datasources/datasource').to_a
    puts "  dsn: #{dataSourcesNodes}"
    datasourceNodes.each do |node|
        datasource = Twb::DataSource.new(node)
        datasources[datasource.name] = datasource
    end
end

#proc(file) ⇒ Object



47
48
49
# File 'lib/twb/countNodes.rb', line 47

def proc file
  emit "\n == #{file}"
end

#process(file) ⇒ Object



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
# File 'lib/twb/countNodes.rb', line 51

def process file
  emit "\n == #{file}"
  doc = Nokogiri::XML(open(file))
  dataSourcesNodes = doc.xpath('//workbook/datasources/datasource')
  dataSourcesNodes.each do |ds|
    emit "\n   dc: #{ds.attribute('caption')}"
    emit   "   dn: #{ds.attribute('name')}\n   ---"
    typeCounts = {}
    $paths.each do |type, path|
      nodes = ds.xpath(path).to_a
#      emit "     : %3i  %-17s  %-s" % [nodes.size, type, path]
      typeCnt = nodes.size
      nodes.each do |n|
        $fieldsCSV << [file,ds.attribute('name'),n.attribute('name'),type]
      end
      if type == 'Columns' then 
        calcCnt = 0
        nodes.each do |n|
          calc = n.xpath('./calculation')
#          emit "    c:   #{calc.size} "
          calcCnt += calc.size
        end
#        emit '   ---'
#        emit "   c#: %3i " % [calcCnt]
#        emit "  !c#: %3i " % [nodes.size - calcCnt]
        typeCounts['Columns']            = nodes.size 
        typeCounts['Columns - calc']     = calcCnt 
        typeCounts['Columns - not calc'] = nodes.size - calcCnt 
      else
        typeCounts[type] = typeCnt 
      end
    end
#    emit '   ---'
    typeCounts.each do |t,c|
      emit "   tc: %3i  %-s" % [c, t]
    end
  end
end

#processTwb(twbName) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/twb/listXMLNodePathsAndAttributes.rb', line 5

def processTwb twbName
    puts  "\t - #{twbName}"
    twb     = Twb::Workbook.new twbName
    nokodoc = twb.node   #Nokogiri::XML(open('dataSources.xml'))
    # $nodePaths = SortedSet.new

    $csvFile  = CSV.open('xmlNodesAndAttributes.csv','w')
    $csvFile << ['Workbook', 'Workbook Directory', 'Node Name', 'Node Path', 'Attr Name', 'Attr Value']
    nodes    = nokodoc.xpath('//.')
    nodes.each do |n|
        nodeName = n.name
        nodePath = n.path.gsub(/\[[0-9]+\]/,'')
        attrs    = n.attributes
        attrs.each do |attrName,attrValue|
            $csvFile << [twbName, twbDir, nodeName, nodePath, attrName, attrValue]
        end
        if attrs.empty?
            $csvFile << [ twbName, twbDir, nodeName, nodePath, nil, nil ]
        end
        # $nodePaths << n.path.gsub(/\[[0-9]+\]/,'').gsub('/content/workbook/','')
    end
    $twbCount      += 1
end

#relationFields(dataSource, connClass) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/twb/findDSFields.rb', line 57

def relationFields dataSource, connClass
  emit "\t relationFields  connClass: '%s'" % [connClass]
  xPaths     = $relClassPaths[connClass]
  emit "\t xPaths: #{xPaths}"
  fnodesPath = xPaths['fieldXPath']
  fnamePath  = xPaths['nameXPath']
  fieldNodes = dataSource.xpath(fnodesPath)
    
end

#showPathsObject



139
140
141
142
143
144
145
146
147
# File 'lib/twb/findDSFields.rb', line 139

def showPaths
  $paths.each do |type, paths|
  	emit "  #{type}"
    paths.each do |key, value|
      emit "      : %10s  =>  %-s" % [key, value]    
    end
    puts " "
  end
end