Skip to content

Commit

Permalink
fix merge conflict from PR 816 (#833)
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 May 29, 2024
1 parent 9e95760 commit 951f5f3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/main/java/network/brightspots/rcv/ContestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,10 @@ enum TabulateBySlice {
public String toString() {
return label;
}

public String toLowerString() {
return label.toLowerCase();
}
}

static class UnrecognizedProviderException extends Exception {}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/network/brightspots/rcv/ResultsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static List<Map.Entry<String, List<Integer>>> getCandidatesWithRanksList
// return a unique, valid string for this slice's output spreadsheet filename
private static String getFileStringForSlice(
ContestConfig.TabulateBySlice slice, String sliceId, Set<String> filenames) {
String sanitized = "%s_%s".formatted(slice, sanitizeStringForOutput(sliceId));
String sanitized = "%s_%s".formatted(sanitizeStringForOutput(sliceId), slice.toLowerString());
String filename = sanitized;
// appendNumber is used to find a unique filename (in practice this really shouldn't be
// necessary because different slice IDs shouldn't have the same sanitized name, but we're
Expand Down Expand Up @@ -941,7 +941,7 @@ private void generateSummaryJson(
configData.put("office", config.getContestOffice());
configData.put("date", config.getContestDate());
if (!isNullOrBlank(sliceId)) {
configData.put(slice.toString(), sliceId);
configData.put(slice.toLowerString(), sliceId);
}

BigDecimal firstRoundUndervotes =
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/network/brightspots/rcv/Tabulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,11 @@ private void calculateAndSetWinningThreshold(
private void setWinningThreshold(int roundNumber, BigDecimal winningThreshold) {
RoundTally currentRoundTally = roundTallies.get(roundNumber);
currentRoundTally.setWinningThreshold(winningThreshold);
// Do the same for each precinct
if (config.isTabulateByPrecinctEnabled()) {
for (var roundTalliesForPrecinct : precinctRoundTallies.values()) {
roundTalliesForPrecinct.get(roundNumber).setWinningThreshold(winningThreshold);

// Do the same for each slice
for (TabulateBySlice slice : config.enabledSlices()) {
for (var roundTalliesForSlice : roundTalliesBySlices.get(slice).values()) {
roundTalliesForSlice.get(roundNumber).setWinningThreshold(winningThreshold);
}
}
Logger.info("Winning threshold set to %s.", winningThreshold);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/network/brightspots/rcv/TabulatorSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ List<String> tabulate(String operatorName) {
return exceptionsEncountered;
}

Set<String> loadPrecinctNamesFromCvrs(ContestConfig config) {
Set<String> loadSliceNamesFromCvrs(ContestConfig.TabulateBySlice slice, ContestConfig config) {
List<CastVoteRecord> castVoteRecords = parseCastVoteRecords(config);
try {
return new Tabulator(castVoteRecords, config).getPrecinctIds();
} catch (IOException | TabulationAbortedException e) {
return new Tabulator(castVoteRecords, config).getEnabledSliceIds().get(slice);
} catch (TabulationAbortedException e) {
throw new RuntimeException(e);
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/test/java/network/brightspots/rcv/TabulatorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ private static void runTabulationTest(String testStem) {
runTabulationTest(testStem, null, 0);
}

private static void runTabulationTest(String testStem, int expectedNumPrecinctFilesToCheck) {
runTabulationTest(testStem, null, expectedNumPrecinctFilesToCheck);
private static void runTabulationTest(String testStem, int expectedNumSliceFilesToCheck) {
runTabulationTest(testStem, null, expectedNumSliceFilesToCheck);
}

private static void runTabulationTest(String testStem, String expectedException) {
Expand All @@ -207,7 +207,7 @@ private static void runTabulationTest(String testStem, String expectedException)

// helper function to support running various tabulation tests
private static void runTabulationTest(String stem, String expectedException,
int expectedNumPrecinctFilesToCheck) {
int expectedNumSliceFilesToCheck) {
String configPath = getTestFilePath(stem, "_config.json");

Logger.info("Running tabulation test: %s\nTabulating config file: %s...", stem, configPath);
Expand All @@ -229,19 +229,20 @@ private static void runTabulationTest(String stem, String expectedException,
compareFiles(config, stem, timestampString, null);
}

int numPrecinctFilesChecked = 0;
if (config.isTabulateByPrecinctEnabled()) {
for (String precinct : session.loadPrecinctNamesFromCvrs(config)) {
String outputType = ResultsWriter.sanitizeStringForOutput(precinct + "_precinct_summary");
int numSlicedFilesChecked = 0;
for (ContestConfig.TabulateBySlice slice : config.enabledSlices()) {
for (String sliceName : session.loadSliceNamesFromCvrs(slice, config)) {
String outputType = ResultsWriter.sanitizeStringForOutput(
String.format("%s_%s_summary", sliceName, slice.toLowerString()));
if (compareFiles(config, stem, outputType, ".json", timestampString, null, true)) {
numPrecinctFilesChecked++;
numSlicedFilesChecked++;
}
if (compareFiles(config, stem, outputType, ".csv", timestampString, null, true)) {
numPrecinctFilesChecked++;
numSlicedFilesChecked++;
}
}
}
assertEquals(numPrecinctFilesChecked, expectedNumPrecinctFilesToCheck);
assertEquals(expectedNumSliceFilesToCheck, numSlicedFilesChecked);

cleanOutputFolder(session);
}
Expand Down

0 comments on commit 951f5f3

Please sign in to comment.