diff --git a/src/predictor.ts b/src/predictor.ts index 9d4fd6c..7c712dc 100644 --- a/src/predictor.ts +++ b/src/predictor.ts @@ -21,6 +21,9 @@ export function MakePrediction(election : Election) : Promise { } for (const state of Object.keys(election.states)) { + if (Object.keys(election.states[state].odds).every(p => election.states[state].odds[p] <= 0)) + for (const candidate of election.candidates) + election.states[state].odds[candidate.party] = 1; var winner = await weightedRand(election.states[state].odds); pred.candidates.find((c : any) => c.party === winner).votes += election.states[state].electoralVotes; // @ts-ignore @@ -62,6 +65,7 @@ export function betterRandom(min : number, max : number) : Promise { export async function weightedRand(spec : { [key : string] : number }) : Promise { var i, j, table = []; for (i in spec) { + if (spec[i] <= 0) continue; for (j = 0; j < spec[i] * 10; j++) { table.push(i); }