mirror of
https://github.com/ArenMg/aren.git
synced 2024-12-22 23:13:29 +00:00
Merge pull request #6 from Arimihanta/main
Regler problème sur vote majoritaire
This commit is contained in:
commit
751ee3247f
2 changed files with 55 additions and 51 deletions
|
@ -27,11 +27,11 @@ public class VMVote extends AbstractEntity implements Serializable {
|
||||||
EXCELLENT
|
EXCELLENT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne
|
||||||
@JoinColumn(name = "subThemeId")
|
@JoinColumn(name = "subThemeId")
|
||||||
private VMChoice subThemeId;
|
private VMChoice subThemeId;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne
|
||||||
@JoinColumn(name = "authorId")
|
@JoinColumn(name = "authorId")
|
||||||
private User authorId ;
|
private User authorId ;
|
||||||
|
|
||||||
|
|
|
@ -63,56 +63,8 @@ public class VMThemeRESTFacade extends AbstractRESTFacade<VMTheme>{
|
||||||
|
|
||||||
|
|
||||||
themes.forEach(theme -> {
|
themes.forEach(theme -> {
|
||||||
Object []choices=theme.getChoices().toArray() ;
|
this.orderChoices(theme);
|
||||||
List<VMChoice> choicesNotVoted=new ArrayList<>() ;
|
|
||||||
List<ProposalTallyInterface> proposalTallyInterfaces=new ArrayList<>() ;
|
|
||||||
for(int i=0 ; i<choices.length ; i++){
|
|
||||||
VMChoice choice=(VMChoice) choices[i] ;
|
|
||||||
if(choice.isVoted()){
|
|
||||||
proposalTallyInterfaces.add(new ProposalTally(
|
|
||||||
new Integer[]{choice.getRejected(),
|
|
||||||
choice.getInsufficient(),
|
|
||||||
choice.getPass(),
|
|
||||||
choice.getAcceptable(),
|
|
||||||
choice.getGood(),
|
|
||||||
choice.getVeryGood(),
|
|
||||||
choice.getExcellent()})) ;
|
|
||||||
}else{
|
|
||||||
choicesNotVoted.add(choice) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VMChoice newChoices[]=new VMChoice[choices.length] ;
|
|
||||||
if(!proposalTallyInterfaces.isEmpty()){
|
|
||||||
ProposalTallyInterface []proposalTallyInterfacesArray=new ProposalTallyInterface[proposalTallyInterfaces.size()] ;
|
|
||||||
for(int i=0 ; i<proposalTallyInterfaces.size() ; i++){
|
|
||||||
proposalTallyInterfacesArray[i]=proposalTallyInterfaces.get(i) ;
|
|
||||||
}
|
|
||||||
TallyInterface tally = new NormalizedTally(proposalTallyInterfacesArray) ;
|
|
||||||
DeliberatorInterface mj = new MajorityJudgmentDeliberator();
|
|
||||||
ResultInterface result = mj.deliberate(tally);
|
|
||||||
|
|
||||||
|
|
||||||
int index=0 ;
|
|
||||||
for(ProposalResultInterface item : result.getProposalResults()){
|
|
||||||
newChoices[item.getRank()-1]=(VMChoice) choices[index] ;
|
|
||||||
System.out.println(item.getRank()+" - "+newChoices[item.getRank()-1].getTitle());
|
|
||||||
index++ ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=0 ; i<choicesNotVoted.size() ; i++){
|
|
||||||
newChoices[newChoices.length-(i+1)]= choicesNotVoted.get(i) ;
|
|
||||||
}
|
|
||||||
LinkedHashSet<VMChoice> setChoices = new LinkedHashSet<>();
|
|
||||||
System.out.println("Rang : ") ;
|
|
||||||
for(int i=0 ; i<newChoices.length ; i++){
|
|
||||||
System.out.println(i+" - "+newChoices[i].getTitle());
|
|
||||||
setChoices.add(newChoices[i]) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
theme.setChoices(setChoices);
|
|
||||||
newThemes.add(theme) ;
|
newThemes.add(theme) ;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return newThemes ;
|
return newThemes ;
|
||||||
|
@ -131,6 +83,58 @@ public class VMThemeRESTFacade extends AbstractRESTFacade<VMTheme>{
|
||||||
public VMTheme find(Long id) {
|
public VMTheme find(Long id) {
|
||||||
boolean withChoices = this.overview == null;
|
boolean withChoices = this.overview == null;
|
||||||
VMTheme theme = themeService.find(id,withChoices,true);
|
VMTheme theme = themeService.find(id,withChoices,true);
|
||||||
|
this.orderChoices(theme);
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void orderChoices(VMTheme theme){
|
||||||
|
Object []choices=theme.getChoices().toArray() ;
|
||||||
|
List<VMChoice> choicesNotVoted=new ArrayList<>() ;
|
||||||
|
List<ProposalTallyInterface> proposalTallyInterfaces=new ArrayList<>() ;
|
||||||
|
for(int i=0 ; i<choices.length ; i++){
|
||||||
|
VMChoice choice=(VMChoice) choices[i] ;
|
||||||
|
if(choice.isVoted()){
|
||||||
|
proposalTallyInterfaces.add(new ProposalTally(
|
||||||
|
new Integer[]{choice.getRejected(),
|
||||||
|
choice.getInsufficient(),
|
||||||
|
choice.getPass(),
|
||||||
|
choice.getAcceptable(),
|
||||||
|
choice.getGood(),
|
||||||
|
choice.getVeryGood(),
|
||||||
|
choice.getExcellent()})) ;
|
||||||
|
}else{
|
||||||
|
choicesNotVoted.add(choice) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VMChoice newChoices[]=new VMChoice[choices.length] ;
|
||||||
|
if(!proposalTallyInterfaces.isEmpty()){
|
||||||
|
ProposalTallyInterface []proposalTallyInterfacesArray=new ProposalTallyInterface[proposalTallyInterfaces.size()] ;
|
||||||
|
for(int i=0 ; i<proposalTallyInterfaces.size() ; i++){
|
||||||
|
proposalTallyInterfacesArray[i]=proposalTallyInterfaces.get(i) ;
|
||||||
|
}
|
||||||
|
TallyInterface tally = new NormalizedTally(proposalTallyInterfacesArray) ;
|
||||||
|
DeliberatorInterface mj = new MajorityJudgmentDeliberator();
|
||||||
|
ResultInterface result = mj.deliberate(tally);
|
||||||
|
|
||||||
|
|
||||||
|
int index=0 ;
|
||||||
|
for(ProposalResultInterface item : result.getProposalResults()){
|
||||||
|
newChoices[item.getRank()-1]=(VMChoice) choices[index] ;
|
||||||
|
System.out.println(item.getRank()+" - "+newChoices[item.getRank()-1].getTitle());
|
||||||
|
index++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0 ; i<choicesNotVoted.size() ; i++){
|
||||||
|
newChoices[newChoices.length-(i+1)]= choicesNotVoted.get(i) ;
|
||||||
|
}
|
||||||
|
LinkedHashSet<VMChoice> setChoices = new LinkedHashSet<>();
|
||||||
|
System.out.println("Rang : ") ;
|
||||||
|
for(int i=0 ; i<newChoices.length ; i++){
|
||||||
|
System.out.println(i+" - "+newChoices[i].getTitle());
|
||||||
|
setChoices.add(newChoices[i]) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
theme.setChoices(setChoices);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue