Blame | Last modification | View Log | RSS feed
package org.tela_botanica.del.client.services;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.tela_botanica.del.client.modeles.MoyenneVote;
import org.tela_botanica.del.client.modeles.PropositionDetermination;
import org.tela_botanica.del.client.modeles.VoteDetermination;
import com.google.gwt.core.client.GWT;
import com.google.gwt.logging.client.FirebugLogHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.core.java.util.Collections;
public class CalculVoteDeterminationService {
public static List<MoyenneVote> calculerVoteDeterminationPlusPopulaire(List<PropositionDetermination> propositions) {
List<MoyenneVote> pairesVotes = new ArrayList<MoyenneVote>();
for (PropositionDetermination proposition : propositions) {
pairesVotes.add(calculerVoteDetermination(proposition));
}
java.util.Collections.sort(pairesVotes);
return pairesVotes;
}
public static MoyenneVote calculerVoteDetermination(PropositionDetermination propositionDetermination) {
List<VoteDetermination> votes = propositionDetermination.getVotesDeterminations();
int scoreVote = 0;
if(votes.size() > 0) {
for (VoteDetermination vote : votes) {
scoreVote += vote.getVote();
}
scoreVote = (scoreVote*100)/votes.size();
} else {
scoreVote = -1;
}
return new MoyenneVote(scoreVote, propositionDetermination.getEspece());
}
}