-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (35 loc) · 1.47 KB
/
Copy pathindex.ts
File metadata and controls
44 lines (35 loc) · 1.47 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
import express from 'express';
import * as teamsJson from './example-responses/teams.json';
import * as fs from 'fs';
import { ILeaderboardJson } from './update-leaderboard.ts';
const app = express();
const port = 80;
app.get('/', async(req, res) => {
res.send(`<p>${await getScoreboard()}</p>`);
})
app.listen(port, () => {
console.log(`The application is listening on port ${port}!`);
})
async function getScoreboard() {
let response: string = ""
let leaderboardFile = fs.readFileSync('leaderboard.json', 'utf8')
let leaderboardJson = JSON.parse(leaderboardFile) as ILeaderboardJson
teamsJson.teams.forEach(team => {
team.players.forEach(player => {
player.position = leaderboardJson.leaderboard.find(i => i.id === player.id)?.position || 999
});
team.players.sort((a, b) => a.position - b.position)
team.team_score = team.players.slice(0, 3).reduce((a, c) => a + c.position, 0);
});
teamsJson.teams.sort((a, b) => a.team_score - b.team_score)
response += `<br>`
teamsJson.teams.forEach(team => {
response += `${team.manager}: ${team.team_score}<br>`
response += `----------------------------------<br>`
team.players.forEach(player => {
player.position >= 54 ? response += `${player.first_name} ${player.last_name}: CUT<br>` : response += `${player.first_name} ${player.last_name}: ${player.position}<br>`
});
response += `<br>`
});
return response;
}