hockey-blast-common-lib 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hockey_blast_common_lib/aggregate_goalie_stats.py +161 -0
- hockey_blast_common_lib/aggregate_human_stats.py +291 -0
- hockey_blast_common_lib/aggregate_referee_stats.py +229 -0
- hockey_blast_common_lib/aggregate_skater_stats.py +323 -0
- hockey_blast_common_lib/db_connection.py +5 -17
- hockey_blast_common_lib/models.py +0 -527
- hockey_blast_common_lib/options.py +22 -0
- hockey_blast_common_lib/stats_models.py +563 -0
- hockey_blast_common_lib/utils.py +65 -0
- hockey_blast_common_lib/wsgi.py +16 -0
- {hockey_blast_common_lib-0.1.6.dist-info → hockey_blast_common_lib-0.1.8.dist-info}/METADATA +1 -1
- hockey_blast_common_lib-0.1.8.dist-info/RECORD +16 -0
- hockey_blast_common_lib-0.1.6.dist-info/RECORD +0 -8
- {hockey_blast_common_lib-0.1.6.dist-info → hockey_blast_common_lib-0.1.8.dist-info}/WHEEL +0 -0
- {hockey_blast_common_lib-0.1.6.dist-info → hockey_blast_common_lib-0.1.8.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,563 @@
|
|
1
|
+
from models import db
|
2
|
+
from sqlalchemy.ext.declarative import declared_attr
|
3
|
+
from sqlalchemy.orm import synonym
|
4
|
+
|
5
|
+
class BaseStatsHuman(db.Model):
|
6
|
+
__abstract__ = True
|
7
|
+
id = db.Column(db.Integer, primary_key=True)
|
8
|
+
human_id = db.Column(db.Integer, db.ForeignKey('humans.id'), nullable=False)
|
9
|
+
games_total = db.Column(db.Integer, default=0)
|
10
|
+
games_total_rank = db.Column(db.Integer, default=0)
|
11
|
+
games_skater = db.Column(db.Integer, default=0)
|
12
|
+
games_skater_rank = db.Column(db.Integer, default=0)
|
13
|
+
games_referee = db.Column(db.Integer, default=0)
|
14
|
+
games_referee_rank = db.Column(db.Integer, default=0)
|
15
|
+
games_scorekeeper = db.Column(db.Integer, default=0)
|
16
|
+
games_scorekeeper_rank = db.Column(db.Integer, default=0)
|
17
|
+
games_goalie = db.Column(db.Integer, default=0)
|
18
|
+
games_goalie_rank = db.Column(db.Integer, default=0)
|
19
|
+
total_in_rank = db.Column(db.Integer, default=0)
|
20
|
+
first_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
21
|
+
last_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
22
|
+
|
23
|
+
@declared_attr
|
24
|
+
def __table_args__(cls):
|
25
|
+
return (
|
26
|
+
db.UniqueConstraint('human_id', cls.get_aggregation_column(), name=f'_human_{cls.aggregation_type}_stats_uc1'),
|
27
|
+
db.Index(f'idx_{cls.aggregation_type}_games_total1', cls.get_aggregation_column(), 'games_total'),
|
28
|
+
db.Index(f'idx_{cls.aggregation_type}_games_skater1', cls.get_aggregation_column(), 'games_skater'),
|
29
|
+
db.Index(f'idx_{cls.aggregation_type}_games_referee1', cls.get_aggregation_column(), 'games_referee'),
|
30
|
+
db.Index(f'idx_{cls.aggregation_type}_games_scorekeeper1', cls.get_aggregation_column(), 'games_scorekeeper'),
|
31
|
+
db.Index(f'idx_{cls.aggregation_type}_games_goalie1', cls.get_aggregation_column(), 'games_goalie')
|
32
|
+
)
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def get_aggregation_column(cls):
|
36
|
+
raise NotImplementedError("Subclasses should implement this method to return the aggregation column name.")
|
37
|
+
|
38
|
+
|
39
|
+
class BaseStatsSkater(db.Model):
|
40
|
+
__abstract__ = True
|
41
|
+
id = db.Column(db.Integer, primary_key=True)
|
42
|
+
human_id = db.Column(db.Integer, db.ForeignKey('humans.id'), nullable=False)
|
43
|
+
games_played = db.Column(db.Integer, default=0)
|
44
|
+
games_played_rank = db.Column(db.Integer, default=0)
|
45
|
+
goals = db.Column(db.Integer, default=0)
|
46
|
+
goals_rank = db.Column(db.Integer, default=0)
|
47
|
+
assists = db.Column(db.Integer, default=0)
|
48
|
+
assists_rank = db.Column(db.Integer, default=0)
|
49
|
+
points = db.Column(db.Integer, default=0)
|
50
|
+
points_rank = db.Column(db.Integer, default=0)
|
51
|
+
penalties = db.Column(db.Integer, default=0)
|
52
|
+
penalties_rank = db.Column(db.Integer, default=0)
|
53
|
+
goals_per_game = db.Column(db.Float, default=0.0)
|
54
|
+
goals_per_game_rank = db.Column(db.Integer, default=0)
|
55
|
+
points_per_game = db.Column(db.Float, default=0.0)
|
56
|
+
points_per_game_rank = db.Column(db.Integer, default=0)
|
57
|
+
assists_per_game = db.Column(db.Float, default=0.0)
|
58
|
+
assists_per_game_rank = db.Column(db.Integer, default=0)
|
59
|
+
penalties_per_game = db.Column(db.Float, default=0.0)
|
60
|
+
penalties_per_game_rank = db.Column(db.Integer, default=0)
|
61
|
+
total_in_rank = db.Column(db.Integer, default=0)
|
62
|
+
first_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
63
|
+
last_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
64
|
+
|
65
|
+
@declared_attr
|
66
|
+
def __table_args__(cls):
|
67
|
+
return (
|
68
|
+
db.UniqueConstraint('human_id', cls.get_aggregation_column(), name=f'_human_{cls.aggregation_type}_uc_skater1'),
|
69
|
+
db.Index(f'idx_{cls.aggregation_type}_goals_per_game3', cls.get_aggregation_column(), 'goals_per_game'),
|
70
|
+
db.Index(f'idx_{cls.aggregation_type}_points_per_game3', cls.get_aggregation_column(), 'points_per_game'),
|
71
|
+
db.Index(f'idx_{cls.aggregation_type}_assists_per_game3', cls.get_aggregation_column(), 'assists_per_game'),
|
72
|
+
db.Index(f'idx_{cls.aggregation_type}_penalties_per_game3', cls.get_aggregation_column(), 'penalties_per_game'),
|
73
|
+
db.Index(f'idx_{cls.aggregation_type}_games_played3', cls.get_aggregation_column(), 'games_played')
|
74
|
+
)
|
75
|
+
|
76
|
+
@classmethod
|
77
|
+
def get_aggregation_column(cls):
|
78
|
+
raise NotImplementedError("Subclasses should implement this method to return the aggregation column name.")
|
79
|
+
|
80
|
+
class BaseStatsGoalie(db.Model):
|
81
|
+
__abstract__ = True
|
82
|
+
id = db.Column(db.Integer, primary_key=True)
|
83
|
+
human_id = db.Column(db.Integer, db.ForeignKey('humans.id'), nullable=False)
|
84
|
+
games_played = db.Column(db.Integer, default=0)
|
85
|
+
games_played_rank = db.Column(db.Integer, default=0)
|
86
|
+
goals_allowed = db.Column(db.Integer, default=0)
|
87
|
+
goals_allowed_rank = db.Column(db.Integer, default=0)
|
88
|
+
goals_allowed_per_game = db.Column(db.Float, default=0.0)
|
89
|
+
goals_allowed_per_game_rank = db.Column(db.Integer, default=0)
|
90
|
+
shots_faced = db.Column(db.Integer, default=0)
|
91
|
+
shots_faced_rank = db.Column(db.Integer, default=0)
|
92
|
+
save_percentage = db.Column(db.Float, default=0.0)
|
93
|
+
save_percentage_rank = db.Column(db.Integer, default=0)
|
94
|
+
total_in_rank = db.Column(db.Integer, default=0)
|
95
|
+
first_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
96
|
+
last_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
97
|
+
|
98
|
+
@declared_attr
|
99
|
+
def __table_args__(cls):
|
100
|
+
return (
|
101
|
+
db.UniqueConstraint('human_id', cls.get_aggregation_column(), name=f'_human_{cls.aggregation_type}_uc_goalie1'),
|
102
|
+
db.Index(f'idx_{cls.aggregation_type}_goals_allowed_per_game1', cls.get_aggregation_column(), 'goals_allowed_per_game'),
|
103
|
+
db.Index(f'idx_{cls.aggregation_type}_save_percentage1', cls.get_aggregation_column(), 'save_percentage'),
|
104
|
+
db.Index(f'idx_{cls.aggregation_type}_shots_faced1', cls.get_aggregation_column(), 'shots_faced'),
|
105
|
+
db.Index(f'idx_{cls.aggregation_type}_games_played_goalie1', cls.get_aggregation_column(), 'games_played'),
|
106
|
+
db.Index(f'idx_{cls.aggregation_type}_goals_allowed1', cls.get_aggregation_column(), 'goals_allowed')
|
107
|
+
)
|
108
|
+
|
109
|
+
@classmethod
|
110
|
+
def get_aggregation_column(cls):
|
111
|
+
raise NotImplementedError("Subclasses should implement this method to return the aggregation column name.")
|
112
|
+
|
113
|
+
class BaseStatsReferee(db.Model):
|
114
|
+
__abstract__ = True
|
115
|
+
id = db.Column(db.Integer, primary_key=True)
|
116
|
+
human_id = db.Column(db.Integer, db.ForeignKey('humans.id'), nullable=False)
|
117
|
+
games_reffed = db.Column(db.Integer, default=0)
|
118
|
+
games_reffed_rank = db.Column(db.Integer, default=0)
|
119
|
+
penalties_given = db.Column(db.Integer, default=0)
|
120
|
+
penalties_given_rank = db.Column(db.Integer, default=0)
|
121
|
+
penalties_per_game = db.Column(db.Float, default=0.0)
|
122
|
+
penalties_per_game_rank = db.Column(db.Integer, default=0)
|
123
|
+
gm_given = db.Column(db.Integer, default=0)
|
124
|
+
gm_given_rank = db.Column(db.Integer, default=0)
|
125
|
+
gm_per_game = db.Column(db.Float, default=0.0)
|
126
|
+
gm_per_game_rank = db.Column(db.Integer, default=0)
|
127
|
+
total_in_rank = db.Column(db.Integer, default=0)
|
128
|
+
first_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
129
|
+
last_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
130
|
+
|
131
|
+
@declared_attr
|
132
|
+
def __table_args__(cls):
|
133
|
+
return (
|
134
|
+
db.UniqueConstraint('human_id', cls.get_aggregation_column(), name=f'_human_{cls.aggregation_type}_uc_referee1'),
|
135
|
+
db.Index(f'idx_{cls.aggregation_type}_games_reffed1', cls.get_aggregation_column(), 'games_reffed'),
|
136
|
+
db.Index(f'idx_{cls.aggregation_type}_penalties_given1', cls.get_aggregation_column(), 'penalties_given'),
|
137
|
+
db.Index(f'idx_{cls.aggregation_type}_penalties_per_game1', cls.get_aggregation_column(), 'penalties_per_game'),
|
138
|
+
db.Index(f'idx_{cls.aggregation_type}_gm_given1', cls.get_aggregation_column(), 'gm_given'),
|
139
|
+
db.Index(f'idx_{cls.aggregation_type}_gm_per_game1', cls.get_aggregation_column(), 'gm_per_game')
|
140
|
+
)
|
141
|
+
|
142
|
+
@classmethod
|
143
|
+
def get_aggregation_column(cls):
|
144
|
+
raise NotImplementedError("Subclasses should implement this method to return the aggregation column name.")
|
145
|
+
|
146
|
+
class BaseStatsScorekeeper(db.Model):
|
147
|
+
__abstract__ = True
|
148
|
+
id = db.Column(db.Integer, primary_key=True)
|
149
|
+
human_id = db.Column(db.Integer, db.ForeignKey('humans.id'), nullable=False)
|
150
|
+
games_recorded = db.Column(db.Integer, default=0)
|
151
|
+
games_recorded_rank = db.Column(db.Integer, default=0)
|
152
|
+
sog_given = db.Column(db.Integer, default=0)
|
153
|
+
sog_given_rank = db.Column(db.Integer, default=0)
|
154
|
+
sog_per_game = db.Column(db.Float, default=0.0)
|
155
|
+
sog_per_game_rank = db.Column(db.Integer, default=0)
|
156
|
+
total_in_rank = db.Column(db.Integer, default=0)
|
157
|
+
first_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
158
|
+
last_game_id = db.Column(db.Integer, db.ForeignKey('games.id'))
|
159
|
+
|
160
|
+
@declared_attr
|
161
|
+
def __table_args__(cls):
|
162
|
+
return (
|
163
|
+
db.UniqueConstraint('human_id', cls.get_aggregation_column(), name=f'_human_{cls.aggregation_type}_uc_scorekeeper1'),
|
164
|
+
db.Index(f'idx_{cls.aggregation_type}_games_recorded1', cls.get_aggregation_column(), 'games_recorded'),
|
165
|
+
db.Index(f'idx_{cls.aggregation_type}_sog_given1', cls.get_aggregation_column(), 'sog_given'),
|
166
|
+
db.Index(f'idx_{cls.aggregation_type}_sog_per_game1', cls.get_aggregation_column(), 'sog_per_game')
|
167
|
+
)
|
168
|
+
|
169
|
+
@classmethod
|
170
|
+
def get_aggregation_column(cls):
|
171
|
+
raise NotImplementedError("Subclasses should implement this method to return the aggregation column name.")
|
172
|
+
|
173
|
+
class OrgStatsHuman(BaseStatsHuman):
|
174
|
+
__tablename__ = 'org_stats_human'
|
175
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
176
|
+
aggregation_id = synonym('org_id')
|
177
|
+
|
178
|
+
@declared_attr
|
179
|
+
def aggregation_type(cls):
|
180
|
+
return 'org'
|
181
|
+
|
182
|
+
@classmethod
|
183
|
+
def get_aggregation_column(cls):
|
184
|
+
return 'org_id'
|
185
|
+
|
186
|
+
class DivisionStatsHuman(BaseStatsHuman):
|
187
|
+
__tablename__ = 'division_stats_human'
|
188
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
189
|
+
aggregation_id = synonym('division_id')
|
190
|
+
|
191
|
+
@declared_attr
|
192
|
+
def aggregation_type(cls):
|
193
|
+
return 'division'
|
194
|
+
|
195
|
+
@classmethod
|
196
|
+
def get_aggregation_column(cls):
|
197
|
+
return 'division_id'
|
198
|
+
|
199
|
+
class OrgStatsSkater(BaseStatsSkater):
|
200
|
+
__tablename__ = 'org_stats_skater'
|
201
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
202
|
+
aggregation_id = synonym('org_id')
|
203
|
+
|
204
|
+
@declared_attr
|
205
|
+
def aggregation_type(cls):
|
206
|
+
return 'org'
|
207
|
+
|
208
|
+
@classmethod
|
209
|
+
def get_aggregation_column(cls):
|
210
|
+
return 'org_id'
|
211
|
+
|
212
|
+
class DivisionStatsSkater(BaseStatsSkater):
|
213
|
+
__tablename__ = 'division_stats_skater'
|
214
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
215
|
+
aggregation_id = synonym('division_id')
|
216
|
+
|
217
|
+
@declared_attr
|
218
|
+
def aggregation_type(cls):
|
219
|
+
return 'division'
|
220
|
+
|
221
|
+
@classmethod
|
222
|
+
def get_aggregation_column(cls):
|
223
|
+
return 'division_id'
|
224
|
+
|
225
|
+
class OrgStatsGoalie(BaseStatsGoalie):
|
226
|
+
__tablename__ = 'org_stats_goalie'
|
227
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
228
|
+
aggregation_id = synonym('org_id')
|
229
|
+
|
230
|
+
@declared_attr
|
231
|
+
def aggregation_type(cls):
|
232
|
+
return 'org'
|
233
|
+
|
234
|
+
@classmethod
|
235
|
+
def get_aggregation_column(cls):
|
236
|
+
return 'org_id'
|
237
|
+
|
238
|
+
class DivisionStatsGoalie(BaseStatsGoalie):
|
239
|
+
__tablename__ = 'division_stats_goalie'
|
240
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
241
|
+
aggregation_id = synonym('division_id')
|
242
|
+
|
243
|
+
@declared_attr
|
244
|
+
def aggregation_type(cls):
|
245
|
+
return 'division'
|
246
|
+
|
247
|
+
@classmethod
|
248
|
+
def get_aggregation_column(cls):
|
249
|
+
return 'division_id'
|
250
|
+
|
251
|
+
|
252
|
+
class OrgStatsReferee(BaseStatsReferee):
|
253
|
+
__tablename__ = 'org_stats_referee'
|
254
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
255
|
+
aggregation_id = synonym('org_id')
|
256
|
+
|
257
|
+
@declared_attr
|
258
|
+
def aggregation_type(cls):
|
259
|
+
return 'org'
|
260
|
+
|
261
|
+
@classmethod
|
262
|
+
def get_aggregation_column(cls):
|
263
|
+
return 'org_id'
|
264
|
+
|
265
|
+
class DivisionStatsReferee(BaseStatsReferee):
|
266
|
+
__tablename__ = 'division_stats_referee'
|
267
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
268
|
+
aggregation_id = synonym('division_id')
|
269
|
+
|
270
|
+
@declared_attr
|
271
|
+
def aggregation_type(cls):
|
272
|
+
return 'division'
|
273
|
+
|
274
|
+
@classmethod
|
275
|
+
def get_aggregation_column(cls):
|
276
|
+
return 'division_id'
|
277
|
+
|
278
|
+
|
279
|
+
class OrgStatsScorekeeper(BaseStatsScorekeeper):
|
280
|
+
__tablename__ = 'org_stats_scorekeeper'
|
281
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
282
|
+
aggregation_id = synonym('org_id')
|
283
|
+
|
284
|
+
@declared_attr
|
285
|
+
def aggregation_type(cls):
|
286
|
+
return 'org'
|
287
|
+
|
288
|
+
@classmethod
|
289
|
+
def get_aggregation_column(cls):
|
290
|
+
return 'org_id'
|
291
|
+
|
292
|
+
class DivisionStatsScorekeeper(BaseStatsScorekeeper):
|
293
|
+
__tablename__ = 'division_stats_scorekeeper'
|
294
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
295
|
+
aggregation_id = synonym('division_id')
|
296
|
+
|
297
|
+
@declared_attr
|
298
|
+
def aggregation_type(cls):
|
299
|
+
return 'division'
|
300
|
+
|
301
|
+
@classmethod
|
302
|
+
def get_aggregation_column(cls):
|
303
|
+
return 'division_id'
|
304
|
+
|
305
|
+
class OrgStatsDailyHuman(BaseStatsHuman):
|
306
|
+
__tablename__ = 'org_stats_daily_human'
|
307
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
308
|
+
aggregation_id = synonym('org_id')
|
309
|
+
|
310
|
+
@classmethod
|
311
|
+
def get_aggregation_column(cls):
|
312
|
+
return 'org_id'
|
313
|
+
|
314
|
+
@declared_attr
|
315
|
+
def aggregation_type(cls):
|
316
|
+
return 'org_daily'
|
317
|
+
|
318
|
+
class OrgStatsWeeklyHuman(BaseStatsHuman):
|
319
|
+
__tablename__ = 'org_stats_weekly_human'
|
320
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
321
|
+
aggregation_id = synonym('org_id')
|
322
|
+
|
323
|
+
@classmethod
|
324
|
+
def get_aggregation_column(cls):
|
325
|
+
return 'org_id'
|
326
|
+
|
327
|
+
@declared_attr
|
328
|
+
def aggregation_type(cls):
|
329
|
+
return 'org_weekly'
|
330
|
+
|
331
|
+
class DivisionStatsDailyHuman(BaseStatsHuman):
|
332
|
+
__tablename__ = 'division_stats_daily_human'
|
333
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
334
|
+
aggregation_id = synonym('division_id')
|
335
|
+
|
336
|
+
@classmethod
|
337
|
+
def get_aggregation_column(cls):
|
338
|
+
return 'division_id'
|
339
|
+
|
340
|
+
@declared_attr
|
341
|
+
def aggregation_type(cls):
|
342
|
+
return 'division_daily'
|
343
|
+
|
344
|
+
class DivisionStatsWeeklyHuman(BaseStatsHuman):
|
345
|
+
__tablename__ = 'division_stats_weekly_human'
|
346
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
347
|
+
aggregation_id = synonym('division_id')
|
348
|
+
|
349
|
+
@classmethod
|
350
|
+
def get_aggregation_column(cls):
|
351
|
+
return 'division_id'
|
352
|
+
|
353
|
+
@declared_attr
|
354
|
+
def aggregation_type(cls):
|
355
|
+
return 'division_weekly'
|
356
|
+
|
357
|
+
class OrgStatsDailySkater(BaseStatsSkater):
|
358
|
+
__tablename__ = 'org_stats_daily_skater'
|
359
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
360
|
+
aggregation_id = synonym('org_id')
|
361
|
+
|
362
|
+
@declared_attr
|
363
|
+
def aggregation_type(cls):
|
364
|
+
return 'org_daily'
|
365
|
+
|
366
|
+
@classmethod
|
367
|
+
def get_aggregation_column(cls):
|
368
|
+
return 'org_id'
|
369
|
+
|
370
|
+
class OrgStatsWeeklySkater(BaseStatsSkater):
|
371
|
+
__tablename__ = 'org_stats_weekly_skater'
|
372
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
373
|
+
aggregation_id = synonym('org_id')
|
374
|
+
|
375
|
+
@declared_attr
|
376
|
+
def aggregation_type(cls):
|
377
|
+
return 'org_weekly'
|
378
|
+
|
379
|
+
@classmethod
|
380
|
+
def get_aggregation_column(cls):
|
381
|
+
return 'org_id'
|
382
|
+
|
383
|
+
class DivisionStatsDailySkater(BaseStatsSkater):
|
384
|
+
__tablename__ = 'division_stats_daily_skater'
|
385
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
386
|
+
aggregation_id = synonym('division_id')
|
387
|
+
|
388
|
+
@declared_attr
|
389
|
+
def aggregation_type(cls):
|
390
|
+
return 'division_daily'
|
391
|
+
|
392
|
+
@classmethod
|
393
|
+
def get_aggregation_column(cls):
|
394
|
+
return 'division_id'
|
395
|
+
|
396
|
+
class DivisionStatsWeeklySkater(BaseStatsSkater):
|
397
|
+
__tablename__ = 'division_stats_weekly_skater'
|
398
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
399
|
+
aggregation_id = synonym('division_id')
|
400
|
+
|
401
|
+
@declared_attr
|
402
|
+
def aggregation_type(cls):
|
403
|
+
return 'division_weekly'
|
404
|
+
|
405
|
+
@classmethod
|
406
|
+
def get_aggregation_column(cls):
|
407
|
+
return 'division_id'
|
408
|
+
|
409
|
+
class OrgStatsDailyGoalie(BaseStatsGoalie):
|
410
|
+
__tablename__ = 'org_stats_daily_goalie'
|
411
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
412
|
+
aggregation_id = synonym('org_id')
|
413
|
+
|
414
|
+
@declared_attr
|
415
|
+
def aggregation_type(cls):
|
416
|
+
return 'org_daily'
|
417
|
+
|
418
|
+
@classmethod
|
419
|
+
def get_aggregation_column(cls):
|
420
|
+
return 'org_id'
|
421
|
+
|
422
|
+
class OrgStatsWeeklyGoalie(BaseStatsGoalie):
|
423
|
+
__tablename__ = 'org_stats_weekly_goalie'
|
424
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
425
|
+
aggregation_id = synonym('org_id')
|
426
|
+
|
427
|
+
@declared_attr
|
428
|
+
def aggregation_type(cls):
|
429
|
+
return 'org_weekly'
|
430
|
+
|
431
|
+
@classmethod
|
432
|
+
def get_aggregation_column(cls):
|
433
|
+
return 'org_id'
|
434
|
+
|
435
|
+
class DivisionStatsDailyGoalie(BaseStatsGoalie):
|
436
|
+
__tablename__ = 'division_stats_daily_goalie'
|
437
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
438
|
+
aggregation_id = synonym('division_id')
|
439
|
+
|
440
|
+
@declared_attr
|
441
|
+
def aggregation_type(cls):
|
442
|
+
return 'division_daily'
|
443
|
+
|
444
|
+
@classmethod
|
445
|
+
def get_aggregation_column(cls):
|
446
|
+
return 'division_id'
|
447
|
+
|
448
|
+
class DivisionStatsWeeklyGoalie(BaseStatsGoalie):
|
449
|
+
__tablename__ = 'division_stats_weekly_goalie'
|
450
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
451
|
+
aggregation_id = synonym('division_id')
|
452
|
+
|
453
|
+
@declared_attr
|
454
|
+
def aggregation_type(cls):
|
455
|
+
return 'division_weekly'
|
456
|
+
|
457
|
+
@classmethod
|
458
|
+
def get_aggregation_column(cls):
|
459
|
+
return 'division_id'
|
460
|
+
|
461
|
+
class OrgStatsDailyReferee(BaseStatsReferee):
|
462
|
+
__tablename__ = 'org_stats_daily_referee'
|
463
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
464
|
+
aggregation_id = synonym('org_id')
|
465
|
+
|
466
|
+
@declared_attr
|
467
|
+
def aggregation_type(cls):
|
468
|
+
return 'org_daily'
|
469
|
+
|
470
|
+
@classmethod
|
471
|
+
def get_aggregation_column(cls):
|
472
|
+
return 'org_id'
|
473
|
+
|
474
|
+
class OrgStatsWeeklyReferee(BaseStatsReferee):
|
475
|
+
__tablename__ = 'org_stats_weekly_referee'
|
476
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
477
|
+
aggregation_id = synonym('org_id')
|
478
|
+
|
479
|
+
@declared_attr
|
480
|
+
def aggregation_type(cls):
|
481
|
+
return 'org_weekly'
|
482
|
+
|
483
|
+
@classmethod
|
484
|
+
def get_aggregation_column(cls):
|
485
|
+
return 'org_id'
|
486
|
+
|
487
|
+
class DivisionStatsDailyReferee(BaseStatsReferee):
|
488
|
+
__tablename__ = 'division_stats_daily_referee'
|
489
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
490
|
+
aggregation_id = synonym('division_id')
|
491
|
+
|
492
|
+
@declared_attr
|
493
|
+
def aggregation_type(cls):
|
494
|
+
return 'division_daily'
|
495
|
+
|
496
|
+
@classmethod
|
497
|
+
def get_aggregation_column(cls):
|
498
|
+
return 'division_id'
|
499
|
+
|
500
|
+
class DivisionStatsWeeklyReferee(BaseStatsReferee):
|
501
|
+
__tablename__ = 'division_stats_weekly_referee'
|
502
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
503
|
+
aggregation_id = synonym('division_id')
|
504
|
+
|
505
|
+
@declared_attr
|
506
|
+
def aggregation_type(cls):
|
507
|
+
return 'division_weekly'
|
508
|
+
|
509
|
+
@classmethod
|
510
|
+
def get_aggregation_column(cls):
|
511
|
+
return 'division_id'
|
512
|
+
|
513
|
+
class OrgStatsDailyScorekeeper(BaseStatsScorekeeper):
|
514
|
+
__tablename__ = 'org_stats_daily_scorekeeper'
|
515
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
516
|
+
aggregation_id = synonym('org_id')
|
517
|
+
|
518
|
+
@declared_attr
|
519
|
+
def aggregation_type(cls):
|
520
|
+
return 'org_daily'
|
521
|
+
|
522
|
+
@classmethod
|
523
|
+
def get_aggregation_column(cls):
|
524
|
+
return 'org_id'
|
525
|
+
|
526
|
+
class OrgStatsWeeklyScorekeeper(BaseStatsScorekeeper):
|
527
|
+
__tablename__ = 'org_stats_weekly_scorekeeper'
|
528
|
+
org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
|
529
|
+
aggregation_id = synonym('org_id')
|
530
|
+
|
531
|
+
@declared_attr
|
532
|
+
def aggregation_type(cls):
|
533
|
+
return 'org_weekly'
|
534
|
+
|
535
|
+
@classmethod
|
536
|
+
def get_aggregation_column(cls):
|
537
|
+
return 'org_id'
|
538
|
+
|
539
|
+
class DivisionStatsDailyScorekeeper(BaseStatsScorekeeper):
|
540
|
+
__tablename__ = 'division_stats_daily_scorekeeper'
|
541
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
542
|
+
aggregation_id = synonym('division_id')
|
543
|
+
|
544
|
+
@declared_attr
|
545
|
+
def aggregation_type(cls):
|
546
|
+
return 'division_daily'
|
547
|
+
|
548
|
+
@classmethod
|
549
|
+
def get_aggregation_column(cls):
|
550
|
+
return 'division_id'
|
551
|
+
|
552
|
+
class DivisionStatsWeeklyScorekeeper(BaseStatsScorekeeper):
|
553
|
+
__tablename__ = 'division_stats_weekly_scorekeeper'
|
554
|
+
division_id = db.Column(db.Integer, db.ForeignKey('divisions.id'), nullable=False)
|
555
|
+
aggregation_id = synonym('division_id')
|
556
|
+
|
557
|
+
@declared_attr
|
558
|
+
def aggregation_type(cls):
|
559
|
+
return 'division_weekly'
|
560
|
+
|
561
|
+
@classmethod
|
562
|
+
def get_aggregation_column(cls):
|
563
|
+
return 'division_id'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import sys
|
2
|
+
import os
|
3
|
+
from datetime import datetime, timedelta
|
4
|
+
|
5
|
+
|
6
|
+
from models import Organization, Human, Division
|
7
|
+
from sqlalchemy.sql import func
|
8
|
+
|
9
|
+
|
10
|
+
def get_org_id_from_alias(session, org_alias):
|
11
|
+
# Predefined organizations
|
12
|
+
predefined_organizations = [
|
13
|
+
{"id": 1, "organization_name": "Sharks Ice", "alias": "sharksice"},
|
14
|
+
{"id": 2, "organization_name": "TriValley Ice", "alias": "tvice"},
|
15
|
+
{"id": 3, "organization_name": "CAHA", "alias": "caha"}
|
16
|
+
]
|
17
|
+
|
18
|
+
# Check if the organization exists
|
19
|
+
organization = session.query(Organization).filter_by(alias=org_alias).first()
|
20
|
+
if organization:
|
21
|
+
return organization.id
|
22
|
+
else:
|
23
|
+
# Insert predefined organizations if they do not exist
|
24
|
+
for org in predefined_organizations:
|
25
|
+
existing_org = session.query(Organization).filter_by(id=org["id"]).first()
|
26
|
+
if not existing_org:
|
27
|
+
new_org = Organization(id=org["id"], organization_name=org["organization_name"], alias=org["alias"])
|
28
|
+
session.add(new_org)
|
29
|
+
session.commit()
|
30
|
+
|
31
|
+
# Retry to get the organization after inserting predefined organizations
|
32
|
+
organization = session.query(Organization).filter_by(alias=org_alias).first()
|
33
|
+
if organization:
|
34
|
+
return organization.id
|
35
|
+
else:
|
36
|
+
raise ValueError(f"Organization with alias '{org_alias}' not found.")
|
37
|
+
|
38
|
+
def get_human_ids_by_names(session, names):
|
39
|
+
human_ids = set()
|
40
|
+
for first_name, middle_name, last_name in names:
|
41
|
+
query = session.query(Human.id)
|
42
|
+
if first_name:
|
43
|
+
query = query.filter(Human.first_name == first_name)
|
44
|
+
if middle_name:
|
45
|
+
query = query.filter(Human.middle_name == middle_name)
|
46
|
+
if last_name:
|
47
|
+
query = query.filter(Human.last_name == last_name)
|
48
|
+
results = query.all()
|
49
|
+
human_ids.update([result.id for result in results])
|
50
|
+
return human_ids
|
51
|
+
|
52
|
+
def get_division_ids_for_last_season_in_all_leagues(session, org_id):
|
53
|
+
# # TODO = remove tmp hack
|
54
|
+
# return get_all_division_ids_for_org(session, org_id)
|
55
|
+
league_numbers = session.query(Division.league_number).filter(Division.org_id == org_id).distinct().all()
|
56
|
+
division_ids = []
|
57
|
+
for league_number, in league_numbers:
|
58
|
+
max_season_number = session.query(func.max(Division.season_number)).filter_by(league_number=league_number, org_id=org_id).scalar()
|
59
|
+
division_ids_for_league = session.query(Division.id).filter_by(league_number=league_number, season_number=max_season_number, org_id=org_id).all()
|
60
|
+
division_ids.extend([division_id.id for division_id in division_ids_for_league])
|
61
|
+
return division_ids
|
62
|
+
|
63
|
+
def get_all_division_ids_for_org(session, org_id):
|
64
|
+
division_ids_for_org = session.query(Division.id).filter_by(org_id=org_id).all()
|
65
|
+
return [division_id.id for division_id in division_ids_for_org]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from flask_migrate import Migrate
|
2
|
+
from flask import Flask
|
3
|
+
from .models import *
|
4
|
+
from .stats_models import *
|
5
|
+
from .stats_models import db
|
6
|
+
from .db_connection import get_db_params
|
7
|
+
|
8
|
+
app = Flask(__name__)
|
9
|
+
db_params = get_db_params("hockey-blast-radonly")
|
10
|
+
db_url = f"postgresql://{db_params['user']}:{db_params['password']}@{db_params['host']}:{db_params['port']}/{db_params['dbname']}"
|
11
|
+
app.config['SQLALCHEMY_DATABASE_URI'] = db_url
|
12
|
+
|
13
|
+
db.init_app(app)
|
14
|
+
migrate = Migrate(app, db)
|
15
|
+
|
16
|
+
# Export db and migrate for flask cli
|
@@ -0,0 +1,16 @@
|
|
1
|
+
hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
hockey_blast_common_lib/aggregate_goalie_stats.py,sha256=jfPmlb7dHLacPb2dNA3S4BuQpoNJFvcOoX7SijnHRFg,8515
|
3
|
+
hockey_blast_common_lib/aggregate_human_stats.py,sha256=rY18_lfHaEYHhqpCYT5MEuhZLfB8kYSmw42VB3xGkHY,14002
|
4
|
+
hockey_blast_common_lib/aggregate_referee_stats.py,sha256=RVgzhh0IajmG7YrxX5wOeFMUhGpIMHk7SUQUDx542d8,10789
|
5
|
+
hockey_blast_common_lib/aggregate_skater_stats.py,sha256=1No-9saK8L30EQYrS7nEP6CbBR96tdA2aXQrtTMU6z0,15336
|
6
|
+
hockey_blast_common_lib/db_connection.py,sha256=JJcYbBuGlstMfui7UwP5GxPRwzrh4PxtsZDpWsQPnqA,998
|
7
|
+
hockey_blast_common_lib/db_utils.py,sha256=GjtcQsSilR55GlLuFAzIGhEVYG3cve7KBkUggW03tDo,767
|
8
|
+
hockey_blast_common_lib/models.py,sha256=GqQIGpanmFub97BoYCuaqDov2MxM4LMesUTxZ2edpvw,15393
|
9
|
+
hockey_blast_common_lib/options.py,sha256=-LtEX8duw5Pl3CSpjFlLM5FPvrZuTAxTfSlDPa7H6mQ,761
|
10
|
+
hockey_blast_common_lib/stats_models.py,sha256=AsHnllpSRWU3-obf01ZFFycnqoRrC9jomwvsC5VPhtI,21023
|
11
|
+
hockey_blast_common_lib/utils.py,sha256=_Lbovw3ygkSBk3vRsSvkunoFem9J_d46C0hzT_uXr-w,2875
|
12
|
+
hockey_blast_common_lib/wsgi.py,sha256=Qpux4NpQQnZ2U3gOAsqualn-bv9cLjFaXQtFQinC0j4,513
|
13
|
+
hockey_blast_common_lib-0.1.8.dist-info/METADATA,sha256=f2nMZVsDXbtoDN2DU0rrxGQVjT0jZqbFLhLM2kAhZFc,317
|
14
|
+
hockey_blast_common_lib-0.1.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
15
|
+
hockey_blast_common_lib-0.1.8.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
|
16
|
+
hockey_blast_common_lib-0.1.8.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
hockey_blast_common_lib/db_connection.py,sha256=4bN9pLynzOhd_9_u0bvQjgmE0qvkKHoOA95Ga3e_x7g,1361
|
3
|
-
hockey_blast_common_lib/db_utils.py,sha256=GjtcQsSilR55GlLuFAzIGhEVYG3cve7KBkUggW03tDo,767
|
4
|
-
hockey_blast_common_lib/models.py,sha256=Sfq1dwaDx4fQpfd66o1R_3AyRNKv34vjnvY4B-ebqg8,33910
|
5
|
-
hockey_blast_common_lib-0.1.6.dist-info/METADATA,sha256=y5wsjzJGFDx-qdCYnAABIwIXdwPJcYgrj0zCuaUTOFE,317
|
6
|
-
hockey_blast_common_lib-0.1.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
7
|
-
hockey_blast_common_lib-0.1.6.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
|
8
|
-
hockey_blast_common_lib-0.1.6.dist-info/RECORD,,
|
File without changes
|
{hockey_blast_common_lib-0.1.6.dist-info → hockey_blast_common_lib-0.1.8.dist-info}/top_level.txt
RENAMED
File without changes
|