Subversion Repositories eFlore/Applications.del

Rev

Rev 210 | Rev 229 | 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
 
227 aurelien 41
		String truc = "";
42
 
163 aurelien 43
		if(votes.size() > 0) {
227 aurelien 44
			Set<String> cles = votes.keySet();
45
			for (String cle : cles) {
46
				scoreVote += votes.get(cle).getVote();
47
				truc += cle+"  "+votes.get(cle).getVote()+"\n";
163 aurelien 48
			}
49
 
50
			scoreVote = (scoreVote*100)/votes.size();
51
		} else {
52
			scoreVote = -1;
53
		}
54
 
189 aurelien 55
		return new MoyenneVote(scoreVote, propositionDetermination);
163 aurelien 56
	}
57
}