spout 0.8.0.beta1 → 0.8.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -9
- data/README.md +30 -13
- data/lib/spout/actions.rb +9 -6
- data/lib/spout/commands/coverage.rb +75 -0
- data/lib/spout/commands/graphs.rb +94 -146
- data/lib/spout/commands/images.rb +276 -0
- data/lib/spout/helpers/chart_types.rb +17 -6
- data/lib/spout/helpers/subject_loader.rb +71 -0
- data/lib/spout/models/coverage_result.rb +65 -0
- data/lib/spout/tasks/engine.rake +7 -139
- data/lib/spout/templates/gitignore +1 -1
- data/lib/spout/version.rb +1 -1
- metadata +6 -3
- data/lib/spout/commands/json_charts_and_tables.rb +0 -202
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.
|
4
|
+
version: 0.8.0.beta2
|
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-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -97,12 +97,15 @@ files:
|
|
97
97
|
- lib/spout.rb
|
98
98
|
- lib/spout/actions.rb
|
99
99
|
- lib/spout/application.rb
|
100
|
+
- lib/spout/commands/coverage.rb
|
100
101
|
- lib/spout/commands/graphs.rb
|
101
|
-
- lib/spout/commands/
|
102
|
+
- lib/spout/commands/images.rb
|
102
103
|
- lib/spout/helpers/array_statistics.rb
|
103
104
|
- lib/spout/helpers/chart_types.rb
|
105
|
+
- lib/spout/helpers/subject_loader.rb
|
104
106
|
- lib/spout/helpers/table_formatting.rb
|
105
107
|
- lib/spout/hidden_reporter.rb
|
108
|
+
- lib/spout/models/coverage_result.rb
|
106
109
|
- lib/spout/models/subject.rb
|
107
110
|
- lib/spout/support/javascripts/data.js
|
108
111
|
- lib/spout/support/javascripts/highcharts-convert.js
|
@@ -1,202 +0,0 @@
|
|
1
|
-
require 'csv'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'json'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
|
8
|
-
require 'spout/models/subject'
|
9
|
-
require 'spout/helpers/array_statistics'
|
10
|
-
require 'spout/helpers/chart_types'
|
11
|
-
|
12
|
-
|
13
|
-
module Spout
|
14
|
-
module Commands
|
15
|
-
class JsonChartsAndTables
|
16
|
-
def initialize(variables)
|
17
|
-
spout_config = YAML.load_file('.spout.yml')
|
18
|
-
|
19
|
-
_visit = ''
|
20
|
-
|
21
|
-
if spout_config.kind_of?(Hash)
|
22
|
-
_visit = spout_config['visit'].to_s.strip
|
23
|
-
|
24
|
-
chart_variables = if spout_config['charts'].kind_of?(Array)
|
25
|
-
spout_config['charts'].collect{|c| c.to_s.strip}.select{|c| c != ''}
|
26
|
-
else
|
27
|
-
[]
|
28
|
-
end
|
29
|
-
else
|
30
|
-
puts "The YAML file needs to be in the following format:"
|
31
|
-
puts "histogram: visitnumber # VISIT_VARIABLE\ncharts:\n - age_s1\n - gender\n - race\n"
|
32
|
-
exit
|
33
|
-
end
|
34
|
-
|
35
|
-
if Spout::Helpers::ChartTypes::get_json(_visit, 'variable') == nil
|
36
|
-
if _visit == ''
|
37
|
-
puts "The visit variable in .spout.yml can't be blank."
|
38
|
-
else
|
39
|
-
puts "Could not find the following visit variable: #{_visit}"
|
40
|
-
end
|
41
|
-
exit
|
42
|
-
end
|
43
|
-
missing_variables = chart_variables.select{|c| Spout::Helpers::ChartTypes::get_json(c, 'variable') == nil}
|
44
|
-
if missing_variables.count > 0
|
45
|
-
puts "Could not find the following chart variable#{'s' unless missing_variables.size == 1}: #{missing_variables.join(', ')}"
|
46
|
-
exit
|
47
|
-
end
|
48
|
-
|
49
|
-
argv_string = variables.join(',')
|
50
|
-
number_of_rows = nil
|
51
|
-
|
52
|
-
if match_data = argv_string.match(/-rows=(\d*)/)
|
53
|
-
number_of_rows = match_data[1].to_i
|
54
|
-
argv_string.gsub!(match_data[0], '')
|
55
|
-
end
|
56
|
-
|
57
|
-
valid_ids = argv_string.split(',').compact.reject{|s| s == ''}
|
58
|
-
|
59
|
-
@visit = _visit
|
60
|
-
|
61
|
-
chart_lookup = { _visit => "Histogram" }
|
62
|
-
|
63
|
-
chart_variables.each do |chart_variable|
|
64
|
-
json = Spout::Helpers::ChartTypes::get_json(chart_variable, 'variable')
|
65
|
-
chart_lookup[chart_variable] = json['display_name']
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
t = Time.now
|
71
|
-
|
72
|
-
|
73
|
-
version = standard_version
|
74
|
-
|
75
|
-
subjects = []
|
76
|
-
|
77
|
-
FileUtils.mkpath "charts/#{version}"
|
78
|
-
|
79
|
-
csv_files = Dir.glob("csvs/#{version}/*.csv")
|
80
|
-
|
81
|
-
csv_files.each_with_index do |csv_file, index|
|
82
|
-
count = 0
|
83
|
-
puts "Parsing: #{csv_file}"
|
84
|
-
CSV.parse( File.open(csv_file, 'r:iso-8859-1:utf-8'){|f| f.read}, headers: true, header_converters: lambda { |h| h.to_s.downcase } ) do |line|
|
85
|
-
|
86
|
-
row = line.to_hash
|
87
|
-
count += 1
|
88
|
-
puts "Line: #{count}" if (count % 1000 == 0)
|
89
|
-
subjects << Spout::Models::Subject.create do |t|
|
90
|
-
|
91
|
-
t._visit = row[_visit] #.to_s.strip
|
92
|
-
|
93
|
-
row.each do |key,value|
|
94
|
-
unless t.respond_to?(key)
|
95
|
-
t.class.send(:define_method, "#{key}") { instance_variable_get("@#{key}") }
|
96
|
-
t.class.send(:define_method, "#{key}=") { |value| instance_variable_set("@#{key}", value) }
|
97
|
-
end
|
98
|
-
|
99
|
-
unless value == nil
|
100
|
-
t.send("#{key}=", value)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
# puts "Memory Used: " + (`ps -o rss -p #{$$}`.strip.split.last.to_i / 1024).to_s + " MB" if count % 1000 == 0
|
105
|
-
# break if count >= 1000
|
106
|
-
break if number_of_rows != nil and count >= number_of_rows
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
variable_files = Dir.glob('variables/**/*.json')
|
111
|
-
variable_files_count = variable_files.count
|
112
|
-
|
113
|
-
variable_files.each do |variable_file|
|
114
|
-
json = JSON.parse(File.read(variable_file)) rescue json = nil
|
115
|
-
next unless json
|
116
|
-
next unless valid_ids.include?(json["id"].to_s.downcase) or valid_ids.size == 0
|
117
|
-
next unless ["numeric", "integer"].include?(json["type"])
|
118
|
-
method = json['id'].to_s.downcase
|
119
|
-
next unless Spout::Models::Subject.method_defined?(method)
|
120
|
-
|
121
|
-
subjects.each{ |s| s.send(method) != nil ? s.send("#{method}=", s.send("#{method}").to_f) : nil }
|
122
|
-
end
|
123
|
-
|
124
|
-
variable_files.each_with_index do |variable_file, file_index|
|
125
|
-
json = JSON.parse(File.read(variable_file)) rescue json = nil
|
126
|
-
next unless json
|
127
|
-
next unless valid_ids.include?(json["id"].to_s.downcase) or valid_ids.size == 0
|
128
|
-
next unless ["numeric", "integer", "choices"].include?(json["type"])
|
129
|
-
variable_name = json['id'].to_s.downcase
|
130
|
-
next unless Spout::Models::Subject.method_defined?(variable_name)
|
131
|
-
|
132
|
-
puts "#{file_index+1} of #{variable_files_count}: #{variable_file.gsub(/(^variables\/|\.json$)/, '').gsub('/', ' / ')}"
|
133
|
-
|
134
|
-
|
135
|
-
stats = {
|
136
|
-
charts: {},
|
137
|
-
tables: {}
|
138
|
-
}
|
139
|
-
|
140
|
-
chart_types = case json['type'] when 'integer', 'numeric', 'choices'
|
141
|
-
chart_lookup.keys
|
142
|
-
else
|
143
|
-
[]
|
144
|
-
end
|
145
|
-
|
146
|
-
chart_types.each do |chart_type|
|
147
|
-
if chart_type == _visit
|
148
|
-
filtered_subjects = subjects.select{ |s| s.send(chart_type) != nil } # and s.send(variable_name) != nil
|
149
|
-
if filtered_subjects.count > 0
|
150
|
-
stats[:charts][chart_lookup[chart_type].downcase] = Spout::Helpers::ChartTypes::chart_histogram(chart_type, filtered_subjects, json, variable_name)
|
151
|
-
stats[:tables][chart_lookup[chart_type].downcase] = Spout::Helpers::ChartTypes::table_arbitrary(chart_type, filtered_subjects, json, variable_name)
|
152
|
-
end
|
153
|
-
else
|
154
|
-
filtered_subjects = subjects.select{ |s| s.send(chart_type) != nil } # and s.send(variable_name) != nil
|
155
|
-
if filtered_subjects.count > 0
|
156
|
-
stats[:charts][chart_lookup[chart_type].downcase] = Spout::Helpers::ChartTypes::chart_arbitrary(chart_type, filtered_subjects, json, variable_name, visits)
|
157
|
-
stats[:tables][chart_lookup[chart_type].downcase] = visits.collect do |visit_display_name, visit_value|
|
158
|
-
visit_subjects = filtered_subjects.select{ |s| s._visit == visit_value }
|
159
|
-
unknown_subjects = visit_subjects.select{ |s| s.send(variable_name) == nil }
|
160
|
-
(visit_subjects.count > 0 && visit_subjects.count != unknown_subjects.count) ? Spout::Helpers::ChartTypes::table_arbitrary(chart_type, visit_subjects, json, variable_name, visit_display_name) : nil
|
161
|
-
end.compact
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
chart_json_file = File.join('charts', version, "#{json['id']}.json")
|
167
|
-
File.open(chart_json_file, 'w') { |file| file.write( JSON.pretty_generate(stats) + "\n" ) }
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
puts "Took #{Time.now - t} seconds."
|
172
|
-
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
# [["Visit 1", "1"], ["Visit 2", "2"], ["CVD Outcomes", "3"]]
|
177
|
-
def visits
|
178
|
-
@visits ||= begin
|
179
|
-
Spout::Commands::JsonChartsAndTables::domain_array(@visit)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
# This is directly from Spout
|
184
|
-
def self.standard_version
|
185
|
-
version = File.open('VERSION', &:readline).strip rescue ''
|
186
|
-
version == '' ? '1.0.0' : version
|
187
|
-
end
|
188
|
-
|
189
|
-
def self.domain_array(variable_name)
|
190
|
-
variable_file = Dir.glob("variables/**/#{variable_name}.json").first
|
191
|
-
json = JSON.parse(File.read(variable_file)) rescue json = nil
|
192
|
-
if json
|
193
|
-
domain_json = Spout::Helpers::ChartTypes::get_domain(json)
|
194
|
-
domain_json ? domain_json.collect{|option_hash| [option_hash['display_name'], option_hash['value']]} : []
|
195
|
-
else
|
196
|
-
[]
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|