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

feat(admin): Ballot Count Report Builder #4019

Merged
merged 15 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions apps/admin/frontend/src/utils/reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ test('generateTitleForReport', () => {
},
'Absentee Ballot Tally Report',
],
[
{
partyIds: ['0'],
},
'Mammal Party Tally Report',
],
[
{
batchIds: ['12345678-0000-0000-0000-000000000000'],
Expand Down Expand Up @@ -121,6 +127,27 @@ test('generateTitleForReport', () => {
},
'Ballot Style 1M Absentee Ballot Tally Report',
],
[
{
ballotStyleIds: ['1M'],
partyIds: ['0'],
},
'Mammal Party Ballot Style 1M Tally Report',
],
[
{
partyIds: ['0'],
votingMethods: ['absentee'],
},
'Mammal Party Absentee Ballot Tally Report',
],
[
{
partyIds: ['0'],
precinctIds: ['precinct-1'],
},
'Mammal Party Precinct 1 Tally Report',
],
[
{
scannerIds: ['VX-00-001'],
Expand All @@ -142,6 +169,16 @@ test('generateTitleForReport', () => {
generateTitleForReport({ filter, electionDefinition, scannerBatches })
).toEqual(ok(title));
}

// Ballot Count Report
expect(
generateTitleForReport({
filter: { precinctIds: ['precinct-1'] },
electionDefinition,
scannerBatches,
reportType: 'Ballot Count',
})
).toEqual(ok('Precinct 1 Ballot Count Report'));
});

test('canonicalizeFilter', () => {
Expand Down
91 changes: 68 additions & 23 deletions apps/admin/frontend/src/utils/reporting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Election, ElectionDefinition, Tabulation } from '@votingworks/types';
import { Optional, Result, err, find, ok } from '@votingworks/basics';
import { getPrecinctById, sanitizeStringForFilename } from '@votingworks/utils';
import {
getPartyById,
getPrecinctById,
sanitizeStringForFilename,
} from '@votingworks/utils';
import moment from 'moment';
import type { ScannerBatch } from '@votingworks/admin-backend';

Expand Down Expand Up @@ -63,6 +67,7 @@ export function generateTitleForReport({
const votingMethod = filter.votingMethods?.[0];
const batchId = filter.batchIds?.[0];
const scannerId = filter.scannerIds?.[0];
const partyId = filter.partyIds?.[0];

const reportRank = getFilterRank(filter);

Expand Down Expand Up @@ -103,39 +108,79 @@ export function generateTitleForReport({
if (scannerId) {
return ok(`Scanner ${scannerId} ${reportType} Report`);
}
}

if (reportRank === 2) {
if (precinctId && votingMethod) {
if (partyId) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A lot of the churn here is just moving things around to make this a little more readable, may wan to review side by side.

return ok(
`${getPrecinctById(electionDefinition, precinctId).name} ${
VOTING_METHOD_LABELS[votingMethod]
} Ballot ${reportType} Report`
`${
getPartyById(electionDefinition, partyId).fullName
} ${reportType} Report`
);
}
}

if (ballotStyleId && votingMethod) {
return ok(
`Ballot Style ${ballotStyleId} ${VOTING_METHOD_LABELS[votingMethod]} Ballot ${reportType} Report`
);
if (reportRank === 2) {
// Party + Other
if (partyId) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These cases were not relevant before because the tally reports cannot have a partyId, but the ballot count reports can.

const partyFullName = getPartyById(electionDefinition, partyId).fullName;
if (precinctId) {
return ok(
`${partyFullName} ${
getPrecinctById(electionDefinition, precinctId).name
} ${reportType} Report`
);
}

if (votingMethod) {
return ok(
`${partyFullName} ${VOTING_METHOD_LABELS[votingMethod]} Ballot ${reportType} Report`
);
}

if (ballotStyleId) {
return ok(
`${partyFullName} Ballot Style ${ballotStyleId} ${reportType} Report`
);
}
}

if (precinctId && ballotStyleId) {
return ok(
`Ballot Style ${ballotStyleId} ${
getPrecinctById(electionDefinition, precinctId).name
} ${reportType} Report`
);
// Ballot Style + Other
if (ballotStyleId) {
if (precinctId) {
return ok(
`Ballot Style ${ballotStyleId} ${
getPrecinctById(electionDefinition, precinctId).name
} ${reportType} Report`
);
}

if (votingMethod) {
return ok(
`Ballot Style ${ballotStyleId} ${VOTING_METHOD_LABELS[votingMethod]} Ballot ${reportType} Report`
);
}
}

if (precinctId && scannerId) {
return ok(
`${
getPrecinctById(electionDefinition, precinctId).name
} Scanner ${scannerId} ${reportType} Report`
);
// Precinct + Other
if (precinctId) {
if (votingMethod) {
return ok(
`${getPrecinctById(electionDefinition, precinctId).name} ${
VOTING_METHOD_LABELS[votingMethod]
} Ballot ${reportType} Report`
);
}

if (scannerId) {
return ok(
`${
getPrecinctById(electionDefinition, precinctId).name
} Scanner ${scannerId} ${reportType} Report`
);
}
}

// Other Combinations

if (scannerId && batchId) {
return ok(
`Scanner ${scannerId} Batch ${batchId.slice(
Expand Down