Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1565 → Rev 1566

/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/moyenne.css
12,6 → 12,12
color: #AAA
}
 
.petitgauche {
font-size: 11px;
color: #AAA;
float: left;
}
 
.barreVote {
padding: 0 5px 0 5px
}
/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/MoyenneVoteVue.ui.xml
8,7 → 8,8
<g:HTMLPanel styleName="{style.zoneNoteGlobale}">
<g:Label styleName="petit enligne">Note générale</g:Label><g:Label ui:field="noteGenerale" styleName="petit enligne"/>
<g:Label ui:field="nbVotes" styleName="{style.petit}"/>
<g:Label ui:field="nbVotes" styleName="{style.petitgauche}"/>
<g:Label ui:field="nbPoints" styleName="{style.petitgauche}"/>
<g:HTMLPanel ui:field="zoneFleur" styleName="{style.zoneFleur}"></g:HTMLPanel>
</g:HTMLPanel>
<g:HorizontalPanel>
/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/MoyenneVotePresenteur.java
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);
}
}
/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/MoyenneVoteVue.java
39,7 → 39,7
Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur;
@UiField
Label nbVotes, protocole, noteGenerale;
Label nbVotes, protocole, noteGenerale, nbPoints;
 
@UiField
Button boutonAnnuler;
67,6 → 67,10
return nbVotes;
}
public HasText getNbPoints() {
return nbPoints;
}
public HasClickHandlers getVotes() {
return votes;
}
83,25 → 87,38
boutonAnnuler.setVisible(false);
}
public void afficherNbVotes () {
public void afficherNbVotes() {
nbVotes.setVisible(true);
}
public void masquerNbVotes () {
public void masquerNbVotes() {
nbVotes.setVisible(false);
}
public void afficherNbPoints() {
nbPoints.setVisible(true);
}
public void masquerNbPoints() {
nbPoints.setVisible(false);
}
public void reinitialiserVotes() {
votes.setValue(valeurOrigine);
}
public void rafraichir(int voteUtilisateur, int nombreVotes) {
public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints) {
valeurOrigine = voteUtilisateur;
String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes();
if (nombreVotes > 1) {
valeurVote += "s";
}
String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints();
if (nombrePoints > 1) {
valeurPoints += "s";
}
nbVotes.setText(valeurVote);
nbPoints.setText(valeurPoints);
votes.setValue(voteUtilisateur);
}