-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateMosaique.php
200 lines (148 loc) · 5.71 KB
/
updateMosaique.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
session_start();
$logged = false;
include "db.php";
if(isset($_SESSION["id"])){
$userId = $_SESSION["id"];
$logged = true;
updateUserLastSeen($_SESSION["id"]);
}
$nbIdsMarked = intval($_GET['nbIdsMarked']);
$nbIdsSpecial = intval($_GET['nbIdsSpecial']);
$nbIds = intval($_GET['nbIds']);
$type=$_GET['type'];
$marked = [];
$all = [];
$special = [];
$userScore = getScore($_SESSION["id"]);
for($i = 0 ; $i < $nbIds ; $i++){
$tmp = 'id'.$i;
array_push($all, intval($_GET[$tmp]));
}
for($i = 0 ; $i < $nbIdsMarked ; $i++){
$tmp = 'idMarked'.$i;
array_push($marked, intval($_GET[$tmp]));
}
for($i = 0 ; $i < $nbIdsSpecial ; $i++){
$tmp = 'idSpecial'.$i;
array_push($special, intval($_GET[$tmp]));
}
$wrong = [];
$notSure = [];
$allOk = true;
if(($userScore <= 100 || getUserErrorRatio($_SESSION["id"]) >= 0.1) && $_SESSION["privileges"] != 1){#TODO TEMPORAIRE
for($i = 0 ; $i < $nbIdsMarked ; $i++){//Images tagged true
if(getImageConsensus($marked[$i]) == 0){
$allOk = false;
array_push($wrong, $marked[$i]);
}
else if(getImageConsensus($marked[$i]) == -1){
array_push($notSure, $marked[$i]);
}
}
for($i = 0 ; $i < $nbIds ; $i++){
if(!in_array($all[$i], $marked) && !in_array($all[$i], $special)){//Images tagged false
if(getImageConsensus($all[$i]) == 1){
$allOk = false;
array_push($wrong, $all[$i]);
}
else if(getImageConsensus($all[$i]) == -1){
array_push($notSure, $all[$i]);
}
}
}
}
//If still training and not trusted user
if(($userScore <= 100 || getUserErrorRatio($_SESSION["id"]) >= 0.1) && $_SESSION["privileges"] != 1){
if($allOk){
$val = count($marked) + count($special);
updateUserScore($userId, $val);
}
}
else{//normal user
$val = count($marked) + count($special);
updateUserScore($userId, $val);
}
updateUserErrors($userId, count($wrong), count($all) - count($notSure) - count($special));
/* if($allOk){
* if($logged){
* $val = count($marked) + count($special);
* updateUserScore($userId, $val);
* updateUserTrainingData($userId, false);
*
* }
* }
* else{
* updateUserTrainingData($userId, true);
* }*/
if(($userScore > 100 && getUserErrorRatio($_SESSION["id"]) < 0.1) || $_SESSION["privileges"] == 1){
for($i = 0 ; $i < $nbIds ; $i++){
if(!in_array($all[$i], $marked) && !in_array($all[$i], $special)){
updateAnswer($all[$i], $userId, 0, $type);
}
}
for($i = 0 ; $i < $nbIdsMarked ; $i++){
updateAnswer($marked[$i], $userId, 1, $type);
}
for($i = 0 ; $i < $nbIdsSpecial ; $i++){
updateAnswer($special[$i], $userId, 2, $type);
}
if($logged){
$val = count($marked) + count($special);
updateUserScore($userId, $val);
}
}
if($_SESSION["privileges"] == 1){
echo '<div id="progressBar">';
$nbTagged = getNbImagesTaggedActive($type);
$nbImages = getNbEntriesActive($type);
$percentage = round(($nbTagged/$nbImages)*100, 2);
echo '<div id="bar" style="width:'.$percentage.'%">';
echo round(($nbTagged/$nbImages)*100, 2).'% Tagged';
echo '</div>';
echo '</div>';
}
echo '<h1>Mark the ';echo $type; echo '</h1>';
$userScore = getScore($_SESSION["id"]);
if(!$allOk)
echo "<h2> You made some mistakes </h2>";
else{
if((intval($userScore) < 100 || getUserErrorRatio($_SESSION["id"]) >= 0.1) && $_SESSION["privileges"] != 1)
echo '<p>You will be in the training mode until your error ratio is below 10% and you have tagged at least 100 images </p>';
}
echo '<div class="grid">';
if($allOk){
if((intval($userScore) > 100 && getUserErrorRatio($_SESSION["id"]) < 0.1) || $_SESSION["privileges"] == 1)
$ids = newGet16RandomIds($type, $_SESSION["privileges"]);
else
$ids = get16RandomIdsTuto($type);
for($i = 0 ; $i < 16 ; $i++){
$id = $ids[$i][0];
echo '<div class="element-item">';
echo '<img id=stop'; echo $i ; echo ' src="assets/stop.png" style="width:75%;position:absolute ; display:none ;pointer-events: none">';
echo '<img id=tick'; echo $i ; echo ' src="assets/ok.png" style="width:75% ;position:absolute ; display:none ;pointer-events: none">';
echo '<img imageId="';echo $id;echo '" value="0" id="';echo $i; echo '" class="tile'.$type.'" src="Images/';echo $type; echo '/' ; echo $id; echo '.png" onclick="markTile(';echo $i;echo ',';echo $id;echo ', false)" >';
echo '</div>';
}
echo '</div>';
echo '<div style="text-align:center; margin-bottom=20px; ">';
echo '<p><button id="cancel" style="float:left;" class="btn btn-danger" role="button" onclick="cancel(callBackReloadIsotope)" >CANCEL LAST TAGS</button></p>';
echo '</div>';
echo '<p><button id="yes" style="float:right;" class="btn btn-primary" role="button" onclick="updateTagger(callBackReloadIsotope, \'';echo $type ; echo '\'' ; echo ' )" >OK</button></p>';
}
else{
for($i = 0 ; $i < 16 ; $i++){
$id = $all[$i];
echo '<div class="element-item">';
echo '<img id=stop'; echo $i ; echo ' src="assets/stop.png" style="width:75%;position:absolute ; display:none ;pointer-events: none">';
echo '<img id=tick'; echo $i ; echo ' src="assets/ok.png" style="width:75% ;position:absolute ; display:none ;pointer-events: none">';
if(in_array($id, $wrong)){
echo '<img id=wrong'; echo $i ; echo ' src="assets/wrong.png" style="width:75% ;position:absolute ; ;pointer-events: none">';
}
echo '<img imageId="';echo $id;echo '" value="0" id="';echo $i; echo '" class="tile'.$type.'" src="Images/';echo $type; echo '/' ; echo $id; echo '.png" onclick="markTile(';echo $i;echo ',';echo $id;echo ', false)" >';
echo '</div>';
}
echo '</div>';
echo '<p><button id="restart" style="float:right;" class="btn btn-primary" role="button" onclick="location.reload();" >Restart</button></p>';
}
?>