이재용

api 로 가져온 데이터를 실제 사용하는 곳

1 +const searchGameInfo = require('../api/api');
2 +var result = {};
3 +var urlencode=require("urlencode")
4 +var local_puuid;
5 +
6 +result.userInfo = function(name) {
7 + var encode_name=urlencode(name)
8 + searchGameInfo.getPuuid(encode_name).then(puuid => {
9 + local_puuid=puuid
10 + return searchGameInfo.getGamename(puuid);
11 + }).then(gamenames => {
12 + //console.log(gamenames);
13 + async function loop(gamenames) {
14 + let gametraits = []
15 + for(var game_name_Index = 0 ; game_name_Index < gamenames.length ; game_name_Index++ ){
16 + await searchGameInfo.getGametrait(gamenames[game_name_Index]).then(gametrait =>{
17 + gametraits.push(gametrait);
18 + })
19 + }
20 + return gametraits;
21 + }
22 + return loop(gamenames);
23 + }).then(data => {
24 + var top_game_map=[]
25 + var all_game_map=[]
26 + for (var data_index=0;data_index<data.length;data_index++)
27 + {
28 + for(var participants_num=0;participants_num<8;participants_num++)
29 + {
30 +
31 + if(data[data_index].participants[participants_num].puuid==local_puuid&&data[data_index].participants[participants_num].placement<=4)
32 + {
33 + top_game_map.push(data[data_index].game_variation)
34 + }
35 + }
36 + all_game_map.push(data[data_index].game_variation)
37 +
38 +
39 + }
40 + var all_map_count = {};
41 + var top_map_count = {};
42 + for (var i = 0; i < all_game_map.length; ++i)
43 + {
44 +
45 + if (!all_map_count[all_game_map[i]])
46 + {
47 + all_map_count[all_game_map[i]] = 0;
48 + }
49 +
50 + ++all_map_count[all_game_map[i]];
51 +
52 + }
53 + for (var i = 0; i < top_game_map.length; ++i)
54 + {
55 +
56 + if (!top_map_count[top_game_map[i]])
57 + {
58 + top_map_count[top_game_map[i]] = 0;
59 + }
60 +
61 + ++top_map_count[top_game_map[i]];
62 +
63 + }
64 +
65 + var result={}
66 + rest_dic=all_map_count
67 + for (key in all_map_count)
68 + {
69 + for(key2 in top_map_count)
70 + {
71 + if(key==key2)
72 + {
73 + console.log(key+" 승률: "+top_map_count[key]/all_map_count[key]+" 판 수: ("+top_map_count[key]+"/"+all_map_count[key]+")")
74 + delete rest_dic[key]
75 +
76 + }
77 + }
78 + }
79 + for (key in rest_dic)
80 + {
81 + console.log(key+" 승률: 0 판 수: (0/"+all_map_count[key]+")")
82 + }
83 +
84 + });
85 + //res.end("done");
86 +};
87 +module.exports = result;
...\ No newline at end of file ...\ No newline at end of file