1: private void cmdPredizione_Click(object sender, EventArgs e) {
2:
3: stopwatch.Start();
4:
5: console.Text = "inizio predizione ...";
6:
7: // Query per vedere se ho preso i valori giusti
8: // SELECT * FROM sql960766_3.reti_voti where userid IN(172, 36, 161, 122, 12, 76, 115, 22, 10, 1, 67, 164, 61) and filmid = 1;
9:
10: List<User> LeaderUser = loadSuperUserV1();
11: List<Dictionary<int, int>> LeaderUserVote = new List<Dictionary<int, int>>();
12:
13: for (int i = 0; i < LeaderUser.Count; i++) {
14: LeaderUserVote.Add(GetUserVote(LeaderUser[i].userid));
15: }
16:
17: double totalScore = 0;
18: double countTotalMatch = 0;
19: int countUserNotDone = 0;
20:
21: console.Text = LoadAllUser();
22: console.AppendText(Environment.NewLine);
23: console.AppendText("Abbiamo " + users.Count + " utenti da analizzare." + Environment.NewLine);
24: console.AppendText("stopwatch " + Stopwatch.IsHighResolution + Environment.NewLine);
25:
26: for (int countUser = 0; countUser < users.Count; countUser++) {
27:
28: int userIDBestFriend = GetUserIDBestFriend(users[countUser].userid);
29:
30: //LeaderUser.Add(new User(userIDBestFriend, "UserIDBestFriend", 0, "Custom", 0, 1, 0));
31: //LeaderUserVote.Add(GetUserVote(userIDBestFriend));
32:
33: Dictionary <int, int> user = GetUserVote(users[countUser].userid);
34:
35: /*
36: Faccio un setup di 10 voti dove vedo l'utente quando è vicino agli altri utenti tipo....
37: poi inizio la predizione e vedo quante volte sbaglio
38: */
39:
40: int[] matrixScore = new int[nRegion];
41:
42: int nSetupMach = 10; // Numero di giri prima che l'algoritmo di predizione inizi a funzionare ...
43:
44: double nMatch = 0;
45: double RightPrediction = 0;
46:
47: for (int idfilm = 1; idfilm <= 50; idfilm++) {
48:
49: // Carico nella matrice i voti dei vari gruppi ...
50: int[] matrixUserScore = SetMatrixValue(LeaderUserVote, idfilm);
51:
52: if (user.ContainsKey(idfilm) == true) {
53:
54: int UserVote = user[idfilm];
55:
56: // Provo ad indovinare se riesco a "predirre" cosa abbia votato l'utente
57: // Ovvero guardo l'utente "leader" che ha piu' punti e suggerisco il suo voto
58: if ((nSetupMach <= 0) && (UserVote != 0)) {
59:
60: int voteSuggest = GetVoteSuggestBySuperUser(matrixUserScore, matrixScore);
61: if (UserVote == voteSuggest) {
62: RightPrediction++;
63: }
64: else {
65: double potenza = 2;
66: double delta = UserVote - voteSuggest;
67: double deltaPower = Math.Pow(delta, potenza);
68: if (deltaPower == 1) {
69: RightPrediction = RightPrediction + 0.5;
70: }
71: }
72: nMatch++;
73: //console.AppendText(users[countUser].userid + "." +idfilm + ") UserVote" + UserVote + " Vs voteSuggest:" + voteSuggest + ". Per adesso " + RightPrediction + "/" + nMatch + " successi" + Environment.NewLine);
74: }
75: else {
76: nSetupMach += -1;
77: }
78:
79: if (UserVote != 0) {
80: // Confronto il voto dell'utente con tutti i vari "leader" user
81: // Aggiungo il punto a chi ha il punteggio uguale
82: for (int i = 0; i < matrixUserScore.Length; i++) {
83: if (UserVote == matrixUserScore[i]) {
84: matrixScore[i] = matrixScore[i] + 1;
85: }
86: }
87: }
88: }
89: }
90:
91: double score = (RightPrediction / nMatch) * 100;
92: if (double.IsNaN(RightPrediction / nMatch) == false) {
93: totalScore += (RightPrediction / nMatch);
94: countTotalMatch++;
95: } else {
96: countUserNotDone++;
97: }
98:
99: //LeaderUser.RemoveAt(LeaderUser.Count - 1);
100: //LeaderUserVote.RemoveAt(LeaderUserVote.Count - 1);
101:
102: }
103:
104:
105: double mathTotalScore = (totalScore / countTotalMatch) * 100;
106: console.AppendText("Il risultato complessivo dell'algoritmo è stato del " + mathTotalScore + "%. Gli utente non analizzati sono stati " + countUserNotDone + Environment.NewLine);
107: console.AppendText("Time elapsed: " + stopwatch.Elapsed + Environment.NewLine + Environment.NewLine);
108: }