Skip to content
Open
Changes from all commits
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
24 changes: 24 additions & 0 deletions src/main/java/network/brightspots/rcv/StreamingCvrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.io.File;
import java.io.IOException;
import java.security.InvalidParameterException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javafx.util.Pair;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -60,6 +62,8 @@ final class StreamingCvrReader extends BaseCvrReader {
private final Integer batchColumnIndex;
// 0-based column index of currentPrecinct name (if present)
private final Integer precinctColumnIndex;
// 0-based column index of Ballot Style (if present)
private final Integer ballotStyleColumnIndex;
// optional delimiter for cells that contain multiple candidates
private final String overvoteDelimiter;
private final String overvoteLabel;
Expand All @@ -86,6 +90,8 @@ final class StreamingCvrReader extends BaseCvrReader {
private boolean hasSeenAnyNonBlankCandidateCells;
// flag indicating data issues during parsing
private boolean encounteredDataErrors = false;
// Does this ballot style have any empty rankings?
private Map<String, Boolean> ballotStyleHasEmptyRankings = new HashMap<>();

StreamingCvrReader(ContestConfig config, RawContestConfig.CvrSource source) {
super(config, source);
Expand All @@ -106,6 +112,7 @@ final class StreamingCvrReader extends BaseCvrReader {
!isNullOrBlank(source.getPrecinctColumnIndex())
? Integer.parseInt(source.getPrecinctColumnIndex()) - 1
: null;
this.ballotStyleColumnIndex = null; // to be implemented
this.overvoteDelimiter = source.getOvervoteDelimiter();
this.overvoteLabel = source.getOvervoteLabel();
this.skippedRankLabel = source.getSkippedRankLabel();
Expand Down Expand Up @@ -186,6 +193,23 @@ private void endCvr() {
String computedCastVoteRecordId =
String.format("%s-%d", OutputWriter.sanitizeStringForOutput(excelFileName), cvrIndex);

if (ballotStyleColumnIndex != null) {
String ballotStyle = currentCvrData.size() > ballotStyleColumnIndex
? currentCvrData.get(ballotStyleColumnIndex)
: null;

if (ballotStyleHasEmptyRankings.containsKey(ballotStyle)) {
Boolean hasPreviouslySeenNonBlankCandidateCells =
ballotStyleHasEmptyRankings.get(ballotStyle);
if (hasPreviouslySeenNonBlankCandidateCells != hasSeenAnyNonBlankCandidateCells) {
Logger.severe("Ballot style %s has some cast vote records with votes and some without. "
+ "Cast vote record file: %s", ballotStyle, excelFileName);
encounteredDataErrors = true;
} else {
ballotStyleHasEmptyRankings.put(ballotStyle, hasSeenAnyNonBlankCandidateCells);
}
}
}
if (!hasSeenAnyNonBlankCandidateCells) {
Logger.auditable(
"Skipping CVR with no votes for any candidates: %s", computedCastVoteRecordId);
Expand Down
Loading