spout 0.8.0.beta15 → 0.8.0.rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ad7fac5482c072ad581a633a31afe12086a659
4
- data.tar.gz: 20de4cb06ae7b431d5e96aa3d82308088986ee43
3
+ metadata.gz: a512974613e6c33b378ed6d6db777f5df1dfd0bf
4
+ data.tar.gz: 28a675288a9ff58e53be07faf13979d0d0db10ef
5
5
  SHA512:
6
- metadata.gz: 5b12a3c4217018bf0cd8f55344a3d0aace8693a538555ed1d234487872631841a4c4526cabd73f44b438368729cda39ed176086ca3bfebbd1c8769d38c7c9cb1
7
- data.tar.gz: 48936868e7b7732ebd84eb2d7c71ff4724889a4395afa9e8adbbaca3ce270a3d95ec982342dde2b3a1a5258d79b9628b44f9b82c4ac0bd0fc04d1e7644458c44
6
+ metadata.gz: 844d78de2f57e79481bc7478cba6a638791ad9df92229467966c5826a00a051823c9e47e0ef597444fe78583e695e342d51ae2fbf1d28bf685cca3af392655f2
7
+ data.tar.gz: ae4016de5fd6cffc99f2c46df23d97fe42c69a1f542cff54084a179dc62896c3bbf05f46bc3b429f5e551d7c0e4693b681069ecdd3baac6b775a3e435a7a3c55
@@ -5,24 +5,27 @@ module Spout
5
5
  module Helpers
6
6
  class ChartTypes
7
7
  def self.get_bucket(buckets, value)
8
+ return nil if buckets.size == 0
8
9
  buckets.each do |b|
9
- return "#{b[0].round(1)} to #{b[1].round(1)}" if value >= b[0] and value <= b[1]
10
+ return "#{b[0]} to #{b[1]}" if value >= b[0] and value <= b[1]
10
11
  end
11
- nil
12
+ "#{buckets.last[0]} to #{buckets.last[1]}"
12
13
  end
13
14
 
14
15
  def self.continuous_buckets(values)
16
+ values.select!{|v| v.kind_of? Numeric}
15
17
  return [] if values.count == 0
16
18
  minimum_bucket = values.min
17
19
  maximum_bucket = values.max
20
+ max_buckets = 12
21
+ bucket_size = ((maximum_bucket - minimum_bucket) / max_buckets.to_f)
22
+ precision = [-Math.log10(bucket_size).floor, 0].max
18
23
 
19
- max_buckets = [(maximum_bucket - minimum_bucket), 12].min
20
- bucket_size = (maximum_bucket - minimum_bucket) / max_buckets
21
24
  buckets = []
22
25
  (0..(max_buckets-1)).to_a.each do |index|
23
- start = minimum_bucket + index * bucket_size
24
- stop = start + bucket_size
25
- buckets << [start,stop]
26
+ start = (minimum_bucket + index * bucket_size)
27
+ stop = (start + bucket_size)
28
+ buckets << [start.round(precision),stop.round(precision)]
26
29
  end
27
30
  buckets
28
31
  end
@@ -337,30 +340,28 @@ module Spout
337
340
  { title: "#{json['display_name']} vs #{chart_variable_json['display_name']}", subtitle: subtitle, headers: headers, footers: footers, rows: rows }
338
341
  end
339
342
 
340
-
341
- def self.chart_histogram_choices(chart_type, subjects, json, method)
342
- return unless domain_json = get_domain(json)
343
+ def self.chart_histogram(chart_type, subjects, json, method)
344
+ domain_json = get_domain(json)
345
+ return if json['type'] == 'choices' and not domain_json
343
346
  return unless chart_variable_json = get_variable(chart_type)
344
347
  return unless chart_variable_domain = domain_array(chart_type)
345
348
 
346
-
347
349
  title = "#{json['display_name']}"
348
350
  subtitle = "By Visit"
349
-
350
- categories = domain_json.collect{|option_hash| option_hash['display_name']}
351
-
352
351
  units = "Subjects"
353
352
  series = []
354
353
 
354
+ all_subject_values = subjects.collect(&method.to_sym).compact.sort
355
+ return nil if all_subject_values.count == 0
356
+ categories = pull_categories(json, method, all_subject_values, domain_json)
357
+
358
+ buckets = continuous_buckets(all_subject_values)
359
+
355
360
  chart_variable_domain.each do |display_name, value|
356
- visit_subjects = subjects.select{ |s| s.send(chart_type) == value and s.send(method) != nil }.collect(&method.to_sym)
361
+ visit_subjects = subjects.select{ |s| s.send(chart_type) == value and s.send(method) != nil }.collect(&method.to_sym).sort
357
362
  next unless visit_subjects.size > 0
358
363
 
359
- data = []
360
-
361
- domain_json.each do |option_hash|
362
- data << visit_subjects.select{ |v| v == option_hash['value'] }.count
363
- end
364
+ data = pull_data(json, visit_subjects, buckets, categories, domain_json)
364
365
 
365
366
  series << { name: display_name, data: data }
366
367
  end
@@ -368,39 +369,30 @@ module Spout
368
369
  { title: title, subtitle: subtitle, categories: categories, units: units, series: series }
369
370
  end
370
371
 
371
- def self.chart_histogram(chart_type, subjects, json, method)
372
- return chart_histogram_choices(chart_type, subjects, json, method) if json['type'] == 'choices'
373
- return unless chart_variable_json = get_variable(chart_type)
374
- return unless chart_variable_domain = domain_array(chart_type)
375
-
376
- title = "#{json['display_name']}"
377
- subtitle = "By Visit"
372
+ def self.pull_categories(json, method, all_subject_values, domain_json)
378
373
  categories = []
379
- units = "Subjects"
380
- series = []
381
-
382
- all_subject_values = subjects.collect(&method.to_sym).compact.sort
383
- return nil if all_subject_values.count == 0
384
- buckets = continuous_buckets(all_subject_values)
385
-
386
- categories = buckets.collect{|b| "#{b[0].round(1)} to #{b[1].round(1)}"}
387
-
388
- chart_variable_domain.each do |display_name, value|
389
- visit_subjects = subjects.select{ |s| s.send(chart_type) == value and s.send(method) != nil }.collect(&method.to_sym).sort
390
- next unless visit_subjects.size > 0
391
-
392
- data = []
374
+ if json['type'] == 'choices'
375
+ categories = domain_json.collect{|option_hash| option_hash['display_name']}
376
+ else
377
+ buckets = continuous_buckets(all_subject_values)
378
+ categories = buckets.collect{|b| "#{b[0]} to #{b[1]}"}
379
+ end
380
+ categories
381
+ end
393
382
 
383
+ def self.pull_data(json, visit_subjects, buckets, categories, domain_json)
384
+ data = []
385
+ if json['type'] == 'choices'
386
+ domain_json.each do |option_hash|
387
+ data << visit_subjects.select{ |v| v == option_hash['value'] }.count
388
+ end
389
+ else
394
390
  visit_subjects.group_by{|v| get_bucket(buckets, v) }.each do |key, values|
395
391
  data[categories.index(key)] = values.count if categories.index(key)
396
392
  end
397
-
398
- series << { name: display_name, data: data }
399
393
  end
400
-
401
- { title: title, subtitle: subtitle, categories: categories, units: units, series: series }
394
+ data
402
395
  end
403
-
404
396
  end
405
397
  end
406
398
  end
data/lib/spout/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spout
3
3
  MAJOR = 0
4
4
  MINOR = 8
5
5
  TINY = 0
6
- BUILD = "beta15" # nil, "pre", "rc", "rc2"
6
+ BUILD = "rc" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
data/spout.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.email = ["remosm@gmail.com"]
19
19
  spec.description = %q{Manage your data dictionary as a JSON repository, and easily export back to CSV.}
20
20
  spec.summary = %q{Turn your CSV data dictionary into a JSON repository. Collaborate with others to update the data dictionary in JSON format. Generate new Data Dictionary from the JSON repository. Test and validate your data dictionary using built-in tests, or add your own for further validations.}
21
- spec.homepage = "https://github.com/sleepepi"
21
+ spec.homepage = "https://github.com/sleepepi/spout"
22
22
  spec.license = "CC BY-NC-SA 3.0"
23
23
 
24
24
  spec.files = Dir['{bin,lib}/**/*'] + ['CHANGELOG.md', 'LICENSE', 'Rakefile', 'README.md', 'spout.gemspec']
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.8.0.beta15
4
+ version: 0.8.0.rc
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-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -164,7 +164,7 @@ files:
164
164
  - lib/spout/views/index.html.erb
165
165
  - lib/spout/views/outliers.html.erb
166
166
  - spout.gemspec
167
- homepage: https://github.com/sleepepi
167
+ homepage: https://github.com/sleepepi/spout
168
168
  licenses:
169
169
  - CC BY-NC-SA 3.0
170
170
  metadata: {}