Subversion Repositories eFlore/Applications.del

Rev

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