spout 0.10.0.beta9 → 0.10.0.beta10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ require 'spout/models/tables/default'
2
+ require 'spout/helpers/array_statistics'
3
+
4
+ module Spout
5
+ module Models
6
+ module Tables
7
+ class NumericVsChoices < Spout::Models::Tables::Default
8
+
9
+ def title
10
+ "#{@chart_variable.display_name} vs #{@variable.display_name}"
11
+ end
12
+
13
+ def headers
14
+ [
15
+ [""] + Spout::Helpers::ArrayStatistics::calculations.collect{|calculation_label, calculation_method| calculation_label} + ["Total"]
16
+ ]
17
+ end
18
+
19
+ def footers
20
+ total_values = Spout::Helpers::ArrayStatistics::calculations.collect do |calculation_label, calculation_method, calculation_type, calculation_format|
21
+ total_count = @filtered_subjects.collect(&@variable.id.to_sym).send(calculation_method)
22
+ { text: Spout::Helpers::TableFormatting::format_number(total_count, calculation_type, calculation_format), style: "font-weight:bold" }
23
+ end
24
+
25
+ [
26
+ [{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting::format_number(@filtered_subjects.count, :count), style: 'font-weight:bold'}]
27
+ ]
28
+ end
29
+
30
+ def rows
31
+ filtered_domain_options(@chart_variable).collect do |option|
32
+ row_subjects = @filtered_subjects.select{ |s| s.send(@chart_variable.id) == option.value }
33
+
34
+ row_cells = Spout::Helpers::ArrayStatistics::calculations.collect do |calculation_label, calculation_method, calculation_type, calculation_format|
35
+ count = row_subjects.collect(&@variable.id.to_sym).send(calculation_method)
36
+ (count == 0 && calculation_method == :count) ? { text: '-', class: 'text-muted' } : Spout::Helpers::TableFormatting::format_number(count, calculation_type, calculation_format)
37
+ end
38
+
39
+ [option.display_name] + row_cells + [{ text: Spout::Helpers::TableFormatting::format_number(row_subjects.count, :count), style: 'font-weight:bold'}]
40
+ end
41
+ end
42
+
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,55 @@
1
+ require 'spout/models/tables/default'
2
+ require 'spout/helpers/array_statistics'
3
+
4
+ module Spout
5
+ module Models
6
+ module Tables
7
+ class NumericVsNumeric < Spout::Models::Tables::Default
8
+
9
+ def title
10
+ "#{@chart_variable.display_name} vs #{@variable.display_name}"
11
+ end
12
+
13
+ def headers
14
+ [ [""] + Spout::Helpers::ArrayStatistics::calculations.collect{|calculation_label, calculation_method| calculation_label} + ["Total"] ]
15
+ end
16
+
17
+ def footers
18
+ total_values = Spout::Helpers::ArrayStatistics::calculations.collect do |calculation_label, calculation_method, calculation_type, calculation_format|
19
+ total_count = @filtered_both_variables_subjects.collect(&@variable.id.to_sym).send(calculation_method)
20
+ { text: Spout::Helpers::TableFormatting::format_number(total_count, calculation_type, calculation_format), style: "font-weight:bold" }
21
+ end
22
+
23
+ [
24
+ [{ text: "Total", style: "font-weight:bold" }] + total_values + [{ text: Spout::Helpers::TableFormatting::format_number(@filtered_both_variables_subjects.count, :count), style: 'font-weight:bold'}]
25
+ ]
26
+ end
27
+
28
+ def rows
29
+ [:quartile_one, :quartile_two, :quartile_three, :quartile_four].collect do |quartile|
30
+ bucket = @filtered_both_variables_subjects.send(quartile)
31
+ row_subjects = bucket.collect(&@variable.id.to_sym)
32
+ data = Spout::Helpers::ArrayStatistics::calculations.collect do |calculation_label, calculation_method, calculation_type, calculation_format|
33
+ Spout::Helpers::TableFormatting::format_number(row_subjects.send(calculation_method), calculation_type, calculation_format)
34
+ end
35
+
36
+ row_name = get_row_name(quartile, bucket, row_subjects)
37
+
38
+ [row_name] + data + [{ text: Spout::Helpers::TableFormatting::format_number(row_subjects.count, :count), style: 'font-weight:bold'}]
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def get_row_name(quartile, bucket, row_subjects)
45
+ if row_subjects.size == 0
46
+ quartile.to_s.capitalize.gsub('_one', ' One').gsub('_two', ' Two').gsub('_three', ' Three').gsub('_four', ' Four')
47
+ else
48
+ "#{bucket.collect(&@chart_variable.id.to_sym).min} to #{bucket.collect(&@chart_variable.id.to_sym).max} #{@chart_variable.units}"
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ require 'spout/models/tables/default'
2
+ require 'spout/models/tables/numeric_vs_choices'
3
+ require 'spout/models/tables/choices_vs_choices'
4
+ require 'spout/models/tables/numeric_vs_numeric'
5
+ require 'spout/models/tables/choices_vs_numeric'
6
+
7
+
8
+ module Spout
9
+ module Models
10
+ module Tables
11
+
12
+ DEFAULT_CLASS = Spout::Models::Tables::Default
13
+ GRAPHABLE_CLASSES = {
14
+ 'numeric_vs_choices' => Spout::Models::Tables::NumericVsChoices,
15
+ 'choices_vs_choices' => Spout::Models::Tables::ChoicesVsChoices,
16
+ 'numeric_vs_numeric' => Spout::Models::Tables::NumericVsNumeric,
17
+ 'choices_vs_numeric' => Spout::Models::Tables::ChoicesVsNumeric
18
+ }
19
+
20
+ def self.for(variable, chart_variable, subjects, subtitle)
21
+ table_type = get_table_type(variable, chart_variable)
22
+ (GRAPHABLE_CLASSES[table_type] || DEFAULT_CLASS).new(variable, chart_variable, subjects, subtitle)
23
+ end
24
+
25
+ def self.get_table_type(variable, chart_variable)
26
+ "#{variable_to_table_type(variable)}_vs_#{variable_to_table_type(chart_variable)}"
27
+ end
28
+
29
+ # Identical to graphables, TODO: Refactor
30
+ def self.variable_to_table_type(variable)
31
+ variable_type = (variable ? variable.type : nil)
32
+ case variable_type when 'numeric', 'integer'
33
+ 'numeric'
34
+ else
35
+ variable_type
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -1,8 +1,13 @@
1
1
  require 'json'
2
2
 
3
+ require 'spout/models/record'
4
+ require 'spout/models/domain'
5
+ require 'spout/models/form'
6
+
7
+
3
8
  module Spout
4
9
  module Models
5
- class Variable
10
+ class Variable < Spout::Models::Record
6
11
  # VARIABLE_TYPES = ['choices', 'numeric', 'integer']
7
12
 
8
13
  attr_accessor :id, :folder, :display_name, :description, :type, :units, :labels, :commonly_used, :calculation
@@ -14,7 +19,7 @@ module Spout
14
19
  @errors = []
15
20
  @id = file_name.to_s.gsub(/^(.*)\/|\.json$/, '').downcase
16
21
  @folder = file_name.to_s.gsub(/^#{dictionary_root}\/variables\/|#{@id}\.json$/, '')
17
-
22
+ @form_names = []
18
23
 
19
24
  json = begin
20
25
  JSON.parse(File.read(file_name))
@@ -41,6 +46,9 @@ module Spout
41
46
  end
42
47
 
43
48
  @errors = (@errors + [error]).compact
49
+
50
+ @domain = Spout::Models::Domain.find_by_id(@domain_name)
51
+ @forms = @form_names.collect{|form_name| Spout::Models::Form.find_by_id(form_name)}.compact
44
52
  end
45
53
 
46
54
  def path
@@ -1 +1 @@
1
- ruby-2.1.3
1
+ ruby-2.1.4
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.3
3
+ - 2.1.4
data/lib/spout/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spout
3
3
  MAJOR = 0
4
4
  MINOR = 10
5
5
  TINY = 0
6
- BUILD = "beta9" # nil, "pre", "rc", "rc2"
6
+ BUILD = "beta10" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.beta9
4
+ version: 0.10.0.beta10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -129,13 +129,28 @@ files:
129
129
  - lib/spout/helpers/send_file.rb
130
130
  - lib/spout/helpers/subject_loader.rb
131
131
  - lib/spout/helpers/table_formatting.rb
132
+ - lib/spout/models/bucket.rb
132
133
  - lib/spout/models/coverage_result.rb
133
134
  - lib/spout/models/dictionary.rb
134
135
  - lib/spout/models/domain.rb
135
136
  - lib/spout/models/form.rb
137
+ - lib/spout/models/graphables.rb
138
+ - lib/spout/models/graphables/choices_vs_choices.rb
139
+ - lib/spout/models/graphables/choices_vs_numeric.rb
140
+ - lib/spout/models/graphables/default.rb
141
+ - lib/spout/models/graphables/histogram.rb
142
+ - lib/spout/models/graphables/numeric_vs_choices.rb
143
+ - lib/spout/models/graphables/numeric_vs_numeric.rb
136
144
  - lib/spout/models/option.rb
137
145
  - lib/spout/models/outlier_result.rb
146
+ - lib/spout/models/record.rb
138
147
  - lib/spout/models/subject.rb
148
+ - lib/spout/models/tables.rb
149
+ - lib/spout/models/tables/choices_vs_choices.rb
150
+ - lib/spout/models/tables/choices_vs_numeric.rb
151
+ - lib/spout/models/tables/default.rb
152
+ - lib/spout/models/tables/numeric_vs_choices.rb
153
+ - lib/spout/models/tables/numeric_vs_numeric.rb
139
154
  - lib/spout/models/variable.rb
140
155
  - lib/spout/support/javascripts/data.js
141
156
  - lib/spout/support/javascripts/highcharts-convert.js
@@ -191,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
206
  version: 1.3.1
192
207
  requirements: []
193
208
  rubyforge_project:
194
- rubygems_version: 2.2.2
209
+ rubygems_version: 2.4.2
195
210
  signing_key:
196
211
  specification_version: 4
197
212
  summary: Turn your CSV data dictionary into a JSON repository. Collaborate with others