Skip to content

Instantly share code, notes, and snippets.

@ChrisGerrard
Created September 14, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisGerrard/aefbc0afe7231e294d9d0fe26ef8e556 to your computer and use it in GitHub Desktop.
Save ChrisGerrard/aefbc0afe7231e294d9d0fe26ef8e556 to your computer and use it in GitHub Desktop.
Ruby script for documenting Tableau Calculated Fields
# analyzeCalculatedFields.rb Copyright (C) 2018 Chris Gerrard
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
system 'cls'
require 'twb'
$analysisFiles = {}
$twbCount = 0
$calcFields = 0
$formulaFields = 0
$nodes = Set.new
$edges = Set.new
$nodesCnt = 0
$edgesCnt = 0
$analyzer = Twb::Analysis::CalculatedFieldsAnalyzer.new
$markdown = Twb::Analysis::CalculatedFields::MarkdownEmitter.new
def processTwb twbName
twb = Twb::Workbook.new twbName
puts "\t - #{twb.name}"
# --
$analyzer.processTWB twb
$nodes.merge $analyzer.nodes
$edges.merge $analyzer.edges
# --
$markdown.processTWB twb
# --
$twbCount += 1
$calcFields += $analyzer.calculatedFieldsCount
$formulaFields += $analyzer.referencedFieldsCount
# --
$nodesCnt += $analyzer.nodes.length
$edgesCnt += $analyzer.edges.length
end
puts "\n\n "
puts " #{$analyzer.funcdoc[:class]}"
puts " #{$analyzer.funcdoc[:blurb]}"
puts "\n "
path = if ARGV.empty? then ['*.twb','*.twbx'] else ARGV[0] end
puts " Processing Workbooks matching: '#{path}'\n "
Dir.glob(path) { |twb| processTwb twb }
puts "\n "
puts " Analysis complete, identified"
$analyzer.metrics.each do |m,v|
puts " %-25s : %5s" % [m,v]
end
$analyzer.docfilesdoc.each do |l|
puts ' ' + l
end
puts "\n\n That's all, folks.\n "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment