def plurality_pie
@election = Election.find(params[:id])
+ @election.results unless @election.plurality_result || @election.approval_result
+ votes = @election.votes.size
+ data = Hash.new
+ names = @election.names_by_id
-
-
+ @election.plurality_result.points.each do |candidate, votes|
+ data[names[candidate]] = votes
+ end
+
pie = GruffGraff.new ( :graph_type => Gruff::Pie,
- :data => ,
- :title => "Percentage of First Plce Votes")
+ :title => "Percentage of First Place Votes",
+ :data => data)
+ send_data(*pie.output)
+
+ end
private
def get_positions_info(election)
<%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
<br />
<%= image_tag( graph_url( :action => 'borda_bar', :id => @election ) ) %><br />
-<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %>
+<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %><br />
+<%= image_tag(graph_url( :action => 'plurality_pie', :id => @election ) )%>
end
def victories_and_ties
- victors = Array.new
- victories_ties = Hash.new
+ victories_ties = {}
candidates = @matrix.keys.sort
candidates.each do |candidate|
candidates.each do |challenger|
next if candidate == challenger
diff = @matrix[candidate][challenger] - @matrix[challenger][candidate]
- if diff >= 0
- victors << [candidate, challenger, diff]
+ victories_ties[candidate] = {} unless victories_ties.key?(candidate)
+ if diff >= 0
+ victories_ties[candidate][challenger] = diff
end
end
- end
-
- victors.each do |list|
- if victories_ties.has_key?(list[0])
- victories_ties[list[0]][list[1]] = list[2]
- else
- victories_ties[list[0]] = Hash.new
- victories_ties[list[0]][list[1]] = list[2]
- end
end
return victories_ties