-
Notifications
You must be signed in to change notification settings - Fork 19
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
STV last round use "Final Round Surplus" rather than inactive #884
Changes from 1 commit
4446731
4fd6b96
bd33aae
29afa7b
a9f4ec5
7a0dc98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,20 +382,16 @@ private void generateSummarySpreadsheet( | |
csvPrinter.println(); | ||
} | ||
|
||
List<Pair<String, StatusForRound>> statusesToPrint = new ArrayList<>(); | ||
statusesToPrint.add(new Pair<>("Overvotes", | ||
StatusForRound.INVALIDATED_BY_OVERVOTE)); | ||
statusesToPrint.add(new Pair<>("Skipped Rankings", | ||
StatusForRound.INVALIDATED_BY_SKIPPED_RANKING)); | ||
statusesToPrint.add(new Pair<>("Exhausted Choices", | ||
StatusForRound.EXHAUSTED_CHOICE)); | ||
statusesToPrint.add(new Pair<>("Repeated Rankings", | ||
StatusForRound.INVALIDATED_BY_REPEATED_RANKING)); | ||
|
||
for (Pair<String, StatusForRound> statusToPrint : statusesToPrint) { | ||
csvPrinter.print("Inactive Ballots by " + statusToPrint.getKey()); | ||
|
||
StatusForRound status = statusToPrint.getValue(); | ||
List<StatusForRound> statusesToPrint = new ArrayList<>(); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_OVERVOTE); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_SKIPPED_RANKING); | ||
statusesToPrint.add(StatusForRound.EXHAUSTED_CHOICE); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_REPEATED_RANKING); | ||
|
||
for (StatusForRound statusToPrint : statusesToPrint) { | ||
csvPrinter.print(statusToPrint.getTitleCaseKey()); | ||
|
||
StatusForRound status = statusToPrint; | ||
for (int round = 1; round <= numRounds; round++) { | ||
BigDecimal thisRoundInactive = roundTallies.get(round).getBallotStatusTally(status); | ||
csvPrinter.print(thisRoundInactive); | ||
|
@@ -457,7 +453,7 @@ private void generateSummarySpreadsheet( | |
|
||
if (config.usesSurpluses()) { | ||
// row for final round surplus (if needed) | ||
csvPrinter.print("Final Round Surplus"); | ||
csvPrinter.print(StatusForRound.FINAL_ROUND_SURPLUS.getTitleCaseKey()); | ||
for (int round = 1; round <= numRounds; round++) { | ||
BigDecimal finalRoundSurplus = | ||
roundTallies.get(round).getBallotStatusTally(StatusForRound.FINAL_ROUND_SURPLUS); | ||
|
@@ -1028,23 +1024,18 @@ private Map<String, BigDecimal> updateCandidateNamesInTally(RoundTally roundSumm | |
|
||
private Map<String, BigDecimal> getInactiveJsonMap(RoundTally roundTally) { | ||
Map<String, BigDecimal> inactiveMap = new HashMap<>(); | ||
List<Pair<String, StatusForRound>> statusesToPrint = new ArrayList<>(); | ||
statusesToPrint.add(new Pair<>("overvotes", | ||
StatusForRound.INVALIDATED_BY_OVERVOTE)); | ||
statusesToPrint.add(new Pair<>("skippedRankings", | ||
StatusForRound.INVALIDATED_BY_SKIPPED_RANKING)); | ||
statusesToPrint.add(new Pair<>("exhaustedChoices", | ||
StatusForRound.EXHAUSTED_CHOICE)); | ||
statusesToPrint.add(new Pair<>("repeatedRankings", | ||
StatusForRound.INVALIDATED_BY_REPEATED_RANKING)); | ||
List<StatusForRound> statusesToPrint = new ArrayList<>(); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_OVERVOTE); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_SKIPPED_RANKING); | ||
statusesToPrint.add(StatusForRound.EXHAUSTED_CHOICE); | ||
statusesToPrint.add(StatusForRound.INVALIDATED_BY_REPEATED_RANKING); | ||
if (config.usesSurpluses() | ||
&& roundTally.getRoundNumber() == numRounds) { | ||
statusesToPrint.add(new Pair<>("finalRoundSurplus", | ||
StatusForRound.FINAL_ROUND_SURPLUS)); | ||
statusesToPrint.add(StatusForRound.FINAL_ROUND_SURPLUS); | ||
} | ||
for (Pair<String, StatusForRound> statusToPrint : statusesToPrint) { | ||
for (StatusForRound statusToPrint : statusesToPrint) { | ||
inactiveMap.put( | ||
statusToPrint.getKey(), roundTally.getBallotStatusTally(statusToPrint.getValue())); | ||
statusToPrint.getCamelCaseKey(), roundTally.getBallotStatusTally(statusToPrint)); | ||
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. I see that you didn't love the stream suggestion! Since you're using a modifiable map here, you could use the static final immutable list described above like this:
Again, not asking for changes in this PR! Just pointing out what I see :) If it's useful to you, great! Overall, I think the changes that have already been made are a step in the right direction. |
||
} | ||
return inactiveMap; | ||
} | ||
|
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.
I'm going to leave one more comment on this, but I want to be clear that I'm not requesting additional changes in this PR. It's easy to start pulling on a thread and not know where to stop! If I were responsible for this code, I would move this list to a static final field on the class:
And then I would reuse the same list starting in line 1027.
List.of() returns an ImmutableList, so you can't conditionally add the
FINAL_ROUND_SURPLUS
to it. I'll leave a second comment on that section of the code with additional thoughts.