pollster 0.2.3 → 2.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +68 -111
- data/example.rb +128 -0
- data/lib/pollster.rb +46 -4
- data/lib/pollster/api.rb +655 -0
- data/lib/pollster/api_client.rb +400 -0
- data/lib/pollster/api_error.rb +26 -0
- data/lib/pollster/configuration.rb +184 -0
- data/lib/pollster/models/chart.rb +239 -0
- data/lib/pollster/models/chart_estimate.rb +226 -0
- data/lib/pollster/models/chart_estimate_lowess_parameters.rb +197 -0
- data/lib/pollster/models/chart_pollster_estimate_summary.rb +217 -0
- data/lib/pollster/models/chart_pollster_trendlines.rb +41 -0
- data/lib/pollster/models/inline_response_200.rb +208 -0
- data/lib/pollster/models/inline_response_200_3.rb +206 -0
- data/lib/pollster/models/inline_response_200_4.rb +208 -0
- data/lib/pollster/models/poll.rb +279 -0
- data/lib/pollster/models/poll_question.rb +198 -0
- data/lib/pollster/models/poll_question_responses.rb +197 -0
- data/lib/pollster/models/poll_question_sample_subpopulations.rb +209 -0
- data/lib/pollster/models/pollster_chart_poll_questions.rb +92 -0
- data/lib/pollster/models/question.rb +253 -0
- data/lib/pollster/models/question_poll_responses_clean.rb +93 -0
- data/lib/pollster/models/question_poll_responses_raw.rb +86 -0
- data/lib/pollster/models/question_responses.rb +207 -0
- data/lib/pollster/models/tag.rb +207 -0
- data/lib/pollster/version.rb +1 -1
- data/pollster.gemspec +17 -16
- metadata +85 -65
- data/.gitignore +0 -2
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -19
- data/Rakefile +0 -8
- data/lib/pollster/base.rb +0 -45
- data/lib/pollster/chart.rb +0 -69
- data/lib/pollster/poll.rb +0 -47
- data/lib/pollster/question.rb +0 -19
- data/test/test_pollster.rb +0 -26
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pollster
|
4
|
+
# A Chart that appears on the Pollster website. See `chart.question.responses` for the list of potential response labels. Sometimes a chart omits one of the labels that appears in `chart.question.responses`; see `chart.pollster_estimates[0].values` for all the response labels that aren't omitted.
|
5
|
+
class Chart
|
6
|
+
# Unique Chart identifier. For example: `obama-job-approval`.
|
7
|
+
attr_accessor :slug
|
8
|
+
|
9
|
+
# URL where Pollster has published this Chart (for end-users, not API users).
|
10
|
+
attr_accessor :url
|
11
|
+
|
12
|
+
# Date Pollster editors first created this Chart
|
13
|
+
attr_accessor :created_at
|
14
|
+
|
15
|
+
# Tag slugs that pertain to this Chart. Includes Tags that pertain to this Chart's Question.
|
16
|
+
attr_accessor :tags
|
17
|
+
|
18
|
+
# Pollster-generated estimates. Intuitively, \"what the polls suggest\". These estimates are produced by algorithms. We publish the output of one or more algorithms. This Array always has at least one entry, and that entry is Pollster's best guess as to \"what the polls suggest\". Branding-wise, you may call these \"Pollster Estimates\" if you publish `chart.pollster_estimates[0].values`.
|
19
|
+
attr_accessor :pollster_estimates
|
20
|
+
|
21
|
+
attr_accessor :pollster_estimate_summary
|
22
|
+
|
23
|
+
attr_accessor :question
|
24
|
+
|
25
|
+
|
26
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
27
|
+
def self.attribute_map
|
28
|
+
{
|
29
|
+
:'slug' => :'slug',
|
30
|
+
:'url' => :'url',
|
31
|
+
:'created_at' => :'created_at',
|
32
|
+
:'tags' => :'tags',
|
33
|
+
:'pollster_estimates' => :'pollster_estimates',
|
34
|
+
:'pollster_estimate_summary' => :'pollster_estimate_summary',
|
35
|
+
:'question' => :'question'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attribute type mapping.
|
40
|
+
def self.swagger_types
|
41
|
+
{
|
42
|
+
:'slug' => :'String',
|
43
|
+
:'url' => :'String',
|
44
|
+
:'created_at' => :'DateTime',
|
45
|
+
:'tags' => :'Array<String>',
|
46
|
+
:'pollster_estimates' => :'Array<ChartEstimate>',
|
47
|
+
:'pollster_estimate_summary' => :'ChartPollsterEstimateSummary',
|
48
|
+
:'question' => :'Question'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
# Initializes the object
|
53
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
54
|
+
def initialize(attributes = {})
|
55
|
+
return unless attributes.is_a?(Hash)
|
56
|
+
|
57
|
+
# convert string to symbol for hash key
|
58
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
59
|
+
|
60
|
+
if attributes.has_key?(:'slug')
|
61
|
+
self.slug = attributes[:'slug']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes.has_key?(:'url')
|
65
|
+
self.url = attributes[:'url']
|
66
|
+
end
|
67
|
+
|
68
|
+
if attributes.has_key?(:'created_at')
|
69
|
+
self.created_at = attributes[:'created_at']
|
70
|
+
end
|
71
|
+
|
72
|
+
if attributes.has_key?(:'tags')
|
73
|
+
if (value = attributes[:'tags']).is_a?(Array)
|
74
|
+
self.tags = value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if attributes.has_key?(:'pollster_estimates')
|
79
|
+
if (value = attributes[:'pollster_estimates']).is_a?(Array)
|
80
|
+
self.pollster_estimates = value
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if attributes.has_key?(:'pollster_estimate_summary')
|
85
|
+
self.pollster_estimate_summary = attributes[:'pollster_estimate_summary']
|
86
|
+
end
|
87
|
+
|
88
|
+
if attributes.has_key?(:'question')
|
89
|
+
self.question = attributes[:'question']
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
95
|
+
# @return Array for valid properies with the reasons
|
96
|
+
def list_invalid_properties
|
97
|
+
invalid_properties = Array.new
|
98
|
+
return invalid_properties
|
99
|
+
end
|
100
|
+
|
101
|
+
# Check to see if the all the properties in the model are valid
|
102
|
+
# @return true if the model is valid
|
103
|
+
def valid?
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
|
107
|
+
# Checks equality by comparing each attribute.
|
108
|
+
# @param [Object] Object to be compared
|
109
|
+
def ==(o)
|
110
|
+
return true if self.equal?(o)
|
111
|
+
self.class == o.class &&
|
112
|
+
slug == o.slug &&
|
113
|
+
url == o.url &&
|
114
|
+
created_at == o.created_at &&
|
115
|
+
tags == o.tags &&
|
116
|
+
pollster_estimates == o.pollster_estimates &&
|
117
|
+
pollster_estimate_summary == o.pollster_estimate_summary &&
|
118
|
+
question == o.question
|
119
|
+
end
|
120
|
+
|
121
|
+
# @see the `==` method
|
122
|
+
# @param [Object] Object to be compared
|
123
|
+
def eql?(o)
|
124
|
+
self == o
|
125
|
+
end
|
126
|
+
|
127
|
+
# Calculates hash code according to all attributes.
|
128
|
+
# @return [Fixnum] Hash code
|
129
|
+
def hash
|
130
|
+
[slug, url, created_at, tags, pollster_estimates, pollster_estimate_summary, question].hash
|
131
|
+
end
|
132
|
+
|
133
|
+
# Builds the object from hash
|
134
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
135
|
+
# @return [Object] Returns the model itself
|
136
|
+
def build_from_hash(attributes)
|
137
|
+
return nil unless attributes.is_a?(Hash)
|
138
|
+
self.class.swagger_types.each_pair do |key, type|
|
139
|
+
if type =~ /\AArray<(.*)>/i
|
140
|
+
# check to ensure the input is an array given that the the attribute
|
141
|
+
# is documented as an array but the input is not
|
142
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
143
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
144
|
+
end
|
145
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
146
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
147
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
148
|
+
end
|
149
|
+
|
150
|
+
self
|
151
|
+
end
|
152
|
+
|
153
|
+
# Deserializes the data based on type
|
154
|
+
# @param string type Data type
|
155
|
+
# @param string value Value to be deserialized
|
156
|
+
# @return [Object] Deserialized data
|
157
|
+
def _deserialize(type, value)
|
158
|
+
case type.to_sym
|
159
|
+
when :DateTime
|
160
|
+
DateTime.parse(value)
|
161
|
+
when :Date
|
162
|
+
Date.parse(value)
|
163
|
+
when :String
|
164
|
+
value.to_s
|
165
|
+
when :Integer
|
166
|
+
value.to_i
|
167
|
+
when :Float
|
168
|
+
value.to_f
|
169
|
+
when :BOOLEAN
|
170
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
171
|
+
true
|
172
|
+
else
|
173
|
+
false
|
174
|
+
end
|
175
|
+
when :Object
|
176
|
+
# generic object (usually a Hash), return directly
|
177
|
+
value
|
178
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
179
|
+
inner_type = Regexp.last_match[:inner_type]
|
180
|
+
value.map { |v| _deserialize(inner_type, v) }
|
181
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
182
|
+
k_type = Regexp.last_match[:k_type]
|
183
|
+
v_type = Regexp.last_match[:v_type]
|
184
|
+
{}.tap do |hash|
|
185
|
+
value.each do |k, v|
|
186
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
else # model
|
190
|
+
temp_model = Pollster.const_get(type).new
|
191
|
+
temp_model.build_from_hash(value)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Returns the string representation of the object
|
196
|
+
# @return [String] String presentation of the object
|
197
|
+
def to_s
|
198
|
+
to_hash.to_s
|
199
|
+
end
|
200
|
+
|
201
|
+
# to_body is an alias to to_hash (backward compatibility)
|
202
|
+
# @return [Hash] Returns the object in the form of hash
|
203
|
+
def to_body
|
204
|
+
to_hash
|
205
|
+
end
|
206
|
+
|
207
|
+
# Returns the object in the form of hash
|
208
|
+
# @return [Hash] Returns the object in the form of hash
|
209
|
+
def to_hash
|
210
|
+
hash = {}
|
211
|
+
self.class.attribute_map.each_pair do |attr, param|
|
212
|
+
value = self.send(attr)
|
213
|
+
next if value.nil?
|
214
|
+
hash[param] = _to_hash(value)
|
215
|
+
end
|
216
|
+
hash
|
217
|
+
end
|
218
|
+
|
219
|
+
# Outputs non-array value in the form of hash
|
220
|
+
# For object, use to_hash. Otherwise, just return the value
|
221
|
+
# @param [Object] value Any valid value
|
222
|
+
# @return [Hash] Returns the value in the form of hash
|
223
|
+
def _to_hash(value)
|
224
|
+
if value.is_a?(Array)
|
225
|
+
value.compact.map{ |v| _to_hash(v) }
|
226
|
+
elsif value.is_a?(Hash)
|
227
|
+
{}.tap do |hash|
|
228
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
229
|
+
end
|
230
|
+
elsif value.respond_to? :to_hash
|
231
|
+
value.to_hash
|
232
|
+
else
|
233
|
+
value
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Pollster
|
4
|
+
# One set of estimates. The first set of estimates on a Chart is the official \"Pollster Estimates\".
|
5
|
+
class ChartEstimate
|
6
|
+
# Name of the algorithm that produced these estimates. Possible values are: `bayesian-kallman` ([source code](https://github.com/huffpostdata/pollster-models/tree/master/poll-average), [academic explanation](http://eppsac.utdallas.edu/files/jackman/CAJP%2040-4%20Jackman.pdf)); `lowess` (locally weighted scatterplot smoothing).
|
7
|
+
attr_accessor :algorithm
|
8
|
+
|
9
|
+
# The time Pollster produced these estimates. Consider `datetime` instead. `datetime` describes what Pollster calculates; `created_at` describes _when_ Pollster made those calculations.
|
10
|
+
attr_accessor :created_at
|
11
|
+
|
12
|
+
# The time these `values` apply to. For instance, Pollster may run `lowess` (which is deterministic) years after an election; in that case `created_at` will be the date of the `lowess` calculation, and `datetime` will be the election date.
|
13
|
+
attr_accessor :datetime
|
14
|
+
|
15
|
+
# Each key is a response Label. Each value is Pollster's estimate of the polling average for that label. For instance, `{ \"Clinton\": 47.3, \"Trump\": 42.0, \"Other\": 5.2 }`. Values often do not add up to 100%. Some Responses on a Question have no corresponding Values, because Pollster sometimes omits Responses from a Chart.
|
16
|
+
attr_accessor :values
|
17
|
+
|
18
|
+
attr_accessor :lowess_parameters
|
19
|
+
|
20
|
+
# Only present if `algorithm` is `bayesian-kallman`. Each key is a response Label. Each value is the `[ low, high ]` of the algorithm's 95% confidence interval.
|
21
|
+
attr_accessor :bayesian_kallman_95_percent_intervals
|
22
|
+
|
23
|
+
|
24
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
25
|
+
def self.attribute_map
|
26
|
+
{
|
27
|
+
:'algorithm' => :'algorithm',
|
28
|
+
:'created_at' => :'created_at',
|
29
|
+
:'datetime' => :'datetime',
|
30
|
+
:'values' => :'values',
|
31
|
+
:'lowess_parameters' => :'lowess_parameters',
|
32
|
+
:'bayesian_kallman_95_percent_intervals' => :'bayesian_kallman_95_percent_intervals'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Attribute type mapping.
|
37
|
+
def self.swagger_types
|
38
|
+
{
|
39
|
+
:'algorithm' => :'String',
|
40
|
+
:'created_at' => :'DateTime',
|
41
|
+
:'datetime' => :'DateTime',
|
42
|
+
:'values' => :'Object',
|
43
|
+
:'lowess_parameters' => :'ChartEstimateLowessParameters',
|
44
|
+
:'bayesian_kallman_95_percent_intervals' => :'Object'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Initializes the object
|
49
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
50
|
+
def initialize(attributes = {})
|
51
|
+
return unless attributes.is_a?(Hash)
|
52
|
+
|
53
|
+
# convert string to symbol for hash key
|
54
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
55
|
+
|
56
|
+
if attributes.has_key?(:'algorithm')
|
57
|
+
self.algorithm = attributes[:'algorithm']
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes.has_key?(:'created_at')
|
61
|
+
self.created_at = attributes[:'created_at']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes.has_key?(:'datetime')
|
65
|
+
self.datetime = attributes[:'datetime']
|
66
|
+
end
|
67
|
+
|
68
|
+
if attributes.has_key?(:'values')
|
69
|
+
self.values = attributes[:'values']
|
70
|
+
end
|
71
|
+
|
72
|
+
if attributes.has_key?(:'lowess_parameters')
|
73
|
+
self.lowess_parameters = attributes[:'lowess_parameters']
|
74
|
+
end
|
75
|
+
|
76
|
+
if attributes.has_key?(:'bayesian_kallman_95_percent_intervals')
|
77
|
+
self.bayesian_kallman_95_percent_intervals = attributes[:'bayesian_kallman_95_percent_intervals']
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
83
|
+
# @return Array for valid properies with the reasons
|
84
|
+
def list_invalid_properties
|
85
|
+
invalid_properties = Array.new
|
86
|
+
return invalid_properties
|
87
|
+
end
|
88
|
+
|
89
|
+
# Check to see if the all the properties in the model are valid
|
90
|
+
# @return true if the model is valid
|
91
|
+
def valid?
|
92
|
+
return true
|
93
|
+
end
|
94
|
+
|
95
|
+
# Checks equality by comparing each attribute.
|
96
|
+
# @param [Object] Object to be compared
|
97
|
+
def ==(o)
|
98
|
+
return true if self.equal?(o)
|
99
|
+
self.class == o.class &&
|
100
|
+
algorithm == o.algorithm &&
|
101
|
+
created_at == o.created_at &&
|
102
|
+
datetime == o.datetime &&
|
103
|
+
values == o.values &&
|
104
|
+
lowess_parameters == o.lowess_parameters &&
|
105
|
+
bayesian_kallman_95_percent_intervals == o.bayesian_kallman_95_percent_intervals
|
106
|
+
end
|
107
|
+
|
108
|
+
# @see the `==` method
|
109
|
+
# @param [Object] Object to be compared
|
110
|
+
def eql?(o)
|
111
|
+
self == o
|
112
|
+
end
|
113
|
+
|
114
|
+
# Calculates hash code according to all attributes.
|
115
|
+
# @return [Fixnum] Hash code
|
116
|
+
def hash
|
117
|
+
[algorithm, created_at, datetime, values, lowess_parameters, bayesian_kallman_95_percent_intervals].hash
|
118
|
+
end
|
119
|
+
|
120
|
+
# Builds the object from hash
|
121
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
122
|
+
# @return [Object] Returns the model itself
|
123
|
+
def build_from_hash(attributes)
|
124
|
+
return nil unless attributes.is_a?(Hash)
|
125
|
+
self.class.swagger_types.each_pair do |key, type|
|
126
|
+
if type =~ /\AArray<(.*)>/i
|
127
|
+
# check to ensure the input is an array given that the the attribute
|
128
|
+
# is documented as an array but the input is not
|
129
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
130
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
131
|
+
end
|
132
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
133
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
134
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
135
|
+
end
|
136
|
+
|
137
|
+
self
|
138
|
+
end
|
139
|
+
|
140
|
+
# Deserializes the data based on type
|
141
|
+
# @param string type Data type
|
142
|
+
# @param string value Value to be deserialized
|
143
|
+
# @return [Object] Deserialized data
|
144
|
+
def _deserialize(type, value)
|
145
|
+
case type.to_sym
|
146
|
+
when :DateTime
|
147
|
+
DateTime.parse(value)
|
148
|
+
when :Date
|
149
|
+
Date.parse(value)
|
150
|
+
when :String
|
151
|
+
value.to_s
|
152
|
+
when :Integer
|
153
|
+
value.to_i
|
154
|
+
when :Float
|
155
|
+
value.to_f
|
156
|
+
when :BOOLEAN
|
157
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
158
|
+
true
|
159
|
+
else
|
160
|
+
false
|
161
|
+
end
|
162
|
+
when :Object
|
163
|
+
# generic object (usually a Hash), return directly
|
164
|
+
value
|
165
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
166
|
+
inner_type = Regexp.last_match[:inner_type]
|
167
|
+
value.map { |v| _deserialize(inner_type, v) }
|
168
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
169
|
+
k_type = Regexp.last_match[:k_type]
|
170
|
+
v_type = Regexp.last_match[:v_type]
|
171
|
+
{}.tap do |hash|
|
172
|
+
value.each do |k, v|
|
173
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
else # model
|
177
|
+
temp_model = Pollster.const_get(type).new
|
178
|
+
temp_model.build_from_hash(value)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns the string representation of the object
|
183
|
+
# @return [String] String presentation of the object
|
184
|
+
def to_s
|
185
|
+
to_hash.to_s
|
186
|
+
end
|
187
|
+
|
188
|
+
# to_body is an alias to to_hash (backward compatibility)
|
189
|
+
# @return [Hash] Returns the object in the form of hash
|
190
|
+
def to_body
|
191
|
+
to_hash
|
192
|
+
end
|
193
|
+
|
194
|
+
# Returns the object in the form of hash
|
195
|
+
# @return [Hash] Returns the object in the form of hash
|
196
|
+
def to_hash
|
197
|
+
hash = {}
|
198
|
+
self.class.attribute_map.each_pair do |attr, param|
|
199
|
+
value = self.send(attr)
|
200
|
+
next if value.nil?
|
201
|
+
hash[param] = _to_hash(value)
|
202
|
+
end
|
203
|
+
hash
|
204
|
+
end
|
205
|
+
|
206
|
+
# Outputs non-array value in the form of hash
|
207
|
+
# For object, use to_hash. Otherwise, just return the value
|
208
|
+
# @param [Object] value Any valid value
|
209
|
+
# @return [Hash] Returns the value in the form of hash
|
210
|
+
def _to_hash(value)
|
211
|
+
if value.is_a?(Array)
|
212
|
+
value.compact.map{ |v| _to_hash(v) }
|
213
|
+
elsif value.is_a?(Hash)
|
214
|
+
{}.tap do |hash|
|
215
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
216
|
+
end
|
217
|
+
elsif value.respond_to? :to_hash
|
218
|
+
value.to_hash
|
219
|
+
else
|
220
|
+
value
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
end
|