Commit e8499507622fb172f4398d818142128cb030aa1d
1 parent
3b9ccf62
Exists in
master
and in
1 other branch
Changes to support new maps, scatter plot on AOI
Showing
3 changed files
with
46 additions
and
11 deletions
Show diff stats
app/controllers/questions_controller.rb
... | ... | @@ -66,8 +66,9 @@ class QuestionsController < InheritedResources::Base |
66 | 66 | |
67 | 67 | # we sometimes request a question when no prompt is displayed |
68 | 68 | # TODO It would be a good idea to find these places and treat them like barebones |
69 | - if visitor_identifier != "" | |
69 | + if !visitor_identifier.blank? | |
70 | 70 | @a = current_user.record_appearance(visitor_identifier, @p) |
71 | + logger.info("creating appearance!") | |
71 | 72 | else |
72 | 73 | @a = nil |
73 | 74 | end |
... | ... | @@ -150,19 +151,52 @@ class QuestionsController < InheritedResources::Base |
150 | 151 | # export_format = params[:export_format] #CSV always now, could expand to xml later |
151 | 152 | end |
152 | 153 | |
153 | - def num_votes_by_visitor_id | |
154 | + def object_info_by_visitor_id | |
155 | + | |
156 | + object_type = params[:object_type] | |
154 | 157 | @question = current_user.questions.find(params[:id]) |
155 | 158 | |
156 | - votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | |
157 | - :joins => :voter, | |
158 | - :conditions => {:question_id => @question.id }, | |
159 | - :group => "voter_id") | |
160 | - | |
161 | 159 | visitor_id_hash = {} |
160 | + if object_type == "votes" | |
161 | + votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | |
162 | + :joins => :voter, | |
163 | + :conditions => {:question_id => @question.id }, | |
164 | + :group => "voter_id") | |
162 | 165 | |
163 | - votes_by_visitor_id.each do |visitor| | |
164 | - visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
165 | - visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
166 | + | |
167 | + votes_by_visitor_id.each do |visitor| | |
168 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
169 | + end | |
170 | + elsif object_type == "uploaded_ideas" | |
171 | + | |
172 | + uploaded_ideas_by_visitor_id = @question.choices.find(:all, :select => 'creator_id, count(*) as ideas_count', | |
173 | + :joins => [:item], | |
174 | + :conditions => "items.creator_id != #{@question.creator_id}", | |
175 | + :group => 'creator_id') | |
176 | + | |
177 | + uploaded_ideas_by_visitor_id.each do |visitor| | |
178 | + v = Visitor.find(visitor.creator_id, :select => 'identifier') | |
179 | + | |
180 | + logger.info(v.identifier) | |
181 | + | |
182 | + visitor_id_hash[v.identifier] = visitor.ideas_count | |
183 | + end | |
184 | + | |
185 | + logger.info(visitor_id_hash.inspect) | |
186 | + elsif object_type == "bounces" | |
187 | + | |
188 | + possible_bounces = @question.appearances.count(:group => :voter_id, :having => 'count_all = 1') | |
189 | + possible_bounce_ids = possible_bounces.inject([]){|list, (k,v)| list << k} | |
190 | + | |
191 | + voted_at_least_once = @question.votes.find(:all, :select => :voter_id, :conditions => {:voter_id => possible_bounce_ids}) | |
192 | + voted_at_least_once_ids = voted_at_least_once.inject([]){|list, v| list << v.voter_id} | |
193 | + | |
194 | + bounces = possible_bounce_ids - voted_at_least_once_ids | |
195 | + | |
196 | + bounces.each do |visitor_id| | |
197 | + v = Visitor.find(visitor_id, :select => 'identifier') | |
198 | + visitor_id_hash[v.identifier] = 1 | |
199 | + end | |
166 | 200 | end |
167 | 201 | respond_to do |format| |
168 | 202 | format.xml{ render :xml => visitor_id_hash.to_xml and return} | ... | ... |
app/models/question.rb
config/routes.rb
... | ... | @@ -3,7 +3,7 @@ ActionController::Routing::Routes.draw do |map| |
3 | 3 | map.resources :densities |
4 | 4 | map.resources :visitors, :collection => {:votes_by_session_ids => :post} |
5 | 5 | map.resources :questions, :member => { :object_info_totals_by_date => :get, |
6 | - :num_votes_by_visitor_id => :get, | |
6 | + :object_info_by_visitor_id => :get, | |
7 | 7 | :export => :post, |
8 | 8 | :set_autoactivate_ideas_from_abroad => :put, |
9 | 9 | :activate => :put, | ... | ... |