search_result.ejs
10.1 KB
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="search_result.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<script language="JavaScript">
function level(){
return "metadata/level/" + '<%- level %>' + ".png";
}
function embl(){
var rand=Math.floor(Math.random()*8+1);
return "background-image:url('metadata/emblem/emblem"+rand+".png')";
}
function get_jsondata(id, kind){
var str;
var local_url='metadata/'+kind+'.json';
function save(data){
str=data;
}
$.ajaxSetup({
async: false
});
$.getJSON(local_url,function(json){
var kind_json;
if(kind=="kart"){
kind_json=json.kart;
}
else if(kind=="track"){
kind_json=json.track;
}
else if(kind=="character"){
kind_json=json.character;
}
for (var i = 0; i < kind_json.length; i++) {
if (kind_json[i]['id'] == id) {
save(kind_json[i]['name']);
break;
}
}
});
return str;
}
</script>
<body>
<div id="div">
<div id="emblem">
<script>document.getElementById("emblem").style = embl()</script>
</div>
<div id="name">
<text id="nick"> <%- name %> </text>
</div>
<img id="s_home" src="metadata/image/search_image.png">
</div>
<div id="resu">
<div id="most">
<text id="title">SAVE</text>
<canvas id="myChart2"width="350" height="200"></canvas>
<text id="title"><br>RANKING GRAPE</text>
<canvas id="myChart"width="350" height="200"></canvas>
<text id="title"><br>MOST KART</text>
<table id="table_most" border="1">
<colgroup>
<col width="10%"/>
<col width="30%"/>
<col width="10%"/>
<col width="10%"/>
</colgroup>
<tr>
<td>카트</td>
<td>이름</td>
<td>save</td>
<td>판 수</td>
</tr>
</table>
</div>
<div id="div1">
<table id="table">
<colgroup>
<col width="100px"/>
<col width="100px"/>
<col width="150px"/>
<col width="200px"/>
<col width="100px"/>
<col width="100px"/>
</colgroup>
</table>
</div>
</div>
</body>
<script>
var body = '<%- body -%>';
var most_kart=[];
var rank_grape=[];
var retire=0;
var match = JSON.parse(body);
var Len = match.matches[0].matches.length;
const div_target=document.querySelector('#table');
for(var i=1; i<=Len; i++){
var obj=document.createElement('tr');
obj.id="table_row";
var win = match.matches[0].matches[i-1].player.matchWin;
var tId = match.matches[0].matches[i-1].trackId;
var character=match.matches[0].matches[i-1].character;
var kartId = match.matches[0].matches[i-1].player.kart;
most_kart.push(kartId);
var mrank = match.matches[0].matches[i-1].player.matchRank;
var players = match.matches[0].matches[i-1].playerCount;
var stime = new Date(match.matches[0].matches[i-1].startTime.split('T')[0] + " " + match.matches[0].matches[i-1].startTime.split('T')[1]);
var etime = new Date(match.matches[0].matches[i-1].endTime.split('T')[0] + " " + match.matches[0].matches[i-1].endTime.split('T')[1]);
var diff = etime - stime
var minute = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
if(minute<10)
minute='0'+minute;
var second = Math.floor((diff % (1000 * 60)) / 1000);
if(second<10)
second='0'+second;
var ranking = mrank + "/" + players
var diff_time=minute + " : " + second;
var now_time=new Date();
var diff_day=Math.ceil((now_time-etime) / (1000*60*60*24))-1+"일 전";
if(win=="0"){
win="패";
obj.style="background: white";
}
else if (win =="1"){
win="승";
obj.style="background: rgb(163,207,236)";
}
else{
win="탈주"
}
if (mrank == "99" || win=="탈주") {
ranking = "retire";
retire+=1;
diff_time = "retire";
obj.style="background: rgb(226,182,179)";
rank_grape.push(8);
}
else{
rank_grape.push(parseInt(mrank));
}
if(diff_day=="0일 전"){
diff_day=Math.ceil((now_time-etime)/1000/60/60)-1;
diff_day+="시간 전"
}
div_target.append(obj);
var arr=["개인전","#"+ranking,kartId,tId,character,diff_time,ranking];
for(var j=1; j<=6; j++){
var sobj=document.createElement('td');
if(j==1){
var tet1=document.createElement('text');
var tet2=document.createElement('text');
var br=document.createElement('br');
tet1.innerText=arr[j-1];
tet2.innerText=diff_day;
sobj.append(tet1);
sobj.append(br);
sobj.append(tet2);
}
else if(j==2){
var tet1=document.createElement('text');
tet1.innerText=arr[j-1];
tet1.id="text_ranking";
sobj.append(tet1);
}
else if(j==3){
var img=document.createElement('img');
var tet1=document.createElement('text');
var str=get_jsondata(arr[j-1],"kart");
var br=document.createElement('br');
img.id="IMG";
if(str==null){
tet1.innerText="조회 불가능"
img.src="metadata/image/empty.png";
}
else{
tet1.innerText=str;
img.src="metadata/kart/"+arr[j-1]+".png";
}
sobj.append(img);
sobj.append(br);
sobj.append(tet1);
}
else if(j==4){
var img=document.createElement('img');
var tet1=document.createElement('text');
var str=get_jsondata(arr[j-1],"track");
tet1.id="IMG2_TEXT";
var br=document.createElement('br');
img.id="IMG2";
if(str==null || str[1]=='r'){
tet1.innerText="조회 불가능"
img.src="metadata/image/empty.png";
}
else{
tet1.innerText=str;
img.src="metadata/track/"+arr[j-1]+".png";
}
sobj.append(img);
sobj.append(br);
sobj.append(tet1);
}
else if(j==5){
var img=document.createElement('img');
var str=get_jsondata(arr[j-1],"character");
var tet1=document.createElement('text');
var br=document.createElement('br');
img.id="IMG4";
img.src="metadata/character/"+arr[j-1]+".png";
tet1.innerText=str;
sobj.append(img);
sobj.append(br);
sobj.append(tet1);
}
else{
sobj.innerText=arr[j-1];
}
obj.append(sobj);
}
}
/////////////most카트라이더 부분/////////////////////////
var count=[];
for(var i=0; i<Len; i++){
var item=most_kart[i];
count[i]=0;
for(var j=0; j<Len; j++){
if(item==most_kart[j]){
count[i]+=1;
}
}
}
var max=0;
var index=0; //most_kart 배열에서 어디부분이 모스트인지 알려주는 index
for(var i=0; i<Len; i++){
if(max<count[i]){
max=count[i];
index=i;
}
}
const most_div=document.querySelector('#table_most');
var obj=document.createElement('tr');
most_div.append(obj);
/*save는 retire횟수 따져주는 것*/
var temp_arr=[most_kart[index],get_jsondata(most_kart[index],'kart'),(Len-retire)*10+"%",max];
for(var i=0; i<4; i++){
var sobj=document.createElement('td');
if(i==0){
var img=document.createElement('img');
img.id="IMG3";
if(temp_arr[1]==null){
temp_arr[1]="조회 불가능"
img.src="metadata/image/empty.png";
}
else{
img.src="metadata/kart/"+temp_arr[i]+".png";
}
sobj.append(img);
}
else{
sobj.innerText=temp_arr[i];
}
obj.append(sobj);
}
//sebo부분//////////////////////////////////////////////////////////
rank_grape=rank_grape.reverse();
var options={
type: 'line',
data:{
labels: ['', '', '', '', '', '','','','',''],
datasets: [{
label: 'rank',
data: rank_grape,
backgroundColor:[
'rgba(0, 0, 0, 0)'
],
borderColor:[
'rgba(54, 162, 235, 1)'
],
borderWidth: 2
}]
},
options:{
responsive:false,
scales:{
xAxes:[{
gridLines:{
display:false
}
}],
yAxes: [{
ticks:{
reverse:true,
min:1,
max:8,
stepSize:1
}
}]
}
}
};
var ctx=document.getElementById('myChart').getContext('2d');
new Chart(ctx,options);
///////////////////////
var options2={
type: 'doughnut',
data:{
labels:['retire','save'],
datasets: [{
data: [retire,Len-retire],
backgroundColor:[
'rgba(255, 100, 100, 1)',
'rgba(54, 162, 235, 1)'
],
}]
},
/* options:{
responsive:false,
scales:{
xAxes: [{
gridLines:{
display:false
},
ticks:{
display:false
}
}],
yAxes: [{
gridLines:{
display:false
},
ticks:{
display:false
}
}]
}
}*/
};
var ctx2=document.getElementById('myChart2').getContext('2d');
new Chart(ctx2,options2);
</script>
</html>