balanceWithMedian method

PollTally balanceWithMedian()

Balance your proposal tallies so that they all hold the same total amount of judgments, by filling the gaps with the majority|median grade. This adds judgments of the median grade, as many as needed (if any) to each proposal in order to balance the tallies.

Implementation

PollTally balanceWithMedian() {
  final amountOfProposals = proposals.length;
  final missingAmounts = estimateMissingJudgments();
  for (var i = 0; i < amountOfProposals; i++) {
    final missingAmount = missingAmounts[i];
    if (0 == missingAmount) continue;
    final proposalTally = proposals[i];
    final analysis = Analysis()..run(proposalTally, true);
    // final analysis = Analysis.of(proposalTally, true);  // <= me like
    proposalTally.gradesTallies[analysis.medianGrade] += missingAmount;
  }

  return this;
}