Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boss display #33

Merged
merged 1 commit into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
boss display
  • Loading branch information
s-vivien committed Apr 27, 2019
commit baeb8cd0ed652b30630b6138530bfbe89e1c7386
85 changes: 77 additions & 8 deletions cgstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var optimizations = ["thor-codesize", "paranoid-codesize", "temperatures-codesiz

var app = express();

// *****************************

app.get('/multi-list', function (req, res) {

// First get the global puzzle list
Expand Down Expand Up @@ -225,13 +227,30 @@ app.get('/search*', function(req, res) {
return;
}

res.type('json').set({
'Access-Control-Allow-Origin' : 'http://cgstats.magusgeek.com'
}).send(JSON.stringify({
player : user,
stats : compileStats(body.success, user.codingamer.userId, users, countDraws),
mode : 'multi'
})).end();
var bossGameId = -1;
for (var i in body.success) {
if (bossGameId != -1) break;
var result = body.success[i];

if (result.done && result.players.length >= 2) {
for (var key in result.players) {
if (result.players[key].userId == 0) {
bossGameId = result.gameId;
break;
}
}
}
}

addBossInUsers(users, bossGameId).then(r => {
res.type('json').set({
'Access-Control-Allow-Origin' : 'http://cgstats.magusgeek.com'
}).send(JSON.stringify({
player : user,
stats : compileStats(body.success, user.codingamer.userId, users, countDraws),
mode : 'multi'
})).end();
});
});
});
}
Expand Down Expand Up @@ -266,6 +285,51 @@ function getStats(resource, parameters) {
});
}

function addBossInUsers(users, gameId) {
return new Promise(function (resolve, reject) {
if (gameId == -1) resolve();
request({
url: 'https://www.codingame.com/services/gameResultRemoteService/findByGameId',
method: 'POST',
json: true,
body: [gameId, null]
}, function (error, response, body) {

if (error) { reject(); }
if (!body || !body.success) { reject("invalid response from server"); }

var bossAgent = null;
for (var key in body.success.agents) {
if (body.success.agents[key].hasOwnProperty('arenaboss')) {
bossAgent = body.success.agents[key];
break;
}
}

if (bossAgent == null) {
reject("cannot find boss data !");
}

users[0] = {
isBoss : true,
league : bossAgent.arenaboss.league,
score : +bossAgent.score.toFixed(2),
pseudo : bossAgent.arenaboss.nickname,
draw : 0,
lose : 0,
beaten : 0,
total : 0,
winrate : 0,
winrateErrorUp : 0,
winrateErrorDown : 0,
winrateErrorRange : 0
}

resolve();
});
});
}

function compileStats(data, myIdentifier, users, countDraws) {

var stats = [[], [], []];
Expand Down Expand Up @@ -364,9 +428,14 @@ function compileStats(data, myIdentifier, users, countDraws) {

users[myIdentifier].highlight = true;

var usersArray = _.values(users);
for (user of usersArray) {
user.scoreKey = user.score + user.league.divisionIndex * 100;
}

var result = {
stats: stats,
users: _.values(users)
users: usersArray
};

return result;
Expand Down
5 changes: 2 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ angular.module('cgstats', ['ui.router'])
$scope.loading = true;

$http.get(url + '/search?game=' + encodeURIComponent($stateParams.game.trim()) + '&player=' + encodeURIComponent($stateParams.player.trim()) + ($stateParams.countDraws ? ('&countDraws=' + $stateParams.countDraws) : ''))

.then(function (response) {

$scope.fail = false;
$scope.date = moment().format('HH:mm:ss');

$scope.sortType = 'rank';
$scope.sortReverse = false;
$scope.sortType = 'scoreKey';
$scope.sortReverse = true;

$scope.player = response.data.player;
$scope.stats = response.data.stats.stats || response.data.stats;
Expand Down
3 changes: 3 additions & 0 deletions templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@
<div ng-if="line.codingamer.avatar" class="avatar">
<img ng-src="https://static.codingame.com/servlet/fileservlet?id={{ line.codingamer.avatar }}&format=navigation_avatar" />
</div>
<div ng-if="line.isBoss" class="avatar">
<img ng-src="https://static.codingame.com/assets/league_boss_wood.1a96cb17.png" />
</div>
<a ui-sref="app.stats({ game: game, player: line.pseudo })">{{ line.pseudo }}</a>
</td>
<td>
Expand Down