This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscores.coffee
94 lines (64 loc) · 2.84 KB
/
scores.coffee
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
90
91
92
93
94
calculate_persons_score = (person) ->
total_score = 0
admin = People.findOne({name: "admin"})
total_score = calculate_group_stage_score person.picks, admin.picks
total_score = total_score + calculate_quarters_score person.picks, admin.picks
total_score = total_score + calculate_semis_score person.picks, admin.picks
total_score = total_score + calculate_finals_score person.picks.winner, admin.picks.winner
total_score = total_score + calculate_tiebreaker_score person.picks.tiebreaker, admin.picks.tiebreaker
total_score
calculate_group_stage_score = (group_picks, admin_picks) ->
score = 0
# If no entries made yet, return 0 as the score
0 if _.isEmpty(group_picks)
# If you guessed right, you get two points
score = score + 2 if group_picks.A1 is admin_picks.A1
score = score + 2 if group_picks.B1 is admin_picks.B1
score = score + 2 if group_picks.C1 is admin_picks.C1
score = score + 2 if group_picks.D1 is admin_picks.D1
score = score + 2 if group_picks.A2 is admin_picks.A2
score = score + 2 if group_picks.B2 is admin_picks.B2
score = score + 2 if group_picks.C2 is admin_picks.C2
score = score + 2 if group_picks.D2 is admin_picks.D2
#If you were one off you only get one point
score = score + 1 if group_picks.A1 is admin_picks.A2
score = score + 1 if group_picks.A2 is admin_picks.A1
score = score + 1 if group_picks.B1 is admin_picks.B2
score = score + 1 if group_picks.B2 is admin_picks.B1
score = score + 1 if group_picks.C1 is admin_picks.C2
score = score + 1 if group_picks.C2 is admin_picks.C1
score = score + 1 if group_picks.D1 is admin_picks.D2
score = score + 1 if group_picks.D2 is admin_picks.D1
score
calculate_quarters_score = (quarters_picks, admin_picks) ->
score = 0
# If no entries made yet, return 0 as the score
0 if _.isEmpty(quarters_picks)
score = score + 4 if quarters_picks.Q1 is admin_picks.Q1
score = score + 4 if quarters_picks.Q2 is admin_picks.Q2
score = score + 4 if quarters_picks.Q3 is admin_picks.Q3
score = score + 4 if quarters_picks.Q4 is admin_picks.Q4
score
calculate_semis_score = (semis_picks, admin_picks) =>
score = 0
# If no entries made yet, return 0 as the score
0 if _.isEmpty(semis_picks)
score = score + 8 if semis_picks.S1 is admin_picks.S1
score = score + 8 if semis_picks.S2 is admin_picks.S2
score
calculate_finals_score = (finals_picks, admin_picks) ->
score = 0
# If no entries made yet, return 0 as the score
0 if _.isEmpty(finals_picks)
if finals_picks is admin_picks
16
else
0
calculate_tiebreaker_score = (tiebreaker, admin_picks) ->
score = 0
# If no entries made yet, return 0 as the score
0 if _.isNull(tiebreaker)
if tiebreaker is admin_picks
10
else
0