Merge pull request #8 from MieuxVoter/feat-default-static-grade

feat: allow setting a static default grade
pull/12/head
Dominique Merle 3 years ago committed by GitHub
commit 6770108f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,6 +44,10 @@ assert(1 == result.getProposalResults()[1].getRank()); // Proposal B
Got more than 2³² judges? Use a `Long[]` in a `ProposalTally`.
Got even more than that ? Use `BigInteger`s !
Want to set a static default grade ? Use a `TallyWithDefaultGrade` instead of a `Tally`.
## Roadmap
@ -55,9 +59,9 @@ Got more than 2³² judges? Use a `Long[]` in a `ProposalTally`.
- [x] Release v0.1.0
- [ ] Guess the amount of judges
- [ ] Allow defining a default grade
- [ ] Static Grade (configurable)
- [x] Static Grade (configurable)
- [ ] Median Grade
- [ ] Normalization (using smallest common multiple)
- [ ] Normalization (using least common multiple)
- [ ] Release v0.2.0
- [ ] Publish on package repositories
- [ ] Gradle

@ -9,17 +9,33 @@ public class ProposalTally implements ProposalTallyInterface {
// Should we allow this as well?
//public ProposalTally() {}
public ProposalTally(String[] tally) {
setTally(tally);
}
public ProposalTally(Integer[] tally) {
setTally(tally);
}
public ProposalTally(Long[] tally) {
setTally(tally);
}
public ProposalTally(BigInteger[] tally) {
setTally(tally);
}
public void setTally(String[] tally) {
int tallyLength = tally.length;
BigInteger[] bigTally = new BigInteger[tallyLength];
for (int i = 0 ; i < tallyLength ; i++) {
bigTally[i] = BigInteger.valueOf(tally[i]);
bigTally[i] = new BigInteger(tally[i]);
}
setTally(bigTally);
}
public ProposalTally(Long[] tally) {
public void setTally(Integer[] tally) {
int tallyLength = tally.length;
BigInteger[] bigTally = new BigInteger[tallyLength];
for (int i = 0 ; i < tallyLength ; i++) {
@ -27,9 +43,14 @@ public class ProposalTally implements ProposalTallyInterface {
}
setTally(bigTally);
}
public ProposalTally(BigInteger[] tally) {
setTally(tally);
public void setTally(Long[] tally) {
int tallyLength = tally.length;
BigInteger[] bigTally = new BigInteger[tallyLength];
for (int i = 0 ; i < tallyLength ; i++) {
bigTally[i] = BigInteger.valueOf(tally[i]);
}
setTally(bigTally);
}
public void setTally(BigInteger[] tally) {
@ -48,7 +69,6 @@ public class ProposalTally implements ProposalTallyInterface {
@Override
public void moveJudgments(Integer fromGrade, Integer intoGrade) {
// this.tally[intoGrade] += this.tally[fromGrade];
this.tally[intoGrade] = this.tally[intoGrade].add(this.tally[fromGrade]);
this.tally[fromGrade] = BigInteger.ZERO;
}

@ -92,7 +92,6 @@ public class ProposalTallyAnalysis {
this.medianGrade = grade;
this.contestationGroupSize = tallyBeforeCursor;
this.medianGroupSize = gradeTally;
// this.adhesionGroupSize = this.totalSize - this.contestationGroupSize - this.medianGroupSize;
this.adhesionGroupSize = this.totalSize.subtract(this.contestationGroupSize).subtract(this.medianGroupSize);
} else {
if (1 == gradeTally.compareTo(BigInteger.ZERO)) { // 0 < gradeTally
@ -108,7 +107,6 @@ public class ProposalTallyAnalysis {
this.contestationGrade = contestationGrade;
this.adhesionGrade = adhesionGrade;
// this.secondMedianGroupSize = Math.max(this.contestationGroupSize, this.adhesionGroupSize);
this.secondMedianGroupSize = this.contestationGroupSize.max(this.adhesionGroupSize);
this.secondMedianGroupSign = 0;
// if (this.contestationGroupSize < this.adhesionGroupSize) {

@ -68,8 +68,16 @@ class MajorityJudgmentDeliberatorTest {
}
tallies[i] = new ProposalTally(tally);
}
String mode = datum.getString("mode", "None");
TallyInterface tally;
if ("StaticDefault".equalsIgnoreCase(mode)) {
tally = new TallyWithDefaultGrade(tallies, amountOfParticipants, datum.getInt("default"));
} else {
tally = new Tally(tallies, amountOfParticipants);
}
DeliberatorInterface mj = new MajorityJudgmentDeliberator();
TallyInterface tally = new Tally(tallies, amountOfParticipants);
ResultInterface result = mj.deliberate(tally);
assertNotNull(result);

@ -49,6 +49,46 @@
1,
2
]
},
{
"title": "Static Default Grade",
"participants": 10,
"mode": "StaticDefault",
"default": 0,
"tallies": [
[ 2, 2, 2, 2, 2 ],
[ 1, 2, 2, 2, 2 ],
[ 0, 0, 4, 0, 0 ],
[ 0, 0, 0, 0, 2 ],
[ 0, 0, 0, 1, 1 ]
],
"ranks": [
1,
1,
3,
4,
5
]
},
{
"title": "Static Default Grade to Passable",
"participants": 10,
"mode": "StaticDefault",
"default": 2,
"tallies": [
[ 2, 2, 2, 2, 2 ],
[ 2, 2, 1, 2, 2 ],
[ 0, 0, 4, 0, 0 ],
[ 0, 0, 0, 0, 2 ],
[ 0, 0, 0, 1, 1 ]
],
"ranks": [
4,
4,
3,
1,
2
]
}
]

Loading…
Cancel
Save