1,5 → 1,6 |
package org.tela_botanica.del.client.composants.votes.moyennevotes; |
|
import java.util.HashMap; |
import java.util.Iterator; |
|
import org.tela_botanica.del.client.cache.CacheClient; |
45,9 → 46,13 |
|
public void masquerNbVotes(); |
|
public void afficherNbPoints(); |
|
public void masquerNbPoints(); |
|
public void reinitialiserVotes(); |
|
public void rafraichir(int moyenneVote, int nbVotes); |
public void rafraichir(int moyenneVote, int nbVotes, int nombrePoints); |
|
public void ajouterAuParent(HasWidgets composite); |
|
80,6 → 85,7 |
private int valeurVoteDefaut = -1; |
private int valeurVoteUtilisateur = -1; |
private int valeurVoteTotal = 0; |
private int nombrePoints = 0; |
private double valeurVoteTotalPrecise = 0.0; |
|
// TODO: on devrait passer un conteneur qui permet d'accéder à ces services |
121,6 → 127,7 |
enregistrerVote(); |
vue.afficherBoutonAnnuler(); |
vue.masquerNbVotes(); |
vue.masquerNbPoints(); |
} |
}); |
|
131,6 → 138,7 |
vue.masquerBoutonAnnuler(); |
supprimerVote(); |
vue.afficherNbVotes(); |
vue.afficherNbPoints(); |
vue.reinitialiserVotes(); |
} |
}); |
216,7 → 224,9 |
|
private void rafraichirVue() { |
valeurVoteTotal = calculerMoyenneVotesArrondie(); |
valeurVoteTotalPrecise = calculerMoyenneVotes(); |
//valeurVoteTotalPrecise = calculerMoyenneVotes(); |
valeurVoteTotalPrecise = calculerMoyennePondereeVotes(); |
nombrePoints = calculerNombrePointsEchelleArbitraire(); |
VoteProtocole voteProtocole = image.getVotesProtocoles( |
protocole.getId()).get( |
CacheClient.getInstance().getUtilisateur().getId()); |
237,31 → 247,59 |
vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise); |
presenteurFleur.go(vue.getZoneFleur()); |
vue.rafraichir(voteUtilisateur, |
image.getVotesProtocoles(protocole.getId()).size()); |
image.getVotesProtocoles(protocole.getId()).size(), nombrePoints); |
} |
|
public double calculerMoyenneVotes() { |
double valeurVote = 0; |
double nbVote = 0; |
for (Iterator<String> iterator = image |
.getVotesProtocoles(protocole.getId()).keySet().iterator(); iterator |
.hasNext();) { |
VoteProtocole imageCelValidationData = image.getVotesProtocoles( |
protocole.getId()).get(iterator.next()); |
valeurVote += (double) imageCelValidationData.getVote() / 5; |
nbVote++; |
|
// Calcule une moyenne, où chaque note est pondérée par son nombre d'occurrences au carré. |
// voir http://www.tela-botanica.org/wikini/DevInformatiques/wakka.php?wiki=AppliDelCalculVotes |
public double calculerMoyennePondereeVotes() { |
|
double score = 0; |
double diviseur = 0; |
int nbOccurrences; |
HashMap<Integer,Integer> occurrencesParNote = new HashMap<Integer,Integer>(); |
|
// rangement par note => occurrences |
for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) { |
VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef); |
nbOccurrences = 1; |
if (occurrencesParNote.containsKey(imageCelValidationData.getVote())) { |
nbOccurrences = occurrencesParNote.get(imageCelValidationData.getVote()) + 1; |
} |
occurrencesParNote.put(imageCelValidationData.getVote(), nbOccurrences); |
} |
|
if (nbVote > 0) { |
valeurVote /= nbVote; |
valeurVote *= 5; |
// calcul pondéré |
for (Integer clef : occurrencesParNote.keySet()) { |
score += clef * occurrencesParNote.get(clef) * occurrencesParNote.get(clef); |
diviseur += occurrencesParNote.get(clef) * occurrencesParNote.get(clef); |
} |
|
return valeurVote; |
if (diviseur > 0) { |
score /= diviseur; |
} |
|
return score; |
} |
|
// remplace chaque note par un nombre de points noté dans "echelle" afin de favoriser |
// les note fortes (5 et 4), pour le défi photo notamment |
public int calculerNombrePointsEchelleArbitraire() { |
int points = 0; |
int[] echelle = {-1,0,1,4,20}; |
|
for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) { |
VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef); |
points += echelle[imageCelValidationData.getVote() - 1]; |
} |
|
// @TODO ramener les votes négatifs à 0 pour ne pas insulter les contributeurs ? |
return points; |
} |
|
public int calculerMoyenneVotesArrondie() { |
double valeurVote = calculerMoyenneVotes(); |
//double valeurVote = calculerMoyenneVotes(); |
double valeurVote = calculerMoyennePondereeVotes(); |
return (int) Math.round(valeurVote); |
} |
} |