Subversion Repositories eFlore/Applications.del

Rev

Rev 1573 | Rev 2000 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1573 Rev 1583
Line 1... Line 1...
1
package org.tela_botanica.del.client.composants.votes.moyennevotes;
1
package org.tela_botanica.del.client.composants.votes.moyennevotes;
Line -... Line 2...
-
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.Collections;
2
 
5
import java.util.Comparator;
3
import java.util.HashMap;
6
import java.util.HashMap;
-
 
7
import java.util.Iterator;
Line 4... Line 8...
4
import java.util.Iterator;
8
import java.util.List;
5
 
9
 
6
import org.tela_botanica.del.client.cache.CacheClient;
10
import org.tela_botanica.del.client.cache.CacheClient;
7
import org.tela_botanica.del.client.composants.votefleur.VoteFleurPresenteur;
11
import org.tela_botanica.del.client.composants.votefleur.VoteFleurPresenteur;
Line 26... Line 30...
26
import com.google.gwt.event.dom.client.MouseMoveHandler;
30
import com.google.gwt.event.dom.client.MouseMoveHandler;
27
import com.google.gwt.user.client.Window;
31
import com.google.gwt.user.client.Window;
28
import com.google.gwt.user.client.ui.HasText;
32
import com.google.gwt.user.client.ui.HasText;
29
import com.google.gwt.user.client.ui.HasWidgets;
33
import com.google.gwt.user.client.ui.HasWidgets;
30
import com.google.gwt.user.client.ui.IsWidget;
34
import com.google.gwt.user.client.ui.IsWidget;
-
 
35
import com.google.gwt.user.client.ui.Panel;
Line 31... Line 36...
31
 
36
 
Line 32... Line 37...
32
public class MoyenneVotePresenteur {
37
public class MoyenneVotePresenteur {
33
 
38
 
Line 44... Line 49...
44
 
49
 
Line 45... Line 50...
45
		public void afficherNbVotes();
50
		public void afficherNbVotes();
Line 46... Line 51...
46
 
51
 
Line 47... Line 52...
47
		public void masquerNbVotes();
52
		public void masquerNbVotes();
Line 48... Line 53...
48
 
53
 
Line 49... Line 54...
49
		public void afficherNbPoints();
54
		//public void afficherNbPoints();
Line 50... Line 55...
50
 
55
 
Line 51... Line 56...
51
		public void masquerNbPoints();
56
		//public void masquerNbPoints();
Line 52... Line 57...
52
 
57
 
Line 53... Line 58...
53
		public void reinitialiserVotes();
58
		public void reinitialiserVotes();
Line -... Line 59...
-
 
59
 
-
 
60
		public void rafraichir(int moyenneVote, int nbVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee);
-
 
61
 
-
 
62
		public void ajouterAuParent(HasWidgets composite);
-
 
63
 
-
 
64
		public void afficherVotePrisEnCompte();
54
 
65
 
Line 55... Line 66...
55
		public void rafraichir(int moyenneVote, int nbVotes, int nombrePoints);
66
		public HasWidgets getZoneFleur();
Line 56... Line 67...
56
 
67
 
57
		public void ajouterAuParent(HasWidgets composite);
68
		public HasText getZoneProtocole();
Line 58... Line 69...
58
 
69
 
Line 59... Line 70...
59
		public void afficherVotePrisEnCompte();
70
		public HasText getNbVotes();
-
 
71
 
-
 
72
		//public HasText getNbPoints();
-
 
73
 
-
 
74
		public HasClickHandlers getLienNbVotes();
Line 60... Line 75...
60
 
75
 
Line 61... Line 76...
61
		public HasWidgets getZoneFleur();
76
		public void setNoteGenerale(int note);
-
 
77
 
-
 
78
		public void afficherVoteModifie();
-
 
79
 
-
 
80
		public HasMouseMoveHandlers getZoneVoter();
62
 
81
		public void masquerZoneVoter();
Line 63... Line 82...
63
		public HasText getZoneProtocole();
82
 
64
 
83
		public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise);
65
		public void setNoteGenerale(int note);
84
 
Line 66... Line 85...
66
 
85
		public void desactiverInteractionVote();
67
		public void afficherVoteModifie();
86
 
68
 
87
		public void activerInteractionVote();
-
 
88
 
-
 
89
		public void afficherVoteSupprime();
69
		public HasMouseMoveHandlers getZoneVoter();
90
 
70
		public void masquerZoneVoter();
91
		public Panel getPanneauDetailVotes();
-
 
92
 
Line 71... Line 93...
71
 
93
		public void afficherPanneauDetailVotes();
72
		public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise);
94
 
Line 73... Line 95...
73
 
95
		public void masquerPanneauDetailVotes();
Line 124... Line 146...
124
			@Override
146
			@Override
125
			public void onClick(ClickEvent event) {
147
			public void onClick(ClickEvent event) {
126
				valeurVoteUtilisateur = vue.getValeurVote();
148
				valeurVoteUtilisateur = vue.getValeurVote();
127
				enregistrerVote();
149
				enregistrerVote();
128
				vue.afficherBoutonAnnuler();
150
				vue.afficherBoutonAnnuler();
129
				vue.masquerNbVotes();
-
 
130
				vue.masquerNbPoints();
-
 
131
			}
151
			}
132
		});
152
		});
Line 133... Line 153...
133
 
153
 
134
		vue.getBoutonAnnuler().addClickHandler(new ClickHandler() {
154
		vue.getBoutonAnnuler().addClickHandler(new ClickHandler() {
135
			@Override
155
			@Override
136
			public void onClick(ClickEvent event) {
156
			public void onClick(ClickEvent event) {
137
				valeurVoteUtilisateur = valeurVoteDefaut;
157
				valeurVoteUtilisateur = valeurVoteDefaut;
138
				vue.masquerBoutonAnnuler();
158
				vue.masquerBoutonAnnuler();
139
				supprimerVote();
-
 
140
				vue.afficherNbVotes();
-
 
141
				vue.afficherNbPoints();
159
				supprimerVote();
142
				vue.reinitialiserVotes();
160
				vue.reinitialiserVotes();
143
			}
161
			}
144
		});
162
		});
-
 
163
 
-
 
164
		// Affiche un chouette panneau qui montre le détail des votes
-
 
165
		vue.getLienNbVotes().addClickHandler(new ClickHandler() {
-
 
166
			@Override
-
 
167
			public void onClick(ClickEvent event) {
-
 
168
				if (vue.getPanneauDetailVotes().isVisible()) {
-
 
169
					vue.masquerPanneauDetailVotes();
-
 
170
				} else {
-
 
171
					vue.afficherPanneauDetailVotes();
-
 
172
				}
-
 
173
			}
-
 
174
		});
-
 
175
 
-
 
176
		vue.getLienPanneauFermer().addClickHandler(new ClickHandler() {
-
 
177
			@Override
-
 
178
			public void onClick(ClickEvent event) {
-
 
179
				vue.masquerPanneauDetailVotes();
-
 
180
			}
-
 
181
		});
145
		
182
 
146
		BusEvenementiel.getInstance().addHandler(EvenementChangementEtatUtilisateur.TYPE, new GestionnaireEvenementChangementEtatUtilisateur() {		
183
		BusEvenementiel.getInstance().addHandler(EvenementChangementEtatUtilisateur.TYPE, new GestionnaireEvenementChangementEtatUtilisateur() {		
147
			@Override
184
			@Override
148
			public void onModificationEtatUtilisateur(EvenementChangementEtatUtilisateur evenementChangementEtatUtilisateur) {
185
			public void onModificationEtatUtilisateur(EvenementChangementEtatUtilisateur evenementChangementEtatUtilisateur) {
149
				rafraichirVue();
186
				rafraichirVue();
Line 222... Line 259...
222
		return vue;
259
		return vue;
223
	}
260
	}
Line 224... Line 261...
224
 
261
 
225
	private void rafraichirVue() {
262
	private void rafraichirVue() {
226
		valeurVoteTotal = calculerMoyenneVotesArrondie();
263
		valeurVoteTotal = calculerMoyenneVotesArrondie();
-
 
264
		moyenneArithmetique = calculerMoyenneVotes();
227
		//valeurVoteTotalPrecise = calculerMoyenneVotes();
265
		mediane = calculerMedianeVotes();
228
		valeurVoteTotalPrecise = calculerMoyennePondereeVotes();
266
		valeurVoteTotalPrecise = calculerMoyennePondereeVotes();
229
		nombrePoints = calculerNombrePointsEchelleArbitraire();
267
		nombrePoints = calculerNombrePointsEchelleArbitraire();
230
		VoteProtocole voteProtocole = image.getVotesProtocoles(
268
		VoteProtocole voteProtocole = image.getVotesProtocoles(
231
				protocole.getId()).get(
269
				protocole.getId()).get(
Line 244... Line 282...
244
				new VoteFleurVue());
282
				new VoteFleurVue());
245
		presenteurFleur.setNote(valeurVoteTotal);
283
		presenteurFleur.setNote(valeurVoteTotal);
246
		vue.setNoteGenerale(valeurVoteTotal);
284
		vue.setNoteGenerale(valeurVoteTotal);
247
		vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise);
285
		vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise);
248
		presenteurFleur.go(vue.getZoneFleur());
286
		presenteurFleur.go(vue.getZoneFleur());
-
 
287
		vue.rafraichir(voteUtilisateur, image.getVotesProtocoles(protocole.getId()).size(), nombrePoints,
-
 
288
					   moyenneArithmetique, mediane, occurrencesParNote, valeurVoteTotalPrecise);
-
 
289
	}
-
 
290
 
-
 
291
	public double calculerMedianeVotes() {
-
 
292
		double med = 0;
-
 
293
		// comparateur de votes (le bulldozer Java™ pour écraser une mouche)
-
 
294
		class Comparatisateur3000 implements Comparator<VoteProtocole> {
-
 
295
			@Override
-
 
296
			public int compare(VoteProtocole v1, VoteProtocole v2) {
-
 
297
				if (v1.getVote() > v2.getVote()) {
-
 
298
					return 1;
-
 
299
				} else if (v1.getVote() > v2.getVote()) {
-
 
300
					return -1;
-
 
301
				} else {
-
 
302
					return 0;
-
 
303
				}
-
 
304
			}
-
 
305
		}
249
		vue.rafraichir(voteUtilisateur,
306
		// conversion en liste triable
-
 
307
		List<VoteProtocole> liste = new ArrayList<VoteProtocole>(image.getVotesProtocoles(protocole.getId()).values());
-
 
308
		Collections.sort(liste, new Comparatisateur3000());
-
 
309
		int longueur = liste.size();
-
 
310
		if (longueur > 0) {
-
 
311
			if (longueur % 2 == 0) {
-
 
312
				// moyenne des éléments centraux
-
 
313
				med = (liste.get(longueur / 2 - 1).getVote() + liste.get(longueur / 2).getVote()) / 2;
-
 
314
			} else {
-
 
315
				// élément central
-
 
316
				med = liste.get((int) (longueur / 2)).getVote(); 
-
 
317
			}
-
 
318
		}
-
 
319
		return med;
-
 
320
	}
-
 
321
 
-
 
322
	// calcule la moyenne arithmétique
-
 
323
	public double calculerMoyenneVotes() {
-
 
324
		double valeurVote = 0;
-
 
325
		double nbVote = 0;
-
 
326
		for (Iterator<String> iterator = image
250
				image.getVotesProtocoles(protocole.getId()).size(), nombrePoints);
327
				.getVotesProtocoles(protocole.getId()).keySet().iterator(); iterator
-
 
328
				.hasNext();) {
-
 
329
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(
-
 
330
					protocole.getId()).get(iterator.next());
-
 
331
			valeurVote += (double) imageCelValidationData.getVote() / 5;
-
 
332
			nbVote++;
-
 
333
		}
-
 
334
 
-
 
335
		if (nbVote > 0) {
-
 
336
			valeurVote /= nbVote;
-
 
337
			valeurVote *= 5;
-
 
338
		}
-
 
339
 
-
 
340
		return valeurVote;
251
	}
341
	}
Line 252... Line 342...
252
 
342
 
253
	// Calcule une moyenne, où chaque note est pondérée par son nombre d'occurrences au carré.
343
	// Calcule une moyenne, où chaque note est pondérée par son nombre d'occurrences au carré.
254
	// voir http://www.tela-botanica.org/wikini/DevInformatiques/wakka.php?wiki=AppliDelCalculVotes
344
	// voir http://www.tela-botanica.org/wikini/DevInformatiques/wakka.php?wiki=AppliDelCalculVotes
Line 255... Line 345...
255
	public double calculerMoyennePondereeVotes() {
345
	public double calculerMoyennePondereeVotes() {
256
 
346
 
257
		double score = 0;
347
		double score = 0;
-
 
348
		double diviseur = 0;
258
		double diviseur = 0;
349
		int nbOccurrences;
Line 259... Line 350...
259
		int nbOccurrences;
350
		// mise à jour des occurrences par note, utile pour le panneau de détails
260
		HashMap<Integer,Integer> occurrencesParNote = new HashMap<Integer,Integer>();
351
		occurrencesParNote = new HashMap<Integer,Integer>();
261
 
352
 
262
		// rangement par note => occurrences
353
		// rangement par note => occurrences
Line 284... Line 375...
284
 
375
 
285
	// remplace chaque note par un nombre de points noté dans "echelle" afin de favoriser
376
	// remplace chaque note par un nombre de points noté dans "echelle" afin de favoriser
286
	// les note fortes (5 et 4), pour le défi photo notamment
377
	// les note fortes (5 et 4), pour le défi photo notamment
287
	public int calculerNombrePointsEchelleArbitraire() {
378
	public int calculerNombrePointsEchelleArbitraire() {
288
		int points = 0;
379
		int points = 0;
-
 
380
		//int[] echelle = {-1,0,1,4,20};
Line 289... Line 381...
289
		int[] echelle = {-1,0,1,4,20};
381
		int[] echelle = {1,10,100,1000,10000};
290
 
382
 
291
		for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) {
383
		for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) {
292
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef);
384
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef);