diff --git a/server/api/shared.py b/server/api/shared.py index c1467d491..535458e74 100644 --- a/server/api/shared.py +++ b/server/api/shared.py @@ -527,6 +527,7 @@ def ballot_vote_deltas( reported = {choice.id: "0" for choice in contest.choices} deltas = {} + total_audited_votes = 0 for choice in contest.choices: reported_vote = ( 0 if reported[choice.id] in ["o", "u"] else int(reported[choice.id]) @@ -534,8 +535,16 @@ def ballot_vote_deltas( audited_vote = ( 0 if audited[choice.id] in ["o", "u"] else int(audited[choice.id]) ) + total_audited_votes += audited_vote deltas[choice.id] = reported_vote - audited_vote + # If this is an overvote, and that was expected, there's no discrepancy here. + # TODO: do we need to do this for undervotes too? + if contest.votes_allowed and total_audited_votes > contest.votes_allowed: + for choice in contest.choices: + if reported[choice.id] == "o": + deltas[choice.id] = 0 + if all(delta == 0 for delta in deltas.values()): return None diff --git a/server/tests/ballot_comparison/snapshots/snap_test_ballot_comparison.py b/server/tests/ballot_comparison/snapshots/snap_test_ballot_comparison.py index aefc88b34..90dc86ca3 100644 --- a/server/tests/ballot_comparison/snapshots/snap_test_ballot_comparison.py +++ b/server/tests/ballot_comparison/snapshots/snap_test_ballot_comparison.py @@ -55,7 +55,7 @@ J1,0002,BATCH2,5,0002000175,"Round 1: 0.128937575131137250, 0.240487859312182291",AUDITED,Choice 1-2,Choice 1-2,,,Choice 2-2,Choice 2-2,,\r J2,0001,BATCH1,1,0001013415,Round 1: 0.228946820159681463,AUDITED,"Choice 1-1, INVALID_WRITE_IN",Choice 1-1,,,"Choice 2-1, INVALID_WRITE_IN",Choice 2-1,,\r J2,0001,BATCH1,3,0001013417,Round 1: 0.457121710197159606,AUDITED,Choice 1-1,Choice 1-1,,,Choice 2-1,Choice 2-1,,\r -J2,0001,BATCH2,3,0001000417,Round 1: 0.269793733438455805,AUDITED,"Choice 1-1, Choice 1-2",Overvote,Choice 1-1: -1; Choice 1-2: -1,,"Choice 2-1, Choice 2-3",Overvote,Choice 2-1: -1; Choice 2-3: -1,\r +J2,0001,BATCH2,3,0001000417,Round 1: 0.269793733438455805,AUDITED,"Choice 1-1, Choice 1-2",Overvote,Choice 1-2: -1,,"Choice 2-1, Choice 2-3",Overvote,,\r J2,0002,BATCH1,3,0002003173,Round 1: 0.328294241227374952,AUDITED,Choice 1-2,Overvote,Choice 1-2: -1,1,Choice 2-2,Overvote,Choice 2-2: -1,1\r J2,0002,BATCH2,1,0002000171,Round 1: 0.390715133294243377,AUDITED,Choice 1-1,Choice 1-1,,,Choice 2-3,Choice 2-3,,\r J2,0002,BATCH2,2,0002000172,Round 1: 0.064290634474137509,AUDITED,Choice 1-1,Choice 1-1,,,Choice 2-3,Choice 2-3,,\r