Permalink
Browse files

Merge pull request #120 from osbridge/selector-votes

Add average, total votes to selector votes CSV export
  • Loading branch information...
reidab committed Apr 24, 2016
2 parents e5540ce + fef97d9 commit 66995d87dca164aab834a8877fcd993691bcf9fd
@@ -20,6 +20,8 @@ def index
proposals.sort_by { |proposal| [ 0 - proposal.selector_vote_points, 0 - proposal.user_favorites.size, proposal.id ] }
when 'votes_count'
proposals.sort_by { |proposal| [ 0 - proposal.selector_votes.size, 0 - proposal.user_favorites.size, proposal.id ] }
when 'average_vote'
proposals.sort_by { |proposal| [ 0 - proposal.selector_votes_average, 0 - proposal.user_favorites.size, proposal.id ] }
when 'favorites_count'
proposals.sort_by { |proposal| [ 0 - proposal.user_favorites.size, 0 - proposal.selector_vote_points, proposal.id ] }
when 'track'
@@ -229,6 +229,8 @@ def emails
user_favorites size: 'Favorites count'
selector_vote_points 'Selector points'
selector_votes_for_comma 'Selector votes'
selector_votes_count 'Selector votes count'
selector_votes_average 'Selector votes average'
comments_for_comma 'Comments'
end
@@ -555,6 +557,11 @@ def selector_votes_count
return self.selector_votes.map(&:rating).reject{|o| o == -1}.size
end
# Return the average vote (not including abstensions)
def selector_votes_average
return (self.selector_vote_points.to_f / self.selector_votes_count.to_f).round(2)
end
#---[ Accessors for getting the titles of related objects ]-------------
def track_title
@@ -21,7 +21,7 @@ HERE
<th><%= link_to('Track', event_selector_votes_path(@event, order: 'track')) %></th>
<th><%= link_to('Vote points', event_selector_votes_path(@event, order: 'vote_points')) %></th>
<th><%= link_to('Votes count', event_selector_votes_path(@event, order: 'votes_count')) %></th>
<th>Average Vote</th>
<th><%= link_to('Average vote', event_selector_votes_path(@event, order: 'average_vote')) %></th>
<th><%= link_to('Favorites count', event_selector_votes_path(@event, order: 'favorites_count')) %></th>
</tr>
<% for proposal in @proposals %>
@@ -40,7 +40,7 @@ HERE
<td><%= proposal.track_title %></td>
<td><%= proposal.selector_vote_points %></td>
<td><%= proposal.selector_votes_count %></td>
<td><%= proposal.selector_vote_points.to_f / proposal.selector_votes_count.to_f %></td>
<td><%= proposal.selector_votes_average %></td>
<td><%= proposal.user_favorites.size %></td>
</tr>
<% if proposal.selector_votes.size > 0 %>

0 comments on commit 66995d8

Please sign in to comment.