-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-store-utils.js
62 lines (50 loc) · 1.7 KB
/
data-store-utils.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const _ = require('lodash');
const {
rootPath,
dataRootPath,
TOP_PLAYERS_PER_POS_AND_PRICE,
} = require('./settings');
const defense = require(`${dataRootPath}/defense.json`);
const positionScores = require(`${rootPath}/position-scores.json`);
function topPlayersByPrice(players) {
return _(players)
.groupBy(({ Price }) => Price)
.pickBy(players => players.length > 0)
.mapValues(players => takeTopPlayers(players, TOP_PLAYERS_PER_POS_AND_PRICE))
.value();
}
function takeTopPlayers(players, numTop) {
return _(players)
.orderBy(({ xp }) => xp, 'desc')
.take(numTop)
.value();
}
function calcPlayerXP(player) {
const { Position: position, Team: team, Anytime: goalOdds, twoOrMore, shouldPlay } = player;
const getPlayerScoreByAchievement = getPlayerScore(position);
const goalScore = getPlayerScoreByAchievement('Goal');
const cleanSheetOdds = defense.find(country => country.Name === team)['Clean sheet'];
const cleanSheetScore = getPlayerScoreByAchievement('Clean');
const assistOdds = goalOdds;
const assistScore = getPlayerScoreByAchievement('Assist');
const probabilityToPlay = shouldPlay;
return (
probabilityToPlay *
(
goalScore / goalOdds +
assistScore / assistOdds +
2 * (goalScore / twoOrMore) +
cleanSheetScore / cleanSheetOdds
)
);
}
function getPlayerScore(playerPosition) {
return playerAchievement =>
positionScores.find(
({ position, achievement }) => position === playerPosition && achievement === playerAchievement
).score;
}
module.exports = {
topPlayersByPrice,
calcPlayerXP,
}