Subversion Repositories eFlore/Applications.del

Rev

Rev 229 | Rev 1098 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
11
 
12
 
13
public class CalculVoteDeterminationService {
14
 
15
	public static List<MoyenneVote> calculerVoteDeterminationPlusPopulaire(List<PropositionDetermination> propositions) {
16
 
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();
163 aurelien 31
		int scoreVote = 0;
32
 
33
		if(votes.size() > 0) {
227 aurelien 34
			Set<String> cles = votes.keySet();
35
			for (String cle : cles) {
36
				scoreVote += votes.get(cle).getVote();
163 aurelien 37
			}
38
 
39
			scoreVote = (scoreVote*100)/votes.size();
40
		} else {
41
			scoreVote = -1;
42
		}
43
 
189 aurelien 44
		return new MoyenneVote(scoreVote, propositionDetermination);
163 aurelien 45
	}
46
}