Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show discrepancies in UI for ballot comparison audits #2034

Merged
merged 7 commits into from
Nov 6, 2024

Conversation

nikhilb4a
Copy link
Contributor

@nikhilb4a nikhilb4a commented Nov 1, 2024

Recommend to review commit by commit

This PR adds discrepancies in UI for ballot comparison audits.

Issue

Screenshot 2024-11-06 at 1 25 56 PM
Screen.Recording.2024-11-04.at.4.52.37.PM.mov

@nikhilb4a nikhilb4a marked this pull request as ready for review November 1, 2024 22:51
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepancies-in-ui-batch-comparison branch from b4fbcdd to 3fa1594 Compare November 4, 2024 17:47
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch 6 times, most recently from 53bfe52 to f5fe503 Compare November 4, 2024 20:18
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepancies-in-ui-batch-comparison branch from 1799cd5 to 2d10c12 Compare November 4, 2024 21:06
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch from f5fe503 to 7d1bfc7 Compare November 4, 2024 21:09
Base automatically changed from nikhil/1912-discrepancies-in-ui-batch-comparison to main November 4, 2024 21:17
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch 2 times, most recently from f518012 to f0a7b18 Compare November 4, 2024 21:51
server/api/jurisdictions.py Outdated Show resolved Hide resolved
# It converts string numbers to int numbers, leaving non-numbers as is (i.e. 'o', 'u'). This is useful for
# ballot CVRs to ensure that numbers are always returned as numbers, to match the behavior of batch discrepancies
# and of vote deltas
def normalize_vals_for_discrepancies(
Copy link
Contributor Author

@nikhilb4a nikhilb4a Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ballot comparison cvrs are different than their batch comparison equivalent in that the values are all strings vs ints, to support 'o' and 'u'. Though, the code did describe it as a somewhat special case, so I am not certain it is relevant and could use some validation.

In the case where it is relevant, I thought it would be better to be consistent in returning ints where it is a number, so that is the purpose of this function. It allows us to have a single return type for discrepancies that is relatively clear. Feel free to let me know if it doesn't seem right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we just leave them as their internal representation (ints for batch comparison, strings for ballot comparison)? Might be simpler to just keep the same representation until there's somewhere we actually need to use the strings as ints, that way you don't need to think about whether it's an int in one place or a string in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm that's true. I guess I thought it might be a bit odd if the frontend is getting strings on some API calls and ints on others for the same field values, when they might both be representing a 1, so that is what motivated me to normalize it. But, leaving them as is will work for sure too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed normalization here

@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch from f0a7b18 to f8e662b Compare November 4, 2024 22:18
Copy link
Contributor

@jonahkagan jonahkagan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanatory comments!

(
sampled_ballot_id,
f"{tabulator}, {name}, Ballot Position {ballot_position}"
+ (f", Container {container}" if container is not None else ""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container should go at the beginning, if present, and not in parens (it's the highest level in the hierarchy - i.e. multiple tabulators' batches could be in a container)

server/api/jurisdictions.py Outdated Show resolved Hide resolved
server/api/jurisdictions.py Outdated Show resolved Hide resolved
server/api/jurisdictions.py Outdated Show resolved Hide resolved
server/api/jurisdictions.py Outdated Show resolved Hide resolved
Comment on lines 881 to 887
reported_votes = {}
if reported_cvr and contest.id in reported_cvr:
reported_votes = reported_cvr[contest.id]

audited_votes = {}
if audited_cvr and contest.id in audited_cvr:
audited_votes = audited_cvr[contest.id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reported_cvr and audited_cvr are guaranteed to be non-null at this point due to the checks in ballot_vote_deltas, so these could probably be condensed to:

reported_votes = reported_cvr.get(contest.id, {})
audited_votes = audited_cvr.get(contest.id, {})

Copy link
Contributor Author

@nikhilb4a nikhilb4a Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the type of audited_cvr and reported_cvr is CVR which is an optional, it can be None. So, mypy complains that Item "None" of "Optional[Dict[str, Dict[str, str]]]" has no attribute "get". I think that is why I originally had that check.

Added the use of .get, but left the null check here, unless there is a cleaner way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant they are logically guaranteed to not be None. I know the type system can't figure that out, since the checks to handle the None cases are in a different function. Up to you whether you prefer handling an impossible case to satisfy the type-system or overriding with a type assertion (I usually go for the latter, but that's just my style). Totally fine to leave it as is

Copy link
Contributor Author

@nikhilb4a nikhilb4a Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Thanks for the clarification and my bad for the miss there. I'll add in the type assertion. Still getting used to use to using type assertions consistently, but I see the benefit

# It converts string numbers to int numbers, leaving non-numbers as is (i.e. 'o', 'u'). This is useful for
# ballot CVRs to ensure that numbers are always returned as numbers, to match the behavior of batch discrepancies
# and of vote deltas
def normalize_vals_for_discrepancies(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we just leave them as their internal representation (ints for batch comparison, strings for ballot comparison)? Might be simpler to just keep the same representation until there's somewhere we actually need to use the strings as ints, that way you don't need to think about whether it's an int in one place or a string in other places

case undefined:
return 0
default:
return val
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to add a .toLocaleString() for longer numbers

@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch 5 times, most recently from bee8123 to ca24e16 Compare November 6, 2024 18:23
@nikhilb4a nikhilb4a force-pushed the nikhil/1912-discrepanices-in-ui-ballot-comparison branch from ca24e16 to 83946d1 Compare November 6, 2024 20:21
@nikhilb4a nikhilb4a merged commit 2c54830 into main Nov 6, 2024
5 checks passed
@nikhilb4a nikhilb4a deleted the nikhil/1912-discrepanices-in-ui-ballot-comparison branch November 6, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants