| 163 |
aurelien |
1 |
package org.tela_botanica.del.client.services;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
| 227 |
aurelien |
6 |
import java.util.Set;
|
| 163 |
aurelien |
7 |
|
|
|
8 |
import org.tela_botanica.del.client.modeles.MoyenneVote;
|
|
|
9 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
|
|
10 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
| 966 |
gduche |
11 |
import com.google.gwt.user.client.Window;
|
| 163 |
aurelien |
12 |
|
|
|
13 |
|
|
|
14 |
public class CalculVoteDeterminationService {
|
|
|
15 |
|
|
|
16 |
public static List<MoyenneVote> calculerVoteDeterminationPlusPopulaire(List<PropositionDetermination> propositions) {
|
|
|
17 |
List<MoyenneVote> pairesVotes = new ArrayList<MoyenneVote>();
|
|
|
18 |
|
|
|
19 |
for (PropositionDetermination proposition : propositions) {
|
|
|
20 |
pairesVotes.add(calculerVoteDetermination(proposition));
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
java.util.Collections.sort(pairesVotes);
|
|
|
24 |
|
|
|
25 |
return pairesVotes;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public static MoyenneVote calculerVoteDetermination(PropositionDetermination propositionDetermination) {
|
|
|
29 |
|
| 227 |
aurelien |
30 |
Map<String,VoteDetermination> votes = propositionDetermination.getVotesDeterminations();
|
| 1098 |
aurelien |
31 |
int nbVotes = votes.size();
|
|
|
32 |
double scoreVoteIdentifie = 0;
|
|
|
33 |
double scoreVoteAnonyme = 0;
|
| 163 |
aurelien |
34 |
|
| 1098 |
aurelien |
35 |
double scoreVote = 0;
|
|
|
36 |
|
| 163 |
aurelien |
37 |
if(votes.size() > 0) {
|
| 227 |
aurelien |
38 |
Set<String> cles = votes.keySet();
|
| 1098 |
aurelien |
39 |
|
| 227 |
aurelien |
40 |
for (String cle : cles) {
|
| 1098 |
aurelien |
41 |
String idAuteur = cle;
|
|
|
42 |
int valeurVote = votes.get(cle).getVote();
|
|
|
43 |
if(estUnAuteurIdentifie(idAuteur)) {
|
|
|
44 |
// un votant identifiant compte comme deux votants supplémentaires
|
|
|
45 |
// il a donc un vote 3 fois supérieur
|
|
|
46 |
scoreVoteIdentifie += 3*valeurVote;
|
|
|
47 |
nbVotes += 2;
|
|
|
48 |
} else {
|
|
|
49 |
scoreVoteAnonyme += valeurVote;
|
|
|
50 |
}
|
| 163 |
aurelien |
51 |
}
|
|
|
52 |
|
| 1098 |
aurelien |
53 |
scoreVote = ((scoreVoteAnonyme + scoreVoteIdentifie)/(nbVotes))*100;
|
| 163 |
aurelien |
54 |
} else {
|
|
|
55 |
scoreVote = -1;
|
|
|
56 |
}
|
|
|
57 |
|
| 1098 |
aurelien |
58 |
return new MoyenneVote((new Double(scoreVote)).intValue(), propositionDetermination);
|
| 163 |
aurelien |
59 |
}
|
| 1098 |
aurelien |
60 |
|
|
|
61 |
private static boolean estUnAuteurIdentifie(String idAuteur) {
|
|
|
62 |
boolean estIdentifie = true;
|
|
|
63 |
try {
|
|
|
64 |
int intIdAuteur = Integer.parseInt(idAuteur);
|
|
|
65 |
} catch (NumberFormatException nfe) {
|
|
|
66 |
estIdentifie = false;
|
|
|
67 |
}
|
|
|
68 |
return estIdentifie;
|
|
|
69 |
}
|
| 163 |
aurelien |
70 |
}
|