Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1471 Rev 1566
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
 
2
 
3
import java.util.HashMap;
Line 3... Line 4...
3
import java.util.Iterator;
4
import java.util.Iterator;
4
 
5
 
5
import org.tela_botanica.del.client.cache.CacheClient;
6
import org.tela_botanica.del.client.cache.CacheClient;
Line 43... Line 44...
43
 
44
 
Line 44... Line 45...
44
		public void afficherNbVotes();
45
		public void afficherNbVotes();
Line -... Line 46...
-
 
46
 
-
 
47
		public void masquerNbVotes();
-
 
48
 
-
 
49
		public void afficherNbPoints();
45
 
50
 
Line 46... Line 51...
46
		public void masquerNbVotes();
51
		public void masquerNbPoints();
Line 47... Line 52...
47
 
52
 
Line 48... Line 53...
48
		public void reinitialiserVotes();
53
		public void reinitialiserVotes();
Line 78... Line 83...
78
	private Image image;
83
	private Image image;
Line 79... Line 84...
79
 
84
 
80
	private int valeurVoteDefaut = -1;
85
	private int valeurVoteDefaut = -1;
81
	private int valeurVoteUtilisateur = -1;
86
	private int valeurVoteUtilisateur = -1;
-
 
87
	private int valeurVoteTotal = 0;
82
	private int valeurVoteTotal = 0;
88
	private int nombrePoints = 0;
Line 83... Line 89...
83
	private double valeurVoteTotalPrecise = 0.0;
89
	private double valeurVoteTotalPrecise = 0.0;
84
 
90
 
Line 119... Line 125...
119
			public void onClick(ClickEvent event) {
125
			public void onClick(ClickEvent event) {
120
				valeurVoteUtilisateur = vue.getValeurVote();
126
				valeurVoteUtilisateur = vue.getValeurVote();
121
				enregistrerVote();
127
				enregistrerVote();
122
				vue.afficherBoutonAnnuler();
128
				vue.afficherBoutonAnnuler();
123
				vue.masquerNbVotes();
129
				vue.masquerNbVotes();
-
 
130
				vue.masquerNbPoints();
124
			}
131
			}
125
		});
132
		});
Line 126... Line 133...
126
 
133
 
127
		vue.getBoutonAnnuler().addClickHandler(new ClickHandler() {
134
		vue.getBoutonAnnuler().addClickHandler(new ClickHandler() {
128
			@Override
135
			@Override
129
			public void onClick(ClickEvent event) {
136
			public void onClick(ClickEvent event) {
130
				valeurVoteUtilisateur = valeurVoteDefaut;
137
				valeurVoteUtilisateur = valeurVoteDefaut;
131
				vue.masquerBoutonAnnuler();
138
				vue.masquerBoutonAnnuler();
132
				supprimerVote();
139
				supprimerVote();
-
 
140
				vue.afficherNbVotes();
133
				vue.afficherNbVotes();
141
				vue.afficherNbPoints();
134
				vue.reinitialiserVotes();
142
				vue.reinitialiserVotes();
135
			}
143
			}
Line 136... Line 144...
136
		});
144
		});
Line 214... Line 222...
214
		return vue;
222
		return vue;
215
	}
223
	}
Line 216... Line 224...
216
 
224
 
217
	private void rafraichirVue() {
225
	private void rafraichirVue() {
218
		valeurVoteTotal = calculerMoyenneVotesArrondie();
226
		valeurVoteTotal = calculerMoyenneVotesArrondie();
-
 
227
		//valeurVoteTotalPrecise = calculerMoyenneVotes();
-
 
228
		valeurVoteTotalPrecise = calculerMoyennePondereeVotes();
219
		valeurVoteTotalPrecise = calculerMoyenneVotes();
229
		nombrePoints = calculerNombrePointsEchelleArbitraire();
220
		VoteProtocole voteProtocole = image.getVotesProtocoles(
230
		VoteProtocole voteProtocole = image.getVotesProtocoles(
221
				protocole.getId()).get(
231
				protocole.getId()).get(
222
				CacheClient.getInstance().getUtilisateur().getId());
232
				CacheClient.getInstance().getUtilisateur().getId());
223
		int voteUtilisateur = 0;
233
		int voteUtilisateur = 0;
Line 235... Line 245...
235
		presenteurFleur.setNote(valeurVoteTotal);
245
		presenteurFleur.setNote(valeurVoteTotal);
236
		vue.setNoteGenerale(valeurVoteTotal);
246
		vue.setNoteGenerale(valeurVoteTotal);
237
		vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise);
247
		vue.setNoteGeneraleToolTip(valeurVoteTotalPrecise);
238
		presenteurFleur.go(vue.getZoneFleur());
248
		presenteurFleur.go(vue.getZoneFleur());
239
		vue.rafraichir(voteUtilisateur,
249
		vue.rafraichir(voteUtilisateur,
240
				image.getVotesProtocoles(protocole.getId()).size());
250
				image.getVotesProtocoles(protocole.getId()).size(), nombrePoints);
241
	}
251
	}
242
	
252
 
-
 
253
	// 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
243
	public double calculerMoyenneVotes() {
255
	public double calculerMoyennePondereeVotes() {
-
 
256
 
244
		double valeurVote = 0;
257
		double score = 0;
245
		double nbVote = 0;
258
		double diviseur = 0;
246
		for (Iterator<String> iterator = image
259
		int nbOccurrences;
247
				.getVotesProtocoles(protocole.getId()).keySet().iterator(); iterator
260
		HashMap<Integer,Integer> occurrencesParNote = new HashMap<Integer,Integer>();
-
 
261
 
248
				.hasNext();) {
262
		// rangement par note => occurrences
-
 
263
		for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) {
249
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(
264
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef);
-
 
265
			nbOccurrences = 1;
250
					protocole.getId()).get(iterator.next());
266
			if (occurrencesParNote.containsKey(imageCelValidationData.getVote())) {
251
			valeurVote += (double) imageCelValidationData.getVote() / 5;
267
				nbOccurrences = occurrencesParNote.get(imageCelValidationData.getVote()) + 1;
252
			nbVote++;
268
			}
-
 
269
			occurrencesParNote.put(imageCelValidationData.getVote(), nbOccurrences);
253
		}
270
		}
Line -... Line 271...
-
 
271
 
-
 
272
		// calcul pondéré
-
 
273
		for (Integer clef : occurrencesParNote.keySet()) {
-
 
274
			score += clef * occurrencesParNote.get(clef) * occurrencesParNote.get(clef);
-
 
275
			diviseur += occurrencesParNote.get(clef) * occurrencesParNote.get(clef);
-
 
276
		}
254
 
277
 
255
		if (nbVote > 0) {
278
		if (diviseur > 0) {
-
 
279
			score /= diviseur;
-
 
280
		}
-
 
281
 
-
 
282
		return score;
-
 
283
	}
-
 
284
 
-
 
285
	// 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
256
			valeurVote /= nbVote;
287
	public int calculerNombrePointsEchelleArbitraire() {
-
 
288
		int points = 0;
-
 
289
		int[] echelle = {-1,0,1,4,20};
-
 
290
 
-
 
291
		for (String clef : image.getVotesProtocoles(protocole.getId()).keySet()) {
-
 
292
			VoteProtocole imageCelValidationData = image.getVotesProtocoles(protocole.getId()).get(clef);
257
			valeurVote *= 5;
293
			points += echelle[imageCelValidationData.getVote() - 1];
Line -... Line 294...
-
 
294
		}
258
		}
295
 
259
 
296
		// @TODO ramener les votes négatifs à 0 pour ne pas insulter les contributeurs ?
Line 260... Line 297...
260
		return valeurVote;
297
		return points;
261
	}
298
	}
-
 
299
 
262
 
300
	public int calculerMoyenneVotesArrondie() {
263
	public int calculerMoyenneVotesArrondie() {
301
		//double valeurVote = calculerMoyenneVotes();
264
		double valeurVote = calculerMoyenneVotes();
302
		double valeurVote = calculerMoyennePondereeVotes();