이재용

callback 으로 값 전달 및 승률 출력 형식 변경

1 const searchGameInfo = require('../api/api'); 1 const searchGameInfo = require('../api/api');
2 var result = {}; 2 var result = {};
3 -var urlencode=require("urlencode") 3 +var urlencode=require("urlencode");
4 +const search = require('../api/api');
4 var local_puuid; 5 var local_puuid;
5 - 6 +var need_data;
6 -result.userInfo = function(name) { 7 +result.userInfo = function(name,callback) {
7 var encode_name=urlencode(name) 8 var encode_name=urlencode(name)
8 searchGameInfo.getPuuid(encode_name).then(puuid => { 9 searchGameInfo.getPuuid(encode_name).then(puuid => {
9 local_puuid=puuid 10 local_puuid=puuid
...@@ -62,7 +63,7 @@ result.userInfo = function(name) { ...@@ -62,7 +63,7 @@ result.userInfo = function(name) {
62 63
63 } 64 }
64 65
65 - var result={} 66 + var result=[]
66 rest_dic=all_map_count 67 rest_dic=all_map_count
67 for (key in all_map_count) 68 for (key in all_map_count)
68 { 69 {
...@@ -70,7 +71,9 @@ result.userInfo = function(name) { ...@@ -70,7 +71,9 @@ result.userInfo = function(name) {
70 { 71 {
71 if(key==key2) 72 if(key==key2)
72 { 73 {
73 - console.log(key+" 승률: "+top_map_count[key]/all_map_count[key]+" 판 수: ("+top_map_count[key]+"/"+all_map_count[key]+")") 74 + a=key+" 승률: "+(top_map_count[key]/all_map_count[key]).toFixed(3)+" 판 수: ("+top_map_count[key]+"/"+all_map_count[key]+")"
75 + result.push(a)
76 +
74 delete rest_dic[key] 77 delete rest_dic[key]
75 78
76 } 79 }
...@@ -78,10 +81,13 @@ result.userInfo = function(name) { ...@@ -78,10 +81,13 @@ result.userInfo = function(name) {
78 } 81 }
79 for (key in rest_dic) 82 for (key in rest_dic)
80 { 83 {
81 - console.log(key+" 승률: 0 판 수: (0/"+all_map_count[key]+")") 84 + b=key+" 승률: 0 판 수: (0/"+all_map_count[key]+")"
85 + result.push(b)
82 } 86 }
83 87
88 +
89 + callback(result);
84 }); 90 });
85 - //res.end("done"); 91 +
86 }; 92 };
87 module.exports = result; 93 module.exports = result;
...\ No newline at end of file ...\ No newline at end of file
......