Subversion Repositories eFlore/Applications.del

Rev

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

package org.tela_botanica.del.client.services;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.tela_botanica.del.client.modeles.MoyenneVote;
import org.tela_botanica.del.client.modeles.PropositionDetermination;
import org.tela_botanica.del.client.modeles.VoteDetermination;


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) {
                
                Map<String,VoteDetermination> votes = propositionDetermination.getVotesDeterminations();
                int scoreVote = 0;
                
                if(votes.size() > 0) {
                        Set<String> cles = votes.keySet();
                        for (String cle : cles) {
                                scoreVote += votes.get(cle).getVote();
                        }
                        
                        scoreVote = (scoreVote*100)/votes.size();
                } else {
                        scoreVote = -1;
                }
                
                return new MoyenneVote(scoreVote, propositionDetermination);
        }
}