163 |
aurelien |
1 |
package org.tela_botanica.del.client.services;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Comparator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
import java.util.TreeMap;
|
|
|
8 |
|
|
|
9 |
import org.tela_botanica.del.client.modeles.MoyenneVote;
|
|
|
10 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
|
|
12 |
|
|
|
13 |
import com.google.gwt.core.client.GWT;
|
|
|
14 |
import com.google.gwt.logging.client.FirebugLogHandler;
|
|
|
15 |
import com.google.gwt.user.client.Window;
|
|
|
16 |
import com.google.gwt.user.client.rpc.core.java.util.Collections;
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
public class CalculVoteDeterminationService {
|
|
|
20 |
|
|
|
21 |
public static List<MoyenneVote> calculerVoteDeterminationPlusPopulaire(List<PropositionDetermination> propositions) {
|
|
|
22 |
|
|
|
23 |
List<MoyenneVote> pairesVotes = new ArrayList<MoyenneVote>();
|
|
|
24 |
|
|
|
25 |
for (PropositionDetermination proposition : propositions) {
|
|
|
26 |
pairesVotes.add(calculerVoteDetermination(proposition));
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
java.util.Collections.sort(pairesVotes);
|
|
|
30 |
|
|
|
31 |
return pairesVotes;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public static MoyenneVote calculerVoteDetermination(PropositionDetermination propositionDetermination) {
|
|
|
35 |
|
|
|
36 |
List<VoteDetermination> votes = propositionDetermination.getVotesDeterminations();
|
|
|
37 |
int scoreVote = 0;
|
|
|
38 |
|
|
|
39 |
if(votes.size() > 0) {
|
|
|
40 |
for (VoteDetermination vote : votes) {
|
|
|
41 |
scoreVote += vote.getVote();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
scoreVote = (scoreVote*100)/votes.size();
|
|
|
45 |
} else {
|
|
|
46 |
scoreVote = -1;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
return new MoyenneVote(scoreVote, propositionDetermination.getEspece());
|
|
|
50 |
}
|
|
|
51 |
}
|