@@ -6,7 +6,6 @@ import type { QuestionResponse, ResultsView } from "../../../live/question";
66import type { VotingCandidate } from "../../../live/states" ;
77import { UnreachableError } from "../../../unreachableError" ;
88import type { CreateQuestionParams , QuestionFormatDetails } from "../../types" ;
9- import { STVElection } from "../preferentialVote" ;
109import type { CloseQuestionDetails , DbQuestionData } from "./queries" ;
1110import {
1211 dbCloseQuestion ,
@@ -106,37 +105,14 @@ function mapDbQuestionData(question: DbQuestionData): RoomQuestion {
106105 } ) ;
107106 }
108107
109- const votingPreferences = Object . entries ( voterAndCandidateRank ) . map (
108+ const _votingPreferences = Object . entries ( voterAndCandidateRank ) . map (
110109 ( [ _voterId , votes ] ) => {
111110 const sortedVotes = votes . sort ( ( a , b ) => a . rank - b . rank ) ; // sort by preference
112111 return sortedVotes . map ( ( vote ) => vote . candidateId ) ;
113112 } ,
114113 ) ;
115114
116- const election = new STVElection ( )
117-
118- for ( const prefs of votingPreferences ) {
119- election . addBallot ( prefs ) ;
120- }
121-
122- const { elected, records } = election . runElection ( question . maxElected ) ;
123-
124- const results = elected . map ( ( c , index ) => ( {
125- id : c ,
126- name :
127- question . candidates . find (
128- ( candidate ) => candidate . id === c ,
129- ) ?. name || "Unknown Candidate" ,
130- rank : index + 1 ,
131- votes : records [ records . length - 1 ] ?. voteTotals [ c ] || 0 ,
132- } ) ) ;
133-
134- return {
135- type : "PreferentialVote" ,
136- results,
137- records,
138- abstained : abstainCount ,
139- } ;
115+ throw new Error ( "STV Election not implemented" ) ; // TODO: Implement STV counting and results formatting
140116 }
141117 default :
142118 throw new UnreachableError ( question . format ) ;
0 commit comments