-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update VxAdmin to support importing new CVR export format #3956
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05c37b9
Move VxAdmin CVR helpers to libs/utils
arsalansufi f8abdf5
Add libs/utils helper for parsing new export directory name format
arsalansufi 8da64a4
Fix artifact authentication bug
arsalansufi 85674ce
Specify encoding when reading files, rather than converting after
arsalansufi c3ae016
Add libs/backend helpers for importing CVRs
arsalansufi 6ea6ad4
Update logic for listing CVR exports on a USB
arsalansufi 9474952
Add new VxAdmin CVR import function
arsalansufi 830a757
Use new CVR import function in API
arsalansufi a668787
Add client-side logic for user readable messages
arsalansufi 84480ad
Use optimized helpers in libs/utils
arsalansufi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ export interface CastVoteRecordReportListing { | |
timestamp: Date; | ||
} | ||
|
||
export interface CastVoteRecordExportDirectoryNameComponents { | ||
inTestMode: boolean; | ||
machineId: string; | ||
time: Date; | ||
} | ||
|
||
export function sanitizeStringForFilename( | ||
input: string, | ||
{ replaceInvalidCharsWith = '', defaultValue = 'placeholder' } = {} | ||
|
@@ -120,37 +126,15 @@ export function generateCastVoteRecordReportDirectoryName( | |
return isTestMode ? `TEST${SECTION_SEPARATOR}${filename}` : filename; | ||
} | ||
|
||
/** | ||
* Generates a name for a cast vote record export directory | ||
*/ | ||
export function generateCastVoteRecordExportDirectoryName({ | ||
inTestMode, | ||
machineId, | ||
time = new Date(), | ||
}: { | ||
inTestMode: boolean; | ||
machineId: string; | ||
time?: Date; | ||
}): string { | ||
const machineString = [ | ||
'machine', | ||
maybeParse(MachineId, machineId) ?? sanitizeStringForFilename(machineId), | ||
].join(SUBSECTION_SEPARATOR); | ||
const timeString = moment(time).format(TIME_FORMAT_STRING); | ||
const directoryNameComponents = [machineString, timeString]; | ||
if (inTestMode) { | ||
directoryNameComponents.unshift('TEST'); | ||
} | ||
return directoryNameComponents.join(SECTION_SEPARATOR); | ||
} | ||
|
||
/** | ||
* Extract information about a CVR file from the filename. Expected filename | ||
* format with human-readable separators is: | ||
* [TEST__]machine_{machineId}__{numberOfBallots}_ballots__YYYY-MM-DD_HH-mm-ss.jsonl | ||
* This format is current as of 2023-02-22 and may be out of date if separator constants have changed | ||
* | ||
* If the the parsing is unsuccessful, returns `undefined`. | ||
* | ||
* @deprecated | ||
*/ | ||
export function parseCastVoteRecordReportDirectoryName( | ||
filename: string | ||
|
@@ -326,3 +310,62 @@ export function generateLogFilename( | |
throwIllegalValue(fileType); | ||
} | ||
} | ||
|
||
/** | ||
* Generates a name for a cast vote record export directory | ||
*/ | ||
export function generateCastVoteRecordExportDirectoryName({ | ||
inTestMode, | ||
machineId, | ||
time = new Date(), | ||
}: Omit<CastVoteRecordExportDirectoryNameComponents, 'time'> & { | ||
time?: Date; | ||
}): string { | ||
const machineString = [ | ||
'machine', | ||
maybeParse(MachineId, machineId) ?? sanitizeStringForFilename(machineId), | ||
].join(SUBSECTION_SEPARATOR); | ||
const timeString = moment(time).format(TIME_FORMAT_STRING); | ||
const directoryNameComponents = [machineString, timeString]; | ||
if (inTestMode) { | ||
directoryNameComponents.unshift('TEST'); | ||
} | ||
return directoryNameComponents.join(SECTION_SEPARATOR); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this function is just moved down from above. The one below is new. |
||
|
||
/** | ||
* Extracts information about a cast vote record export from the export directory name | ||
*/ | ||
export function parseCastVoteRecordReportExportDirectoryName( | ||
exportDirectoryName: string | ||
): Optional<CastVoteRecordExportDirectoryNameComponents> { | ||
const sections = exportDirectoryName.split(SECTION_SEPARATOR); | ||
const inTestMode = sections.length === 3 && sections[0] === 'TEST'; | ||
const postTestPrefixSections = inTestMode ? sections.slice(1) : sections; | ||
if (postTestPrefixSections.length !== 2) { | ||
return; | ||
} | ||
assert(postTestPrefixSections[0] !== undefined); | ||
assert(postTestPrefixSections[1] !== undefined); | ||
|
||
const machineString = postTestPrefixSections[0]; | ||
const machineSubsections = machineString.split(SUBSECTION_SEPARATOR); | ||
if (machineSubsections.length !== 2 || machineSubsections[0] !== 'machine') { | ||
return; | ||
} | ||
assert(machineSubsections[1] !== undefined); | ||
const machineId = machineSubsections[1]; | ||
|
||
const timeString = postTestPrefixSections[1]; | ||
const timeMoment = moment(timeString, TIME_FORMAT_STRING); | ||
if (!timeMoment.isValid()) { | ||
return; | ||
} | ||
const time = timeMoment.toDate(); | ||
|
||
return { | ||
inTestMode, | ||
machineId, | ||
time, | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
test.each
is just moved down from above. The one below is new.