Class: RailsDataExplorer::DataType::Quantitative
- Inherits:
-
RailsDataExplorer::DataType
- Object
- RailsDataExplorer::DataType
- RailsDataExplorer::DataType::Quantitative
- Defined in:
- lib/rails-data-explorer/data_type/quantitative.rb,
lib/rails-data-explorer/data_type/quantitative/decimal.rb,
lib/rails-data-explorer/data_type/quantitative/integer.rb,
lib/rails-data-explorer/data_type/quantitative/temporal.rb
Defined Under Namespace
Classes: Decimal, Integer, Temporal
Instance Method Summary collapse
-
#all_available_chart_types ⇒ Object
This is an abstract class.
- #axis_scale(data_series, d3_or_vega) ⇒ Object
- #axis_tick_format(values) ⇒ Object
- #descriptive_statistics(values) ⇒ Object
-
#descriptive_statistics_table(values) ⇒ Object
Returns an object that describes a statistics table.
Methods inherited from RailsDataExplorer::DataType
Instance Method Details
#all_available_chart_types ⇒ Object
This is an abstract class. Use sub_classes
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails-data-explorer/data_type/quantitative.rb', line 7 def all_available_chart_types [ # { # chart_class: Chart::BoxPlot, # chart_roles: [:y], # dimensions_count_min: 1, # dimensions_count_max: 1 # }, { chart_class: Chart::HistogramQuantitative, chart_roles: [:x], dimensions_count_min: 1, dimensions_count_max: 1 }, { chart_class: Chart::BoxPlotGroup, chart_roles: [:x], dimensions_count_min: 2, dimensions_count_max: 2, }, { chart_class: Chart::Scatterplot, chart_roles: [:x, :y, :size], dimensions_count_min: 2 }, { chart_class: Chart::DescriptiveStatisticsTable, chart_roles: [:any], dimensions_count_min: 1, dimensions_count_max: 1 }, { chart_class: Chart::ParallelCoordinates, chart_roles: [:dimension], dimensions_count_min: 3, }, ].freeze end |
#axis_scale(data_series, d3_or_vega) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/rails-data-explorer/data_type/quantitative.rb', line 125 def axis_scale(data_series, d3_or_vega) # Log scales can't handle 0 values if data_series.min_val > 0.0 && data_series.has_large_dynamic_range? { d3: 'd3.scale.log', vega: 'log' }[d3_or_vega] else { d3: 'd3.scale.linear', vega: 'linear' }[d3_or_vega] end end |
#axis_tick_format(values) ⇒ Object
121 122 123 |
# File 'lib/rails-data-explorer/data_type/quantitative.rb', line 121 def axis_tick_format(values) raise "Implement me in sub_class" end |
#descriptive_statistics(values) ⇒ Object
46 47 48 49 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 95 96 |
# File 'lib/rails-data-explorer/data_type/quantitative.rb', line 46 def descriptive_statistics(values) non_nil_values = values.find_all { |e| !(e.nil? || Float::NAN == e) } stats = ::DescriptiveStatistics::Stats.new(non_nil_values) ruby_formatters = { integer: Proc.new { |v| v.nil? ? 'Null' : number_with_delimiter(v.round) }, decimal: Proc.new { |v| case when v.nil? 'Null' when v.is_a?(Float) && v.nan? 'NaN' else number_with_precision( v, precision: 3, significant: true, strip_insignificant_zeros: true, delimiter: ',' ) end }, pass_through: Proc.new { |v| (v.nil? || Float::NAN == v) ? 'NaN' : v }, } [ { label: 'Min', value: stats.min, ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '1%ile', value: stats.value_from_percentile(1), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '5%ile', value: stats.value_from_percentile(5), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '10%ile', value: stats.value_from_percentile(10), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '25%ile', value: stats.value_from_percentile(25), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: 'Median', value: stats.median, ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '75%ile', value: stats.value_from_percentile(75), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '90%ile', value: stats.value_from_percentile(90), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '95%ile', value: stats.value_from_percentile(95), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: '99%ile', value: stats.value_from_percentile(99), ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: 'Max', value: stats.max, ruby_formatter: ruby_formatters[:decimal], table_row: 1 }, { label: 'Range', value: stats.range, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Mean', value: stats.mean, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Mode', value: stats.mode, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Count', value: values.length, ruby_formatter: ruby_formatters[:integer], table_row: 2 }, { label: 'Sum', value: non_nil_values.inject(0) { |m,e| m += e }, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Variance', value: stats.variance, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Std. dev.', value: stats.standard_deviation, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Rel. std. dev.', value: stats.relative_standard_deviation, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Skewness', value: stats.skewness, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: 'Kurtosis', value: stats.kurtosis, ruby_formatter: ruby_formatters[:decimal], table_row: 2 }, { label: '', value: '', ruby_formatter: ruby_formatters[:pass_through], table_row: 2 }, ] end |
#descriptive_statistics_table(values) ⇒ Object
Returns an object that describes a statistics table.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rails-data-explorer/data_type/quantitative.rb', line 99 def descriptive_statistics_table(values) desc_stats = descriptive_statistics(values) table = Utils::RdeTable.new([]) [1,2].each do |table_row| table.rows << Utils::RdeTableRow.new( :tr, desc_stats.find_all { |e| table_row == e[:table_row] }.map { |stat| Utils::RdeTableCell.new(:th, stat[:label], ruby_formatter: Proc.new { |e| e }, css_class: 'rde-cell-label') }, css_class: 'rde-column_header' ) table.rows << Utils::RdeTableRow.new( :tr, desc_stats.find_all { |e| table_row == e[:table_row] }.map { |stat| Utils::RdeTableCell.new(:td, stat[:value], ruby_formatter: stat[:ruby_formatter], css_class: 'rde-cell-value') }, css_class: 'rde-data_row' ) end table end |