-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_matrix.rb
114 lines (109 loc) · 3.93 KB
/
play_matrix.rb
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module PlayByPlay
module Model
class PlayMatrix
ACCESSIBLE_PLAYS = {
technical_free_throws: [
[ :ft ],
[ :ft_miss ],
[ :period_end ],
[ :technical_foul, team: :defense ],
[ :technical_foul, team: :offense ],
[ :technical_foul, flagrant: true, team: :defense ],
[ :technical_foul, flagrant: true, team: :offense ],
],
free_throws: [
[ :ft ],
[ :ft_miss ],
[ :offensive_foul ],
[ :period_end ],
[ :personal_foul, team: :defense ],
[ :personal_foul, team: :offense ],
[ :technical_foul, team: :defense ],
[ :technical_foul, team: :offense ],
[ :technical_foul, flagrant: true, team: :defense ],
[ :technical_foul, flagrant: true, team: :offense ],
[ :turnover ],
],
team: [
[ :block ],
[ :block, point_value: 3 ],
[ :fg ],
[ :fg, and_one: true ],
[ :fg, point_value: 3 ],
[ :fg, point_value: 3, and_one: true ],
[ :fg, assisted: true ],
[ :fg, and_one: true, assisted: true ],
[ :fg, point_value: 3, assisted: true ],
[ :fg, point_value: 3, and_one: true, assisted: true ],
[ :fg_miss ],
[ :fg_miss, point_value: 3 ],
[ :offensive_foul ],
[ :period_end ],
[ :personal_foul, away_from_play: true, team: :defense ],
[ :personal_foul, away_from_play: true, team: :offense ],
[ :personal_foul, clear_path: true, team: :defense ],
[ :personal_foul, intentional: true, team: :defense ],
[ :personal_foul, team: :defense ],
[ :personal_foul, team: :offense ],
[ :shooting_foul ],
[ :shooting_foul, point_value: 3 ],
[ :steal ],
[ :technical_foul, team: :defense ],
[ :technical_foul, team: :offense ],
[ :technical_foul, flagrant: true, team: :defense ],
[ :technical_foul, flagrant: true, team: :offense ],
[ :turnover ],
],
ball_in_play: [
[ :offensive_foul ],
[ :period_end ],
[ :personal_foul, clear_path: true, team: :defense ],
[ :personal_foul, intentional: true, team: :defense ],
[ :personal_foul, team: :defense ],
[ :personal_foul, team: :offense ],
[ :rebound, team: :defense ],
[ :rebound, team: :offense ],
[ :team_rebound, team: :defense ],
[ :team_rebound, team: :offense ],
[ :technical_foul, team: :defense ],
[ :technical_foul, team: :offense ],
[ :technical_foul, flagrant: true, team: :defense ],
[ :technical_foul, flagrant: true, team: :offense ],
],
no_seconds_remaining: [
[ :period_end ],
],
nil => [
[ :jump_ball, team: :home ],
[ :jump_ball, team: :visitor ],
[ :jump_ball_out_of_bounds, team: :home ],
[ :jump_ball_out_of_bounds, team: :visitor ],
[ :period_end ],
[ :team_rebound, team: :home ],
[ :team_rebound, team: :visitor ],
[ :technical_foul, team: :home ],
[ :technical_foul, team: :visitor ],
[ :technical_foul, flagrant: true, team: :defense ],
[ :technical_foul, flagrant: true, team: :offense ],
[ :turnover, team: :home ],
[ :turnover, team: :visitor ],
]
}.freeze
def self.play_keys
ACCESSIBLE_PLAYS.values.flatten(1).uniq
end
def self.possession_key?(key)
possession_keys.include? key
end
def self.possession_keys
ACCESSIBLE_PLAYS.keys
end
def self.accessible_plays(possession_key)
ACCESSIBLE_PLAYS[possession_key]
end
def self.accessible?(possession, play)
accessible_plays(possession.key).include? play.key
end
end
end
end