1,7 → 1,11 |
package org.tela_botanica.del.client.composants.votes.moyennevotes; |
|
import java.util.ArrayList; |
import java.util.Collections; |
import java.util.Comparator; |
import java.util.HashMap; |
import java.util.Iterator; |
import java.util.List; |
|
import org.tela_botanica.del.client.cache.CacheClient; |
import org.tela_botanica.del.client.composants.votefleur.VoteFleurPresenteur; |
28,6 → 32,7 |
import com.google.gwt.user.client.ui.HasText; |
import com.google.gwt.user.client.ui.HasWidgets; |
import com.google.gwt.user.client.ui.IsWidget; |
import com.google.gwt.user.client.ui.Panel; |
|
public class MoyenneVotePresenteur { |
|
46,13 → 51,13 |
|
public void masquerNbVotes(); |
|
public void afficherNbPoints(); |
//public void afficherNbPoints(); |
|
public void masquerNbPoints(); |
//public void masquerNbPoints(); |
|
public void reinitialiserVotes(); |
|
public void rafraichir(int moyenneVote, int nbVotes, int nombrePoints); |
public void rafraichir(int moyenneVote, int nbVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee); |
|
public void ajouterAuParent(HasWidgets composite); |
|
62,6 → 67,12 |
|
public HasText getZoneProtocole(); |
|
public HasText getNbVotes(); |
|
//public HasText getNbPoints(); |
|
public HasClickHandlers getLienNbVotes(); |
|
public void setNoteGenerale(int note); |
|
public void afficherVoteModifie(); |
71,11 → 82,19 |
|
public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise); |
|
void desactiverInteractionVote(); |
public void desactiverInteractionVote(); |
|
void activerInteractionVote(); |
public void activerInteractionVote(); |
|
void afficherVoteSupprime(); |
public void afficherVoteSupprime(); |
|
public Panel getPanneauDetailVotes(); |
|
public void afficherPanneauDetailVotes(); |
|
public void masquerPanneauDetailVotes(); |
|
public HasClickHandlers getLienPanneauFermer(); |
} |
|
private Vue vue; |
85,8 → 104,11 |
private int valeurVoteDefaut = -1; |
private int valeurVoteUtilisateur = -1; |
private int valeurVoteTotal = 0; |
private double moyenneArithmetique = 0; |
private double mediane = 0; |
private int nombrePoints = 0; |
private double valeurVoteTotalPrecise = 0.0; |
private HashMap<Integer,Integer> occurrencesParNote; |
|
// TODO: on devrait passer un conteneur qui permet d'accéder à ces services |
private VoteProtocoleService voteProtocoleService; |
126,8 → 148,6 |
valeurVoteUtilisateur = vue.getValeurVote(); |
enregistrerVote(); |
vue.afficherBoutonAnnuler(); |
vue.masquerNbVotes(); |
vue.masquerNbPoints(); |
} |
}); |
|
137,12 → 157,29 |
valeurVoteUtilisateur = valeurVoteDefaut; |
vue.masquerBoutonAnnuler(); |
supprimerVote(); |
vue.afficherNbVotes(); |
vue.afficherNbPoints(); |
vue.reinitialiserVotes(); |
} |
}); |
|
|
// Affiche un chouette panneau qui montre le détail des votes |
vue.getLienNbVotes().addClickHandler(new ClickHandler() { |
@Override |
public void onClick(ClickEvent event) { |
if (vue.getPanneauDetailVotes().isVisible()) { |
vue.masquerPanneauDetailVotes(); |
} else { |
vue.afficherPanneauDetailVotes(); |
} |
} |
}); |
|
vue.getLienPanneauFermer().addClickHandler(new ClickHandler() { |
@Override |
public void onClick(ClickEvent event) { |
vue.masquerPanneauDetailVotes(); |
} |
}); |
|
BusEvenementiel.getInstance().addHandler(EvenementChangementEtatUtilisateur.TYPE, new GestionnaireEvenementChangementEtatUtilisateur() { |
@Override |
public void onModificationEtatUtilisateur(EvenementChangementEtatUtilisateur evenementChangementEtatUtilisateur) { |
224,7 → 261,8 |
|
private void rafraichirVue() { |
valeurVoteTotal = calculerMoyenneVotesArrondie(); |
//valeurVoteTotalPrecise = calculerMoyenneVotes(); |
moyenneArithmetique = calculerMoyenneVotes(); |
mediane = calculerMedianeVotes(); |
valeurVoteTotalPrecise = calculerMoyennePondereeVotes(); |
nombrePoints = calculerNombrePointsEchelleArbitraire(); |
VoteProtocole voteProtocole = image.getVotesProtocoles( |
246,10 → 284,62 |
vue.setNoteGenerale(valeurVoteTotal); |
vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise); |
presenteurFleur.go(vue.getZoneFleur()); |
vue.rafraichir(voteUtilisateur, |
image.getVotesProtocoles(protocole.getId()).size(), nombrePoints); |
vue.rafraichir(voteUtilisateur, image.getVotesProtocoles(protocole.getId()).size(), nombrePoints, |
moyenneArithmetique, mediane, occurrencesParNote, valeurVoteTotalPrecise); |
} |
|
public double calculerMedianeVotes() { |
double med = 0; |
// comparateur de votes (le bulldozer Java™ pour écraser une mouche) |
class Comparatisateur3000 implements Comparator<VoteProtocole> { |
@Override |
public int compare(VoteProtocole v1, VoteProtocole v2) { |
if (v1.getVote() > v2.getVote()) { |
return 1; |
} else if (v1.getVote() > v2.getVote()) { |
return -1; |
} else { |
return 0; |
} |
} |
} |
// conversion en liste triable |
List<VoteProtocole> liste = new ArrayList<VoteProtocole>(image.getVotesProtocoles(protocole.getId()).values()); |
Collections.sort(liste, new Comparatisateur3000()); |
int longueur = liste.size(); |
if (longueur > 0) { |
if (longueur % 2 == 0) { |
// moyenne des éléments centraux |
med = (liste.get(longueur / 2 - 1).getVote() + liste.get(longueur / 2).getVote()) / 2; |
} else { |
// élément central |
med = liste.get((int) (longueur / 2)).getVote(); |
} |
} |
return med; |
} |
|
// calcule la moyenne arithmétique |
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++; |
} |
|
if (nbVote > 0) { |
valeurVote /= nbVote; |
valeurVote *= 5; |
} |
|
return valeurVote; |
} |
|
// 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() { |
257,7 → 347,8 |
double score = 0; |
double diviseur = 0; |
int nbOccurrences; |
HashMap<Integer,Integer> occurrencesParNote = new HashMap<Integer,Integer>(); |
// mise à jour des occurrences par note, utile pour le panneau de détails |
occurrencesParNote = new HashMap<Integer,Integer>(); |
|
// rangement par note => occurrences |
for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) { |
286,7 → 377,8 |
// 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}; |
//int[] echelle = {-1,0,1,4,20}; |
int[] echelle = {1,10,100,1000,10000}; |
|
for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) { |
VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef); |