X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/cfd119bac0ac5118dfc56057aca595dc03ea0ef0..ee900b07e68ccad333d94c0cc322dcca289349a5:/app/models/selectricity_service.rb?ds=inline diff --git a/app/models/selectricity_service.rb b/app/models/selectricity_service.rb index d383dcd..75d2e3e 100644 --- a/app/models/selectricity_service.rb +++ b/app/models/selectricity_service.rb @@ -7,15 +7,34 @@ class SelectricityService < ActionWebService::Base end def get_quickvote_results(shortname) #TODO: Validate shortname - session=ActionController::Integration::Session.new - debugger - controller=session.get "quickvote/#{shortname}/results" + qv=QuickVote.ident_to_quickvote(shortname) result=VoteResultStruct.new - result.plurality_winners=session.controller.plurality_result.winners.inspect - result.approval_winners=session.controller.approval_result.winners.inspect - result.condorcet_winners=session.controller.condorcet_result.winners.inspect - result.ssd_winners=session.controller.ssd_result.winners.inspect - result.borda_winners=session.controller.borda_result.winners.inspect + result.errors=[] + unless qv + result.errors << "No quickvote with name #{shortname} found!" + return result + end + qv.results + result.plurality_winners=qv.plurality_result.winners + result.approval_winners=qv.approval_result.winners + result.condorcet_winners=qv.condorcet_result.winners + result.ssd_winners=qv.ssd_result.winners + result.borda_winners=qv.borda_result.winners result end + def get_quickvote_candidate_map(shortname) + qv=QuickVote.ident_to_quickvote(shortname) + result=CandidateMap.new + result.errors=[] + unless qv + result.errors << "No quickvote with name #{shortname} found!" + return result + end + candidates={} + qv.candidates.each {|c| candidates[c.id] = c.name} + result.candidate_ids=candidates.keys + result.candidate_names=candidates.values + result + end + end