Commit fff49b4783dcf618384260c1648e3f9bc7582864
1 parent
2bebac97
Exists in
master
and in
1 other branch
Changes to support viewing site wide data
Showing
2 changed files
with
56 additions
and
8 deletions
Show diff stats
app/controllers/questions_controller.rb
... | ... | @@ -102,25 +102,42 @@ class QuestionsController < InheritedResources::Base |
102 | 102 | |
103 | 103 | def num_votes_by_visitor_id |
104 | 104 | @question = current_user.questions.find(params[:id]) |
105 | - hash = Vote.count(:conditions => "question_id = #{@question.id}", :group => "voter_id") | |
105 | + | |
106 | + votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | |
107 | + :joins => :voter, | |
108 | + :conditions => {:question_id => @question.id }, | |
109 | + :group => "voter_id") | |
110 | + | |
106 | 111 | visitor_id_hash = {} |
107 | - hash.each do |visitor_id, num_votes| | |
108 | - visitor = Visitor.find(visitor_id) | |
109 | - visitor_id_hash[visitor.identifier] = num_votes | |
112 | + | |
113 | + votes_by_visitor_id.each do |visitor| | |
114 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
115 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
110 | 116 | end |
111 | 117 | respond_to do |format| |
112 | 118 | format.xml{ render :xml => visitor_id_hash.to_xml and return} |
113 | 119 | end |
114 | 120 | end |
115 | 121 | |
116 | - def object_info_totals_by_date | |
117 | - authenticate | |
122 | + def all_num_votes_by_visitor_id | |
123 | + votes_by_visitor_id= Vote.all(:select => 'visitors.identifier as thevi, count(*) as the_votes_count', | |
124 | + :joins => :voter, | |
125 | + :group => "voter_id") | |
126 | + visitor_id_hash = {} | |
127 | + votes_by_visitor_id.each do |visitor| | |
128 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
129 | + visitor_id_hash[visitor.thevi] = visitor.the_votes_count | |
130 | + end | |
131 | + respond_to do |format| | |
132 | + format.xml{ render :xml => visitor_id_hash.to_xml and return} | |
133 | + end | |
134 | + end | |
118 | 135 | |
136 | + def object_info_totals_by_date | |
119 | 137 | object_type = params[:object_type] |
120 | 138 | |
121 | 139 | @question = current_user.questions.find(params[:id]) |
122 | 140 | if object_type == 'votes' |
123 | - # eventually allow for users to specify type of export through params[:type] | |
124 | 141 | hash = Vote.count(:conditions => "question_id = #{@question.id}", :group => "date(created_at)") |
125 | 142 | elsif object_type == 'user_submitted_ideas' |
126 | 143 | hash = Choice.count(:include => 'item', |
... | ... | @@ -140,6 +157,29 @@ class QuestionsController < InheritedResources::Base |
140 | 157 | format.xml { render :xml => hash.to_xml and return} |
141 | 158 | end |
142 | 159 | end |
160 | + | |
161 | + def all_object_info_totals_by_date | |
162 | + object_type = params[:object_type] | |
163 | + | |
164 | + if object_type == 'votes' | |
165 | + hash = Vote.count(:group => "date(created_at)") | |
166 | + elsif object_type == 'user_submitted_ideas' | |
167 | + hash = Choice.count(:include => ['item', 'question'], | |
168 | + :conditions => "items.creator_id <> questions.creator_id", | |
169 | + :group => "date(choices.created_at)") | |
170 | + elsif object_type == 'user_sessions' | |
171 | + result = Vote.find(:all, :select => 'date(created_at) as date, voter_id, count(*) as vote_count', | |
172 | + :group => 'date(created_at), voter_id') | |
173 | + hash = Hash.new(0) | |
174 | + result.each do |r| | |
175 | + hash[r.date]+=1 | |
176 | + end | |
177 | + end | |
178 | + | |
179 | + respond_to do |format| | |
180 | + format.xml { render :xml => hash.to_xml and return} | |
181 | + end | |
182 | + end | |
143 | 183 | |
144 | 184 | protected |
145 | 185 | def export_votes | ... | ... |
config/routes.rb
1 | 1 | ActionController::Routing::Routes.draw do |map| |
2 | 2 | #map.resources :clicks |
3 | 3 | map.resources :visitors, :collection => {:votes_by_session_ids => :post} |
4 | - map.resources :questions, :member => { :object_info_totals_by_date => :get, :num_votes_by_visitor_id => :get, :export => :post, :set_autoactivate_ideas_from_abroad => :put, :activate => :put, :suspend => :put}, :collection => {:recent_votes_by_question_id => :get} do |question| | |
4 | + map.resources :questions, :member => { :object_info_totals_by_date => :get, | |
5 | + :num_votes_by_visitor_id => :get, | |
6 | + :export => :post, | |
7 | + :set_autoactivate_ideas_from_abroad => :put, | |
8 | + :activate => :put, | |
9 | + :suspend => :put}, | |
10 | + :collection => {:all_num_votes_by_visitor_id => :get, | |
11 | + :all_object_info_totals_by_date => :get, | |
12 | + :recent_votes_by_question_id => :get} do |question| | |
5 | 13 | question.resources :items |
6 | 14 | question.resources :prompts, :member => {:vote_left => :post, :vote_right => :post, :skip => :post, :vote => :post}, |
7 | 15 | :collection => {:single => :get, :index => :get} | ... | ... |