-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointsService.js
More file actions
89 lines (71 loc) · 2.74 KB
/
PointsService.js
File metadata and controls
89 lines (71 loc) · 2.74 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
angular.module('APP')
.service('PointsService', function UsersListCtrl() {
var model = this;
const MAX_POINTS = 3;
const MID_POINTS = 2;
const MIN_POINTS = 1;
const MULTIPLIER_POINTS = 2;
model.getPoints = function (bet, fixture, matchday) {
var points = 0;
if (bet === '-') {
points = 0;
} else if (bet === fixture) {
points = MAX_POINTS;
} else {
var betHomeGoals = parseInt(bet[0]);
var betAwayGoals = parseInt(bet[2]);
var fixtureHomeGoals = parseInt(fixture[0]);
var fixtureAwayGoals = parseInt(fixture[2]);
var winnerFixture;
var winnerBet;
// fixture
if (fixtureHomeGoals > fixtureAwayGoals) {
winnerFixture = 'home';
} else if (fixtureHomeGoals === fixtureAwayGoals) {
winnerFixture = 'none';
} else {
winnerFixture = 'away';
}
// bet
if (betHomeGoals > betAwayGoals) {
winnerBet = 'home';
} else if (betHomeGoals === betAwayGoals) {
winnerBet = 'none';
} else {
winnerBet = 'away';
}
if (winnerFixture === winnerBet) {
// with winner
if (winnerFixture === 'home' || winnerFixture === 'away') {
var betGoalsDiff = betHomeGoals - betAwayGoals;
var fixtureGoalsDiff = fixtureHomeGoals - fixtureAwayGoals;
if (betGoalsDiff === fixtureGoalsDiff) {
points = MID_POINTS;
}
else {
points = MIN_POINTS;
}
}
// without winner - draw
else {
var betGoals = betHomeGoals;
var fixtureGoals = fixtureHomeGoals;
var goalsDifference = betGoals - fixtureGoals;
if (goalsDifference === -1 || goalsDifference === 1) {
points = MID_POINTS;
}
else {
points = MIN_POINTS;
}
}
// without winner
} else {
points = 0;
}
}
if (matchday > 3) {
points *= MULTIPLIER_POINTS;
}
return points;
}
});