Skip to content

Commit

Permalink
make Convert to CDF filenames more likely to be unique (#751)
Browse files Browse the repository at this point in the history
Co-authored-by: Armin Samii <[email protected]>
  • Loading branch information
artoonie and artoonie authored Sep 28, 2023
1 parent 9c5e0af commit 02a00cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/network/brightspots/rcv/ResultsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,28 @@ String writeGenericCvrCsv(
List<CastVoteRecord> castVoteRecords,
Integer numRanks,
String csvOutputFolder,
String inputFilepath,
String contestId,
String undeclaredWriteInLabel)
throws IOException {
String fileWritten;
// Get input filename with extension
String inputFileBaseName = new File(inputFilepath).getName();
// Remove the extension if it exists
int lastIndex = inputFileBaseName.lastIndexOf('.');
if (lastIndex != -1) {
inputFileBaseName = inputFileBaseName.substring(0, lastIndex);
}
// Put the input filename in the output filename in case contestId isn't unique --
// knowing that it's possible that if both the filename AND the contestId isn't unique,
// this will fail.
Path outputPath =
Paths.get(
getOutputFilePath(
csvOutputFolder,
"dominion_conversion_contest",
timestampString,
sanitizeStringForOutput(contestId))
inputFileBaseName + "-" + sanitizeStringForOutput(contestId))
+ ".csv");
try {
Logger.info("Writing cast vote records in generic format to file: %s...", outputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ private List<CastVoteRecord> parseCastVoteRecords(ContestConfig config) {
castVoteRecords,
reader.getMaxRankingsAllowed(source.getContestId()),
config.getOutputDirectory(),
source.getFilePath(),
source.getContestId(),
source.getUndeclaredWriteInLabel());
} catch (IOException exception) {
Expand Down

0 comments on commit 02a00cd

Please sign in to comment.