Class: Superset::Dashboard::Compare
- Inherits:
-
Object
- Object
- Superset::Dashboard::Compare
- Defined in:
- lib/superset/dashboard/compare.rb
Instance Attribute Summary collapse
-
#first_dashboard_id ⇒ Object
readonly
Returns the value of attribute first_dashboard_id.
-
#second_dashboard_id ⇒ Object
readonly
Returns the value of attribute second_dashboard_id.
Instance Method Summary collapse
- #cross_filter_configuration(dashboard_result) ⇒ Object
- #first_dashboard ⇒ Object
-
#initialize(first_dashboard_id:, second_dashboard_id:) ⇒ Compare
constructor
A new instance of Compare.
- #list_charts ⇒ Object
- #list_cross_filters ⇒ Object
- #list_cross_filters_for(dashboard_result) ⇒ Object
- #list_datasets ⇒ Object
- #list_native_filters ⇒ Object
- #list_native_filters_for(dashboard_result) ⇒ Object
- #native_filter_configuration(dashboard_result) ⇒ Object
- #perform ⇒ Object
- #second_dashboard ⇒ Object
Constructor Details
#initialize(first_dashboard_id:, second_dashboard_id:) ⇒ Compare
Returns a new instance of Compare.
13 14 15 16 |
# File 'lib/superset/dashboard/compare.rb', line 13 def initialize(first_dashboard_id: , second_dashboard_id: ) @first_dashboard_id = first_dashboard_id @second_dashboard_id = second_dashboard_id end |
Instance Attribute Details
#first_dashboard_id ⇒ Object (readonly)
Returns the value of attribute first_dashboard_id.
11 12 13 |
# File 'lib/superset/dashboard/compare.rb', line 11 def first_dashboard_id @first_dashboard_id end |
#second_dashboard_id ⇒ Object (readonly)
Returns the value of attribute second_dashboard_id.
11 12 13 |
# File 'lib/superset/dashboard/compare.rb', line 11 def second_dashboard_id @second_dashboard_id end |
Instance Method Details
#cross_filter_configuration(dashboard_result) ⇒ Object
81 82 83 |
# File 'lib/superset/dashboard/compare.rb', line 81 def cross_filter_configuration(dashboard_result) JSON.parse(dashboard_result['json_metadata'])['chart_configuration'].map {|k, v| [ v['id'], v['crossFilters'].to_s ] } end |
#first_dashboard ⇒ Object
30 31 32 |
# File 'lib/superset/dashboard/compare.rb', line 30 def first_dashboard @first_dashboard ||= Get.new(first_dashboard_id).result end |
#list_charts ⇒ Object
44 45 46 47 48 49 |
# File 'lib/superset/dashboard/compare.rb', line 44 def list_charts puts "\n ====== DASHBOARD CHARTS ====== " Superset::Dashboard::Charts::List.new(first_dashboard_id).list puts '' Superset::Dashboard::Charts::List.new(second_dashboard_id).list end |
#list_cross_filters ⇒ Object
58 59 60 61 62 63 |
# File 'lib/superset/dashboard/compare.rb', line 58 def list_cross_filters puts "\n ====== DASHBOARD CROSS FILTERS ====== " list_cross_filters_for(first_dashboard) puts '' list_cross_filters_for(second_dashboard) end |
#list_cross_filters_for(dashboard_result) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/superset/dashboard/compare.rb', line 85 def list_cross_filters_for(dashboard_result) puts Terminal::Table.new( title: [dashboard_result['id'], dashboard_result['dashboard_title']].join(' - '), headings: ['Chart Id', 'Cross Filter Config'], rows: cross_filter_configuration(dashboard_result) ) end |
#list_datasets ⇒ Object
38 39 40 41 42 |
# File 'lib/superset/dashboard/compare.rb', line 38 def list_datasets puts "\n ====== DASHBOARD DATASETS ====== " Superset::Dashboard::Datasets::List.new(first_dashboard_id).list Superset::Dashboard::Datasets::List.new(second_dashboard_id).list end |
#list_native_filters ⇒ Object
51 52 53 54 55 56 |
# File 'lib/superset/dashboard/compare.rb', line 51 def list_native_filters puts "\n ====== DASHBOARD NATIVE FILTERS ====== " list_native_filters_for(first_dashboard) puts '' list_native_filters_for(second_dashboard) end |
#list_native_filters_for(dashboard_result) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/superset/dashboard/compare.rb', line 73 def list_native_filters_for(dashboard_result) puts Terminal::Table.new( title: [dashboard_result['id'], dashboard_result['dashboard_title']].join(' - '), headings: ['Filter Name', 'Dataset Id'], rows: native_filter_configuration(dashboard_result) ) end |
#native_filter_configuration(dashboard_result) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/superset/dashboard/compare.rb', line 65 def native_filter_configuration(dashboard_result) rows = [] JSON.parse(dashboard_result['json_metadata'])['native_filter_configuration'].each do |filter| filter['targets'].each {|t| rows << [ t['column']['name'], t['datasetId'] ] } end rows end |
#perform ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/superset/dashboard/compare.rb', line 19 def perform raise "Error: first_dashboard_id integer is required" unless first_dashboard_id.present? && first_dashboard_id.is_a?(Integer) raise "Error: second_dashboard_id integer is required" unless second_dashboard_id.present? && second_dashboard_id.is_a?(Integer) list_datasets list_charts list_native_filters list_cross_filters end |