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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
var sqmod_test = {
init:function(that,j_page){
var pro_tab = new class_sqmod_test_pro_tab(that);
that.export_urlchange = function(direct){
var _in = function(){
that.fadein(j_page);
that.addtab('pro',pro_tab);
index.addtab('pro','/toj/sq/' + that.sqid + '/','題目');
_change();
};
var _out = function(){
that.fadeout(j_page);
index.emptytab();
that.tab_urlchange(null);
};
var _change = function(){
var tabname;
tabname = common.geturlpart()[2];
if(!(tabname in that.tab_list)){
tabname = 'pro';
common.replaceurl('/toj/sq/' + that.sqid + '/pro/');
}
that.tab_urlchange(tabname);
}
if(direct == 'in'){
_in();
}else if(direct == 'out'){
_out();
}else if(direct == 'same'){
_change();
}
}
}
};
var class_sqmod_test_pro_tab = function(paobj){
var that = this;
var j_tab = $('#index_page > [page="sq"] > [tab="pro"]');
var promap = null;
var pro_listset = function(j_item,proo){
var i;
var bscore;
var fscore;
var ratio;
var j_a;
var j_team;
if(proo != null){
j_item.attr('proid',proo.proid);
j_item.find('td.no').text(proo.prono);
j_a = j_item.find('td.name > a.link');
j_a.attr('href','/toj/pro/' + proo.proid + '/');
j_a.text(proo.proname);
bscore = proo.bscore;
fscore = proo.full_score;
j_item.find('td.bscore').text(bscore + ' / ' + fscore);
if(proo.tried == false){
j_item.css('border-color','#1C1C1C');
}else{
ratio = bscore / fscore;
if(ratio < 0.6){
j_item.css('border-color','#FF0000');
}else if(ratio < 0.8){
j_item.css('border-color','#00FF00');
}else if(ratio < 1){
j_item.css('border-color','#FFFF00');
}else{
j_item.css('border-color','#FFFFFF');
}
}
j_team = j_item.find('td.team');
j_team.hide();
for(i = 0;i < proo.tscore.length;i++){
$(j_team[i]).text(proo.tscore[i]);
$(j_team[i]).show();
}
}
};
var pro_listnew = function(proo){
var j_item;
j_item = $('<tr class="item"><td class="no"></td><td class="name"><a class="link"></a></td><td class="bscore"></td><td class="team"></td><td class="team"></td><td class="team"></td><td class="team"></td></tr>');
pro_listset(j_item,proo);
return j_item;
};
var prog_set = function(j_progbox,baseline,totalscore){
var off;
var ratio;
var j_prog;
off = 0;
ratio = baseline.pass_score * 100 / baseline.total_score;
j_prog = j_progbox.find('div.pass');
j_prog.css('width',ratio + '%');
j_prog.html(baseline.pass_score + ' ');
off += ratio;
ratio = (baseline.good_score - baseline.pass_score) * 100 / baseline.total_score;
j_prog = j_progbox.find('div.good');
j_prog.css('left',off + '%');
j_prog.css('width',ratio + '%');
j_prog.html(baseline.good_score + ' ');
off += ratio;
ratio = 100 - off;
j_prog = j_progbox.find('div.total');
j_prog.css('left',off + '%');
j_prog.css('width',ratio + '%');
j_prog.html(baseline.total_score + ' ');
ratio = totalscore * 100 / baseline.total_score;
j_prog = j_progbox.find('div.prog');
j_prog.css('width',ratio + '%');
j_prog.html(totalscore + ' ');
if(totalscore < baseline.pass_score){
ratio = totalscore / baseline.pass_score;
j_prog.css('background-color','rgba(255,' + Math.round(64 * ratio) + ',0,0.8)');
}else if(totalscore < baseline.good_score){
ratio = (totalscore - baseline.pass_score) / (baseline.good_score - baseline.pass_score);
j_prog.css('background-color','rgba(' + Math.round(128 * ratio) + ',255,0,0.8)');
}else if(totalscore < baseline.total_score){
ratio = (totalscore - baseline.good_score) / (baseline.total_score - baseline.good_score);
j_prog.css('background-color','rgba(255,255,' + Math.round(128 * ratio) + ',0.8)');
}else{
j_prog.css('background-color','rgba(255,255,255,0.8)');
}
}
var prostat_refresh = function(){
if(refresh_flag == false){
return;
}
$.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_user_stat','data':JSON.stringify({'sqid':paobj.sqid,'display_team':true})},function(res){
var i;
var j;
var reto;
var team;
var teamo;
var prostat;
var prostato;
var proo;
var user_total;
var team_total;
var maxscore;
var j_list;
var j_team;
var j_a;
var j_item;
if(res[0] != 'E'){
reto = JSON.parse(res);
team = reto.team;
prostat = reto.prostat;
j_list = j_tab.find('table.prolist');
if(team != undefined){
j_team = j_list.find('th.team');
for(i = 0;i < team.length;i++){
teamo = team[i];
j_a = j_team.find('a.link');
$(j_a[i]).attr('href','/toj/user/' + teamo.uid + '/')
$(j_a[i]).text(teamo.name);
for(j = 0;j < teamo.prostat.length;j++){
if(teamo.prostat[j].tried == true){
promap[teamo.prostat[j].proid].tscore[i] = teamo.prostat[j].best_score;
}else{
promap[teamo.prostat[j].proid].tscore[i] = 0;
}
}
j_team.show();
}
j_tab.find('table.stat tr.team_prog').show();
}
user_total = 0;
team_total = 0;
for(i = 0;i < prostat.length;i++){
prostato = prostat[i];
proo = promap[prostato.proid];
proo.bscore = prostato.best_score;
proo.tried = prostato.tried;
user_total += prostato.best_score;
j_item = j_list.find('[proid = "' + prostato.proid + '"]');
if(j_item.length > 0){
pro_listset(j_item,proo);
}
maxscore = proo.bscore;
for(j = 0;j < proo.tscore.length;j++){
maxscore = Math.max(maxscore,proo.tscore[j]);
}
team_total += maxscore;
}
prog_set(j_tab.find('table.stat div.user_prog'),reto.base_line,user_total);
prog_set(j_tab.find('table.stat div.team_prog'),reto.team_base_line,team_total);
setTimeout(prostat_refresh,2000);
}
});
};
that.__super(paobj);
that.urlchange = function(direct){
if(direct == 'in'){
that.fadein(j_tab);
refresh_flag = true;
$.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_prolist','data':JSON.stringify({'sqid':paobj.sqid})},function(res){
var i;
var reto;
var proo;
var j_list;
var j_item;
if(res[0] != 'E'){
reto = JSON.parse(res);
promap = new Array;
j_list = j_tab.find('table.prolist');
for(i = 0;i < reto.length;i++){
proo = reto[i];
proo.bscore = 0;
proo.tscore = new Array;
proo.tried = false;
if(proo.hidden == false){
promap[proo.proid] = proo;
j_item = pro_listnew(proo);
j_list.append(j_item);
}
}
prostat_refresh();
}
});
}else if(direct == 'out'){
that.fadeout(j_tab);
refresh_flag = false;
}
};
}; __extend(class_sqmod_test_pro_tab,class_common_tab);
|