From b4ab13a9d205f96da2b9175f4948c9d451de4b77 Mon Sep 17 00:00:00 2001 From: John Morgan Date: Tue, 8 Aug 2023 09:16:11 -0400 Subject: [PATCH] Remove overvote / undervote #416 --- .../ViewModels/ViewTallyViewModel.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/electionguard-ui/ElectionGuard.UI/ViewModels/ViewTallyViewModel.cs b/src/electionguard-ui/ElectionGuard.UI/ViewModels/ViewTallyViewModel.cs index 380d169ff..5043305b0 100644 --- a/src/electionguard-ui/ElectionGuard.UI/ViewModels/ViewTallyViewModel.cs +++ b/src/electionguard-ui/ElectionGuard.UI/ViewModels/ViewTallyViewModel.cs @@ -1,6 +1,7 @@ using CommunityToolkit.Maui.Storage; using CommunityToolkit.Mvvm.Input; using ElectionGuard.Decryption.Tally; +using ElectionGuard.UI.Lib.Models; using ElectionGuard.UI.Models; using Newtonsoft.Json; @@ -180,8 +181,6 @@ private void GenerateContestData() var contest = CurrentManifest.Contests.Single(c => c.ObjectId == item.ObjectId); var contestItem = new ContestItem() { Name = contest.Name, TotalVotes = contest.VotesAllowed * (ulong)Tally.CastBallotCount }; ulong writeInTotal = 0; - ulong overVoteTotal = 0; - ulong underVoteTotal = 0; ulong totalVotes = 0; foreach (var (skey, selection) in item.Selections) @@ -204,16 +203,31 @@ private void GenerateContestData() var percent = (float)writeInTotal / (contest.VotesAllowed * (ulong)Tally.CastBallotCount) * 100; contestItem.Selections.Add(new() { Name = "Write-ins", Party = string.Empty, Votes = writeInTotal, Percent = percent }); } - underVoteTotal = (contest.VotesAllowed * (ulong)Tally.CastBallotCount) - totalVotes; - var underPercent = (float)underVoteTotal / (contest.VotesAllowed * (ulong)Tally.CastBallotCount) * 100; - contestItem.Selections.Add(new() { Name = "Undervotes", Party = string.Empty, Votes = underVoteTotal, Percent = underPercent }); - var overPercent = (float)overVoteTotal / (contest.VotesAllowed * (ulong)Tally.CastBallotCount) * 100; - contestItem.Selections.Add(new() { Name = "Overvotes", Party = string.Empty, Votes = overVoteTotal, Percent = overPercent }); + + // TallyOverVoteUndervote(contest, Tally, contestItem, totalVotes); Contests.Add(contestItem); } } + // TODO: Fix calculation and add to contest item. + private void TallyOverVoteUndervote(ContestDescriptionWithPlaceholders contest, ContestItem contestItem, ulong totalVotes) + { + if (Tally == null) + { + return; + } + + var overVoteTotal = 0UL; + var underVoteTotal = (contest.VotesAllowed * (ulong)Tally.CastBallotCount) - totalVotes; + var underPercent = (float)underVoteTotal / (contest.VotesAllowed * (ulong)Tally.CastBallotCount) * 100; + + contestItem.Selections.Add(new() { Name = "Undervotes", Party = string.Empty, Votes = underVoteTotal, Percent = underPercent }); + var overPercent = (float)overVoteTotal / (contest.VotesAllowed * (ulong)Tally.CastBallotCount) * 100; + + contestItem.Selections.Add(new() { Name = "Overvotes", Party = string.Empty, Votes = overVoteTotal, Percent = overPercent }); + } + public override async Task OnLeavingPage() { OriginalManifest?.Dispose();