Skip to content

Commit

Permalink
Show discrepancies for ballot comparisons in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilb4a committed Nov 4, 2024
1 parent 18e5d31 commit 852d21d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ function getChoiceName(
return choice.name
}

function displayDiscrepancy(val: string | number | undefined): string | number {
switch (val) {
case 'o':
return 'Overvote'
case 'u':
return 'Undervote'
case undefined:
return 0
default:
return val
}
}

export interface IJurisdictionDiscrepanciesProps {
electionId: string
handleClose: () => void
Expand All @@ -69,7 +82,7 @@ const JurisdictionDiscrepancies: React.FC<IJurisdictionDiscrepanciesProps> = ({
return null
}

const discrepanciesByBatch = discrepancyQuery.data[jurisdiction.id]
const discrepanciesByBatchOrBallot = discrepancyQuery.data[jurisdiction.id]
const contests = contestsQuery.data

return (
Expand All @@ -80,13 +93,13 @@ const JurisdictionDiscrepancies: React.FC<IJurisdictionDiscrepanciesProps> = ({
title={`${jurisdiction.name} Discrepancies`}
>
<div className={Classes.DIALOG_BODY} style={{ marginBottom: 0 }}>
{Object.entries(discrepanciesByBatch).map(
([batchName, discrepanciesByContest]) => {
{Object.entries(discrepanciesByBatchOrBallot).map(
([batchOrBallotName, discrepanciesByContest]) => {
return Object.entries(discrepanciesByContest).map(
([contestId, contestDiscrepancies]) => (
<div key={contestId}>
<TableHeader>
{batchName} - {getContestName(contests, contestId)}
{batchOrBallotName} - {getContestName(contests, contestId)}
</TableHeader>
<ContestDiscrepanciesTable>
<thead>
Expand All @@ -98,24 +111,33 @@ const JurisdictionDiscrepancies: React.FC<IJurisdictionDiscrepanciesProps> = ({
</tr>
</thead>
<tbody>
{Object.keys(contestDiscrepancies.discrepancies).map(
choiceId => (
{Object.keys(contestDiscrepancies.discrepancies)
.filter(
choiceID =>
contestDiscrepancies.discrepancies[choiceID] !== 0
)
.map(choiceId => (
<tr key={choiceId}>
<td>
{getChoiceName(contests, contestId, choiceId)}
</td>
<td>
{contestDiscrepancies.reportedVotes[choiceId]}
{displayDiscrepancy(
contestDiscrepancies.reportedVotes[choiceId]
)}
</td>
<td>
{contestDiscrepancies.auditedVotes[choiceId]}
{displayDiscrepancy(
contestDiscrepancies.auditedVotes[choiceId]
)}
</td>
<td>
{contestDiscrepancies.discrepancies[choiceId]}
{displayDiscrepancy(
contestDiscrepancies.discrepancies[choiceId]
)}
</td>
</tr>
)
)}
))}
</tbody>
</ContestDiscrepanciesTable>
</div>
Expand Down
8 changes: 0 additions & 8 deletions client/src/components/AuditAdmin/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ const Progress: React.FC<IProgressProps> = ({
const showDiscrepancies =
Boolean(round) &&
(auditType === 'BALLOT_COMPARISON' || auditType === 'BATCH_COMPARISON')
const showDiscrepanciesReview =
Boolean(round) && auditType === 'BATCH_COMPARISON'
const discrepancyCountsQuery = useDiscrepancyCountsByJurisdiction(
electionId,
{ enabled: showDiscrepancies }
Expand Down Expand Up @@ -330,12 +328,6 @@ const Progress: React.FC<IProgressProps> = ({
)
}
if (!value) return null
if (!showDiscrepanciesReview)
return (
<>
<Icon icon="flag" intent="danger" /> {value.toLocaleString()}
</>
)
return (
<Button
onClick={() => setJurisdictionDiscrepanciesId(jurisdiction.id)}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/useJurisdictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ export type DiscrepanciesByJurisdiction = Record<
>

type ContestDiscrepancies = {
reportedVotes: Record<string, number> // `Record` keys are choiceId
auditedVotes: Record<string, number>
discrepancies: Record<string, number>
reportedVotes: Record<string, number | string> // `Record` keys are choiceId
auditedVotes: Record<string, number | string> // `Record` values are discrepancy counts or "o" (overvote), "u" (undervote)
discrepancies: Record<string, number | string>
}

const discrepanciesByJurisdictionQueryKey = (electionId: string): string[] =>
Expand Down

0 comments on commit 852d21d

Please sign in to comment.