Skip to content

Instantly share code, notes, and snippets.

@billy3321
Created July 3, 2012 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billy3321/3038157 to your computer and use it in GitHub Desktop.
Save billy3321/3038157 to your computer and use it in GitHub Desktop.
erep battle stats collection
//Author: Billy Zhe-Wei Lin
//Use for get erep battle stats
//Licence: BSD
var battleId = '30140';
$j.getJSON("/en/military/battle-stats/"+ battleId +"/2", function(data){
console.log(data);
var allStats = data.stats.current;
var div1 = {};
var div2 = {};
var div3 = {};
var div4 = {};
var divAll = {};
var country1 = '';
var country2 = '';
console.log(allStats);
for (var i in allStats){
for (var j in allStats[i][1]){
if(country1 === ''){
country1 = j;
}else{
country2 = j;
}
if(div1[j] == undefined){
div1[j] = 0;
}
for(var k in allStats[i][1][j]){
div1[j] += parseInt(allStats[i][1][j][k]['damage']);
}
}
for (var j in allStats[i][2]){
if(div2[j] == undefined){
div2[j] = 0;
}
for(var k in allStats[i][2][j]){
div2[j] += parseInt(allStats[i][2][j][k]['damage']);
}
}
for (var j in allStats[i][3]){
if(div3[j] == undefined){
div3[j] = 0;
}
for(var k in allStats[i][3][j]){
div3[j] += parseInt(allStats[i][3][j][k]['damage']);
}
}
for (var j in allStats[i][4]){
if(div4[j] == undefined){
div4[j] = 0;
}
for(var k in allStats[i][4][j]){
div4[j] += parseInt(allStats[i][4][j][k]['damage']);
}
}
}
console.log(div1);
console.log(div2);
console.log(div3);
console.log(div4);
var html = '';
var str = '';
for(var i in div1){
divAll[i] = div1[i] + div2[i] + div3[i] + div4[i];
}
str += 'country:' + country1 + ',' + country2 + '\n';
str += 'div 1:' + div1[country1] + ',' + div1[country2] + '\n';
str += 'div 2:' + div2[country1] + ',' + div2[country2] + '\n';
str += 'div 3:' + div3[country1] + ',' + div3[country2] + '\n';
str += 'div 4:' + div4[country1] + ',' + div4[country2] + '\n';
str += 'div all:' + divAll[country1] + ',' + divAll[country2] + '\n';
html += '<table border="1"><tr><th></th><th>' + country1 + '</th><th>' + country2 + '</th></tr>';
html += '<tr><td>div1</td><td>' + div1[country1] + '</td><td>' + div1[country2] + '</td></tr>';
html += '<tr><td>div2</td><td>' + div2[country1] + '</td><td>' + div2[country2] + '</td></tr>';
html += '<tr><td>div3</td><td>' + div3[country1] + '</td><td>' + div3[country2] + '</td></tr>';
html += '<tr><td>div4</td><td>' + div4[country1] + '</td><td>' + div4[country2] + '</td></tr>';
html += '<tr><td>div all</td><td>' + divAll[country1] + '</td><td>' + divAll[country2] + '</td></tr>';
html += '</table>';
//alert(html);
alert(str);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment