/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/moyenne.css |
---|
12,12 → 12,43 |
color: #AAA |
} |
.petitgauche { |
.petitgauche, .petitgauchecliquable { |
font-size: 11px; |
color: #AAA; |
float: left; |
} |
.petitgauchecliquable, .fermerPanneauDetails { |
text-decoration: underline; |
cursor: pointer; |
} |
.chiffreDroite { |
float: right; |
margin-right: 10px; |
color: #22ee22; |
} |
.panneauDetailVotes { |
position: absolute; |
top: -205px; |
right: 0; |
width : 200px; |
height: 192px; |
padding: 3px; |
color: #dddddd; |
background-color: #333333; |
border: solid white 1px; |
} |
.fermerPanneauDetails { |
position: absolute; |
bottom: 3px; |
right: 3px; |
font-size: 11px; |
color: #AAA; |
} |
.barreVote { |
padding: 0 5px 0 5px |
} |
/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/MoyenneVoteVue.ui.xml |
---|
5,11 → 5,80 |
<ui:style src="moyenne.css" /> |
<g:HTMLPanel styleName="{style.moyenne}"> |
<g:HTMLPanel ui:field="panneauDetailVotes" styleName="{style.panneauDetailVotes}"> |
<g:Label ui:field="lienPanneauFermer" styleName="{style.fermerPanneauDetails}"> |
Fermer X |
</g:Label> |
Moyenne pondérée: <span ui:field="pdvMoyennePonderee" class="chiffreDroite"></span> |
<br/> |
Moyenne arithmétique: <span ui:field="pdvMoyenneArithmetique" class="chiffreDroite"></span> |
<br/> |
Médiane: <span ui:field="pdvMediane" class="chiffreDroite"></span> |
<br/> |
Nombre de points: <span ui:field="pdvNbPoints" class="chiffreDroite"></span> |
<br/> |
<table class="notesVotes"> |
<tr> |
<td class="image"> |
<img src="./img/etoile_5.png" style="width: 16px;"/> |
</td> |
<td class="barre"> |
<div ui:field="barre5" class="avancement"></div> |
</td> |
<td class="votants"> |
<span ui:field="votants5"></span> |
</td> |
</tr> |
<tr> |
<td> |
<img src="./img/etoile_4.png" style="width: 16px;"/> |
</td> |
<td class="barre"> |
<div ui:field="barre4" class="avancement"></div> |
</td> |
<td class="votants"> |
<span ui:field="votants4"></span> |
</td> |
</tr> |
<tr> |
<td> |
<img src="./img/etoile_3.png" style="width: 16px;"/> |
</td> |
<td class="barre"> |
<div ui:field="barre3" class="avancement"></div> |
</td> |
<td class="votants"> |
<span ui:field="votants3"></span> |
</td> |
</tr> |
<tr> |
<td> |
<img src="./img/etoile_2.png" style="width: 16px;"/> |
</td> |
<td class="barre"> |
<div ui:field="barre2" class="avancement"></div> |
</td> |
<td class="votants"> |
<span ui:field="votants2"></span> |
</td> |
</tr> |
<tr> |
<td> |
<img src="./img/etoile_1.png" style="width: 16px;"/> |
</td> |
<td class="barre"> |
<div ui:field="barre1" class="avancement"></div> |
</td> |
<td class="votants"> |
<span ui:field="votants1"></span> |
</td> |
</tr> |
</table> |
</g:HTMLPanel> |
<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.petitgauche}"/> |
<g:Label ui:field="nbPoints" styleName="{style.petitgauche}"/> |
<g:Label ui:field="nbVotes" styleName="{style.petitgauchecliquable}"/> |
<!-- <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,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); |
/trunk/src/org/tela_botanica/del/client/composants/votes/moyennevotes/MoyenneVoteVue.java |
---|
1,14 → 1,20 |
package org.tela_botanica.del.client.composants.votes.moyennevotes; |
import java.util.HashMap; |
import org.cobogw.gwt.user.client.ui.Rating; |
import org.tela_botanica.del.client.composants.votes.barrerepartition.InfoBulleAnim; |
import org.tela_botanica.del.client.i18n.I18n; |
import com.google.gwt.core.client.GWT; |
import com.google.gwt.dom.client.DivElement; |
import com.google.gwt.dom.client.SpanElement; |
import com.google.gwt.event.dom.client.HasClickHandlers; |
import com.google.gwt.event.dom.client.HasMouseMoveHandlers; |
import com.google.gwt.i18n.client.NumberFormat; |
import com.google.gwt.uibinder.client.UiBinder; |
import com.google.gwt.uibinder.client.UiField; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.Button; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.FocusPanel; |
36,17 → 42,23 |
FocusPanel voter; |
@UiField |
Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur; |
Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur, panneauDetailVotes; |
@UiField |
Label nbVotes, protocole, noteGenerale, nbPoints; |
Label nbVotes, protocole, noteGenerale/*, nbPoints*/, zoneVoter, lienPanneauFermer; |
@UiField |
Button boutonAnnuler; |
@UiField |
Label zoneVoter; |
// pour le panneau de détail des votes |
SpanElement pdvMoyenneArithmetique, pdvMoyennePonderee, pdvMediane, pdvNbPoints, |
votants5, votants4, votants3, votants2, votants1; |
@UiField |
DivElement barre5, barre4, barre3, barre2, barre1; |
public static final double TAILLE_MAX_BARRE = 135; // si "int", peut faire foirer les divisions |
public MoyenneVoteVue() { |
initWidget(uiBinder.createAndBindUi(this)); |
votes = new Rating(0, 5); |
53,6 → 65,7 |
votes.setReadOnly(false); |
voter.add(votes); |
masquerBoutonAnnuler(); |
masquerPanneauDetailVotes(); |
votePrisEnCompte.setVisible(false); |
animerVotePrisEnCompte = new InfoBulleAnim(votePrisEnCompte); |
animerVoteModifie = new InfoBulleAnim(voteModifie); |
67,10 → 80,14 |
return nbVotes; |
} |
public HasText getNbPoints() { |
return nbPoints; |
public HasClickHandlers getLienNbVotes() { |
return nbVotes; |
} |
/*public HasText getNbPoints() { |
return nbPoints; |
}*/ |
public HasClickHandlers getVotes() { |
return votes; |
} |
90,38 → 107,113 |
public void afficherNbVotes() { |
nbVotes.setVisible(true); |
} |
public void masquerNbVotes() { |
nbVotes.setVisible(false); |
} |
/*public void afficherNbPoints() { |
nbPoints.setVisible(true); |
}*/ |
/*public void masquerNbPoints() { |
nbPoints.setVisible(false); |
}*/ |
public void afficherNbPoints() { |
nbPoints.setVisible(true); |
public void afficherPanneauDetailVotes() { |
panneauDetailVotes.setVisible(true); |
} |
public void masquerNbPoints() { |
nbPoints.setVisible(false); |
public void masquerPanneauDetailVotes() { |
panneauDetailVotes.setVisible(false); |
} |
public Panel getPanneauDetailVotes() { |
return panneauDetailVotes; |
} |
public HasClickHandlers getLienPanneauFermer() { |
return lienPanneauFermer; |
} |
public void reinitialiserVotes() { |
votes.setValue(valeurOrigine); |
} |
public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints) { |
public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee) { |
valeurOrigine = voteUtilisateur; |
String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes(); |
if (nombreVotes > 1) { |
valeurVote += "s"; |
} |
String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints(); |
/*String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints(); |
if (nombrePoints > 1) { |
valeurPoints += "s"; |
} |
}*/ |
nbVotes.setText(valeurVote); |
nbPoints.setText(valeurPoints); |
//nbPoints.setText(valeurPoints); |
pdvNbPoints.setInnerHTML("" + nombrePoints); |
votes.setValue(voteUtilisateur); |
rafraichirPanneauDetail(moyennePonderee, moyenneArithmetique, mediane, occurrencesParNote, nombreVotes); |
} |
// si la chose est nulle, on retourne 0 |
private int nullCestZero(Integer chose) { |
if (chose == null) { |
return 0; |
} else { |
return chose; |
} |
} |
// try { |
// codeConcisEtEfficace(); |
// } catch (ShitLanguageException e) { |
// codeCracra(); |
// } |
private void rafraichirPanneauDetail(double moyennePonderee, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, int nombreVotes) { |
// stats |
NumberFormat df = NumberFormat.getFormat("0.###"); |
this.pdvMoyennePonderee.setInnerHTML("" + df.format(moyennePonderee)); |
this.pdvMoyenneArithmetique.setInnerHTML("" + df.format(moyenneArithmetique)); |
this.pdvMediane.setInnerHTML("" + df.format(mediane)); |
// détail des votes |
double tailleBarre1 = 0, |
tailleBarre2 = 0, |
tailleBarre3 = 0, |
tailleBarre4 = 0, |
tailleBarre5 = 0; |
// on peut pas mettre des attributs dans une variable ? Quelle idée aussi de faire |
// du Web avec un langage statique... du coup codre cracra, ça vous fera les pieds |
if (nombreVotes > 0) { |
if (occurrencesParNote.get(1) != null) { |
tailleBarre1 = (int) (occurrencesParNote.get(1) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(2) != null) { |
tailleBarre2 = (int) (occurrencesParNote.get(2) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(3) != null) { |
tailleBarre3 = (int) (occurrencesParNote.get(3) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(4) != null) { |
tailleBarre4 = (int) (occurrencesParNote.get(4) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(5) != null) { |
tailleBarre5 = (int) (occurrencesParNote.get(5) * TAILLE_MAX_BARRE / nombreVotes); |
} |
} |
this.barre1.setAttribute("style", "width: " + tailleBarre1 + "px;"); |
this.barre2.setAttribute("style", "width: " + tailleBarre2 + "px;"); |
this.barre3.setAttribute("style", "width: " + tailleBarre3 + "px;"); |
this.barre4.setAttribute("style", "width: " + tailleBarre4 + "px;"); |
this.barre5.setAttribute("style", "width: " + tailleBarre5 + "px;"); |
this.votants1.setInnerHTML("" + nullCestZero(occurrencesParNote.get(1))); |
this.votants2.setInnerHTML("" + nullCestZero(occurrencesParNote.get(2))); |
this.votants3.setInnerHTML("" + nullCestZero(occurrencesParNote.get(3))); |
this.votants4.setInnerHTML("" + nullCestZero(occurrencesParNote.get(4))); |
this.votants5.setInnerHTML("" + nullCestZero(occurrencesParNote.get(5))); |
} |
@Override |
public void ajouterAuParent(HasWidgets composite) { |
composite.add(this); |