hockey-blast-common-lib 0.1.33__py3-none-any.whl → 0.1.35__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_all_stats.py +26 -0
- hockey_blast_common_lib/aggregate_goalie_stats.py +12 -16
- hockey_blast_common_lib/aggregate_human_stats.py +32 -35
- hockey_blast_common_lib/aggregate_referee_stats.py +12 -18
- hockey_blast_common_lib/aggregate_skater_stats.py +14 -19
- hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz +0 -0
- hockey_blast_common_lib/models.py +1 -0
- hockey_blast_common_lib/skills_in_divisions.py +1 -16
- hockey_blast_common_lib/stats_utils.py +0 -4
- hockey_blast_common_lib/utils.py +36 -4
- {hockey_blast_common_lib-0.1.33.dist-info → hockey_blast_common_lib-0.1.35.dist-info}/METADATA +1 -1
- hockey_blast_common_lib-0.1.35.dist-info/RECORD +23 -0
- hockey_blast_common_lib-0.1.33.dist-info/RECORD +0 -22
- {hockey_blast_common_lib-0.1.33.dist-info → hockey_blast_common_lib-0.1.35.dist-info}/WHEEL +0 -0
- {hockey_blast_common_lib-0.1.33.dist-info → hockey_blast_common_lib-0.1.35.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
import sys, os
|
2
|
+
|
3
|
+
# Add the package directory to the Python path
|
4
|
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
5
|
+
|
6
|
+
from hockey_blast_common_lib.aggregate_human_stats import run_aggregate_human_stats
|
7
|
+
from hockey_blast_common_lib.aggregate_skater_stats import run_aggregate_skater_stats
|
8
|
+
from hockey_blast_common_lib.aggregate_goalie_stats import run_aggregate_goalie_stats
|
9
|
+
from hockey_blast_common_lib.aggregate_referee_stats import run_aggregate_referee_stats
|
10
|
+
|
11
|
+
if __name__ == "__main__":
|
12
|
+
print("Running aggregate_human_stats...")
|
13
|
+
run_aggregate_human_stats()
|
14
|
+
print("Finished running aggregate_human_stats\n")
|
15
|
+
|
16
|
+
print("Running aggregate_skater_stats...")
|
17
|
+
run_aggregate_skater_stats()
|
18
|
+
print("Finished running aggregate_skater_stats\n")
|
19
|
+
|
20
|
+
print("Running aggregate_goalie_stats...")
|
21
|
+
run_aggregate_goalie_stats()
|
22
|
+
print("Finished running aggregate_goalie_stats\n")
|
23
|
+
|
24
|
+
print("Running aggregate_referee_stats...")
|
25
|
+
run_aggregate_referee_stats()
|
26
|
+
print("Finished running aggregate_referee_stats\n")
|
@@ -11,8 +11,8 @@ from hockey_blast_common_lib.stats_models import OrgStatsGoalie, DivisionStatsGo
|
|
11
11
|
from hockey_blast_common_lib.db_connection import create_session
|
12
12
|
from sqlalchemy.sql import func, case
|
13
13
|
from hockey_blast_common_lib.options import not_human_names, parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, MIN_GAMES_FOR_LEVEL_STATS
|
14
|
-
from hockey_blast_common_lib.utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
|
15
|
-
from hockey_blast_common_lib.
|
14
|
+
from hockey_blast_common_lib.utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org, get_start_datetime
|
15
|
+
from hockey_blast_common_lib.utils import assign_ranks
|
16
16
|
from sqlalchemy import func, case, and_
|
17
17
|
from collections import defaultdict
|
18
18
|
|
@@ -61,18 +61,11 @@ def aggregate_goalie_stats(session, aggregation_type, aggregation_id, names_to_f
|
|
61
61
|
|
62
62
|
# Apply aggregation window filter
|
63
63
|
if aggregation_window:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
elif aggregation_window == 'Weekly':
|
70
|
-
start_datetime = last_game_datetime - timedelta(weeks=1)
|
71
|
-
else:
|
72
|
-
start_datetime = None
|
73
|
-
if start_datetime:
|
74
|
-
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
|
75
|
-
filter_condition = filter_condition & game_window_filter
|
64
|
+
last_game_datetime_str = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, Game.status.like('Final%')).scalar()
|
65
|
+
start_datetime = get_start_datetime(last_game_datetime_str, aggregation_window)
|
66
|
+
if start_datetime:
|
67
|
+
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime_str)
|
68
|
+
filter_condition = filter_condition & game_window_filter
|
76
69
|
|
77
70
|
# Delete existing items from the stats table
|
78
71
|
session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
|
@@ -180,7 +173,7 @@ def aggregate_goalie_stats(session, aggregation_type, aggregation_id, names_to_f
|
|
180
173
|
session.commit()
|
181
174
|
session.commit()
|
182
175
|
|
183
|
-
|
176
|
+
def run_aggregate_goalie_stats():
|
184
177
|
session = create_session("boss")
|
185
178
|
human_id_to_debug = None
|
186
179
|
|
@@ -216,4 +209,7 @@ if __name__ == "__main__":
|
|
216
209
|
if human_id_to_debug is None:
|
217
210
|
print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
|
218
211
|
processed_levels += 1
|
219
|
-
aggregate_goalie_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names, debug_human_id=human_id_to_debug)
|
212
|
+
aggregate_goalie_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names, debug_human_id=human_id_to_debug)
|
213
|
+
|
214
|
+
if __name__ == "__main__":
|
215
|
+
run_aggregate_goalie_stats()
|
@@ -12,7 +12,8 @@ from hockey_blast_common_lib.db_connection import create_session
|
|
12
12
|
from sqlalchemy.sql import func, case
|
13
13
|
from hockey_blast_common_lib.options import parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, MIN_GAMES_FOR_LEVEL_STATS, not_human_names
|
14
14
|
from hockey_blast_common_lib.utils import get_fake_human_for_stats, get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
|
15
|
-
from hockey_blast_common_lib.
|
15
|
+
from hockey_blast_common_lib.utils import assign_ranks
|
16
|
+
from hockey_blast_common_lib.utils import get_start_datetime
|
16
17
|
|
17
18
|
def aggregate_human_stats(session, aggregation_type, aggregation_id, names_to_filter_out, human_id_filter=None, aggregation_window=None):
|
18
19
|
human_ids_to_filter = get_human_ids_by_names(session, names_to_filter_out)
|
@@ -50,18 +51,11 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, names_to_fi
|
|
50
51
|
|
51
52
|
# Apply aggregation window filter
|
52
53
|
if aggregation_window:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
elif aggregation_window == 'Weekly':
|
59
|
-
start_datetime = last_game_datetime - timedelta(weeks=1)
|
60
|
-
else:
|
61
|
-
start_datetime = None
|
62
|
-
if start_datetime:
|
63
|
-
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
|
64
|
-
filter_condition = filter_condition & game_window_filter
|
54
|
+
last_game_datetime_str = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, Game.status.like('Final%')).scalar()
|
55
|
+
start_datetime = get_start_datetime(last_game_datetime_str, aggregation_window)
|
56
|
+
if start_datetime:
|
57
|
+
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime_str)
|
58
|
+
filter_condition = filter_condition & game_window_filter
|
65
59
|
|
66
60
|
# Delete existing items from the stats table
|
67
61
|
session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
|
@@ -415,30 +409,30 @@ def aggregate_human_stats(session, aggregation_type, aggregation_id, names_to_fi
|
|
415
409
|
session.add(overall_human_stat)
|
416
410
|
session.commit()
|
417
411
|
|
418
|
-
|
412
|
+
def run_aggregate_human_stats():
|
419
413
|
session = create_session("boss")
|
420
414
|
human_id_to_debug = None
|
421
415
|
|
422
|
-
#
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
416
|
+
# Aggregate by Org and Division inside Org
|
417
|
+
org_ids = session.query(Organization.id).all()
|
418
|
+
org_ids = [org_id[0] for org_id in org_ids]
|
419
|
+
|
420
|
+
for org_id in org_ids:
|
421
|
+
division_ids = get_all_division_ids_for_org(session, org_id)
|
422
|
+
print(f"Aggregating human stats for {len(division_ids)} divisions in org_id {org_id}...")
|
423
|
+
total_divisions = len(division_ids)
|
424
|
+
processed_divisions = 0
|
425
|
+
for division_id in division_ids:
|
426
|
+
aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug)
|
427
|
+
aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
|
428
|
+
aggregate_human_stats(session, aggregation_type='division', aggregation_id=division_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug, aggregation_window='Daily')
|
429
|
+
processed_divisions += 1
|
430
|
+
if human_id_to_debug is None:
|
431
|
+
print(f"\rProcessed {processed_divisions}/{total_divisions} divisions ({(processed_divisions/total_divisions)*100:.2f}%)", end="")
|
432
|
+
print("")
|
433
|
+
aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug)
|
434
|
+
aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug, aggregation_window='Weekly')
|
435
|
+
aggregate_human_stats(session, aggregation_type='org', aggregation_id=org_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug, aggregation_window='Daily')
|
442
436
|
|
443
437
|
# Aggregate by level
|
444
438
|
level_ids = session.query(Division.level_id).distinct().all()
|
@@ -451,4 +445,7 @@ if __name__ == "__main__":
|
|
451
445
|
if human_id_to_debug is None:
|
452
446
|
print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
|
453
447
|
processed_levels += 1
|
454
|
-
aggregate_human_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug)
|
448
|
+
aggregate_human_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names, human_id_filter=human_id_to_debug)
|
449
|
+
|
450
|
+
if __name__ == "__main__":
|
451
|
+
run_aggregate_human_stats()
|
@@ -12,7 +12,8 @@ from hockey_blast_common_lib.db_connection import create_session
|
|
12
12
|
from sqlalchemy.sql import func, case
|
13
13
|
from hockey_blast_common_lib.options import parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, MIN_GAMES_FOR_LEVEL_STATS, not_human_names
|
14
14
|
from hockey_blast_common_lib.utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
|
15
|
-
from hockey_blast_common_lib.
|
15
|
+
from hockey_blast_common_lib.utils import assign_ranks
|
16
|
+
from hockey_blast_common_lib.utils import get_start_datetime
|
16
17
|
|
17
18
|
def aggregate_referee_stats(session, aggregation_type, aggregation_id, names_to_filter_out, aggregation_window=None):
|
18
19
|
human_ids_to_filter = get_human_ids_by_names(session, names_to_filter_out)
|
@@ -50,18 +51,11 @@ def aggregate_referee_stats(session, aggregation_type, aggregation_id, names_to_
|
|
50
51
|
|
51
52
|
# Apply aggregation window filter
|
52
53
|
if aggregation_window:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
elif aggregation_window == 'Weekly':
|
59
|
-
start_datetime = last_game_datetime - timedelta(weeks=1)
|
60
|
-
else:
|
61
|
-
start_datetime = None
|
62
|
-
if start_datetime:
|
63
|
-
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
|
64
|
-
filter_condition = filter_condition & game_window_filter
|
54
|
+
last_game_datetime_str = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, Game.status.like('Final%')).scalar()
|
55
|
+
start_datetime = get_start_datetime(last_game_datetime_str, aggregation_window)
|
56
|
+
if start_datetime:
|
57
|
+
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime_str)
|
58
|
+
filter_condition = filter_condition & game_window_filter
|
65
59
|
|
66
60
|
# Delete existing items from the stats table
|
67
61
|
session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
|
@@ -197,12 +191,9 @@ def aggregate_referee_stats(session, aggregation_type, aggregation_id, names_to_
|
|
197
191
|
# Commit in batches
|
198
192
|
if i % batch_size == 0:
|
199
193
|
session.commit()
|
200
|
-
print(f"\r{i}/{total_items} ({(i/total_items)*100:.2f}%)", end="")
|
201
194
|
session.commit()
|
202
|
-
print(f"\r{total_items}/{total_items} (100.00%)")
|
203
|
-
print("\nDone.")
|
204
195
|
|
205
|
-
|
196
|
+
def run_aggregate_referee_stats():
|
206
197
|
session = create_session("boss")
|
207
198
|
human_id_to_debug = None
|
208
199
|
|
@@ -238,4 +229,7 @@ if __name__ == "__main__":
|
|
238
229
|
if human_id_to_debug is None:
|
239
230
|
print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
|
240
231
|
processed_levels += 1
|
241
|
-
aggregate_referee_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names)
|
232
|
+
aggregate_referee_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names)
|
233
|
+
|
234
|
+
if __name__ == "__main__":
|
235
|
+
run_aggregate_referee_stats()
|
@@ -12,6 +12,7 @@ from hockey_blast_common_lib.db_connection import create_session
|
|
12
12
|
from sqlalchemy.sql import func, case
|
13
13
|
from hockey_blast_common_lib.options import not_human_names, parse_args, MIN_GAMES_FOR_ORG_STATS, MIN_GAMES_FOR_DIVISION_STATS, MIN_GAMES_FOR_LEVEL_STATS
|
14
14
|
from hockey_blast_common_lib.utils import get_org_id_from_alias, get_human_ids_by_names, get_division_ids_for_last_season_in_all_leagues, get_all_division_ids_for_org
|
15
|
+
from hockey_blast_common_lib.utils import get_start_datetime
|
15
16
|
from sqlalchemy import func, case, and_
|
16
17
|
from collections import defaultdict
|
17
18
|
|
@@ -21,6 +22,9 @@ def aggregate_skater_stats(session, aggregation_type, aggregation_id, names_to_f
|
|
21
22
|
# Get the name of the aggregation, for debug purposes
|
22
23
|
if aggregation_type == 'org':
|
23
24
|
aggregation_name = session.query(Organization).filter(Organization.id == aggregation_id).first().organization_name
|
25
|
+
print(f"Aggregating skater stats for {aggregation_name} with window {aggregation_window}...")
|
26
|
+
|
27
|
+
aggregation_name = session.query(Organization).filter(Organization.id == aggregation_id).first().organization_name
|
24
28
|
elif aggregation_type == 'division':
|
25
29
|
aggregation_name = session.query(Division).filter(Division.id == aggregation_id).first().level
|
26
30
|
elif aggregation_type == 'level':
|
@@ -59,18 +63,11 @@ def aggregate_skater_stats(session, aggregation_type, aggregation_id, names_to_f
|
|
59
63
|
|
60
64
|
# Apply aggregation window filter
|
61
65
|
if aggregation_window:
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
elif aggregation_window == 'Weekly':
|
68
|
-
start_datetime = last_game_datetime - timedelta(weeks=1)
|
69
|
-
else:
|
70
|
-
start_datetime = None
|
71
|
-
if start_datetime:
|
72
|
-
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime)
|
73
|
-
filter_condition = filter_condition & game_window_filter
|
66
|
+
last_game_datetime_str = session.query(func.max(func.concat(Game.date, ' ', Game.time))).filter(filter_condition, Game.status.like('Final%')).scalar()
|
67
|
+
start_datetime = get_start_datetime(last_game_datetime_str, aggregation_window)
|
68
|
+
if start_datetime:
|
69
|
+
game_window_filter = func.cast(func.concat(Game.date, ' ', Game.time), sqlalchemy.types.TIMESTAMP).between(start_datetime, last_game_datetime_str)
|
70
|
+
filter_condition = filter_condition & game_window_filter
|
74
71
|
|
75
72
|
# Delete existing items from the stats table
|
76
73
|
session.query(StatsModel).filter(StatsModel.aggregation_id == aggregation_id).delete()
|
@@ -254,16 +251,11 @@ def aggregate_skater_stats(session, aggregation_type, aggregation_id, names_to_f
|
|
254
251
|
# Commit in batches
|
255
252
|
if i % batch_size == 0:
|
256
253
|
session.commit()
|
257
|
-
if debug_human_id is None:
|
258
|
-
print(f"\r{i}/{total_items} ({(i/total_items)*100:.2f}%)", end="")
|
259
|
-
|
260
254
|
session.commit()
|
261
|
-
if debug_human_id is None:
|
262
|
-
print(f"\r{total_items}/{total_items} (100.00%)")
|
263
255
|
|
264
|
-
|
256
|
+
def run_aggregate_skater_stats():
|
265
257
|
session = create_session("boss")
|
266
|
-
human_id_to_debug =
|
258
|
+
human_id_to_debug = None
|
267
259
|
|
268
260
|
# Get all org_id present in the Organization table
|
269
261
|
org_ids = session.query(Organization.id).all()
|
@@ -298,3 +290,6 @@ if __name__ == "__main__":
|
|
298
290
|
print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
|
299
291
|
processed_levels += 1
|
300
292
|
aggregate_skater_stats(session, aggregation_type='level', aggregation_id=level_id, names_to_filter_out=not_human_names, debug_human_id=human_id_to_debug)
|
293
|
+
|
294
|
+
if __name__ == "__main__":
|
295
|
+
run_aggregate_skater_stats()
|
Binary file
|
@@ -224,6 +224,7 @@ class Organization(db.Model):
|
|
224
224
|
id = db.Column(db.Integer, primary_key=True)
|
225
225
|
alias = db.Column(db.String(100), unique=True)
|
226
226
|
organization_name = db.Column(db.String(100), unique=True)
|
227
|
+
website = db.Column(db.String(100), nullable=True)
|
227
228
|
|
228
229
|
class Penalty(db.Model):
|
229
230
|
__tablename__ = 'penalties'
|
@@ -7,6 +7,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
7
7
|
|
8
8
|
from hockey_blast_common_lib.models import Game, Division, Level, Season, League
|
9
9
|
from hockey_blast_common_lib.db_connection import create_session
|
10
|
+
from hockey_blast_common_lib.utils import get_fake_skill
|
10
11
|
|
11
12
|
def analyze_levels(org):
|
12
13
|
session = create_session(org)
|
@@ -76,22 +77,6 @@ def fill_seed_skills():
|
|
76
77
|
|
77
78
|
print("Seed skills have been populated into the database.")
|
78
79
|
|
79
|
-
def get_fake_skill(session):
|
80
|
-
# Create a special fake Skill with org_id == -1 and skill_value == -1
|
81
|
-
fake_skill = session.query(Level).filter_by(org_id=1, level_name='Fake Skill').first()
|
82
|
-
if not fake_skill:
|
83
|
-
fake_skill = Level(
|
84
|
-
org_id=1,
|
85
|
-
skill_value=-1,
|
86
|
-
level_name='Fake Skill',
|
87
|
-
level_alternative_name='',
|
88
|
-
is_seed=False
|
89
|
-
)
|
90
|
-
session.add(fake_skill)
|
91
|
-
session.commit()
|
92
|
-
print("Created special fake Skill record.")
|
93
|
-
return fake_skill
|
94
|
-
|
95
80
|
def assign_fake_skill_to_divisions(session, fake_skill):
|
96
81
|
# Assign the special fake Skill to every existing Division
|
97
82
|
divisions = session.query(Division).all()
|
hockey_blast_common_lib/utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import sys
|
2
2
|
import os
|
3
|
+
from datetime import datetime, timedelta
|
3
4
|
|
4
5
|
# Add the package directory to the Python path
|
5
6
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
@@ -11,9 +12,9 @@ from sqlalchemy.sql import func
|
|
11
12
|
def get_org_id_from_alias(session, org_alias):
|
12
13
|
# Predefined organizations
|
13
14
|
predefined_organizations = [
|
14
|
-
{"id": 1, "organization_name": "Sharks Ice", "alias": "sharksice"},
|
15
|
-
{"id": 2, "organization_name": "TriValley Ice", "alias": "tvice"},
|
16
|
-
{"id": 3, "organization_name": "CAHA", "alias": "caha"}
|
15
|
+
{"id": 1, "organization_name": "Sharks Ice", "alias": "sharksice", "website": "https://www.sharksice.com"},
|
16
|
+
{"id": 2, "organization_name": "TriValley Ice", "alias": "tvice", "website": "https://www.trivalleyice.com"},
|
17
|
+
{"id": 3, "organization_name": "CAHA", "alias": "caha", "website": "https://www.caha.com"}
|
17
18
|
]
|
18
19
|
|
19
20
|
# Check if the organization exists
|
@@ -25,7 +26,7 @@ def get_org_id_from_alias(session, org_alias):
|
|
25
26
|
for org in predefined_organizations:
|
26
27
|
existing_org = session.query(Organization).filter_by(id=org["id"]).first()
|
27
28
|
if not existing_org:
|
28
|
-
new_org = Organization(id=org["id"], organization_name=org["organization_name"], alias=org["alias"])
|
29
|
+
new_org = Organization(id=org["id"], organization_name=org["organization_name"], alias=org["alias"], website=org["website"])
|
29
30
|
session.add(new_org)
|
30
31
|
session.commit()
|
31
32
|
|
@@ -82,6 +83,37 @@ def get_fake_human_for_stats(session):
|
|
82
83
|
|
83
84
|
return human.id
|
84
85
|
|
86
|
+
def get_start_datetime(last_game_datetime_str, aggregation_window):
|
87
|
+
if last_game_datetime_str:
|
88
|
+
last_game_datetime = datetime.strptime(last_game_datetime_str, '%Y-%m-%d %H:%M:%S')
|
89
|
+
if aggregation_window == 'Daily':
|
90
|
+
# From 10AM till midnight, 14 hours to avoid last day games
|
91
|
+
return last_game_datetime - timedelta(hours=14)
|
92
|
+
elif aggregation_window == 'Weekly':
|
93
|
+
return last_game_datetime - timedelta(weeks=1)
|
94
|
+
return None
|
95
|
+
|
96
|
+
def assign_ranks(stats_dict, field, reverse_rank=False):
|
97
|
+
sorted_stats = sorted(stats_dict.items(), key=lambda x: x[1][field], reverse=not reverse_rank)
|
98
|
+
for rank, (key, stat) in enumerate(sorted_stats, start=1):
|
99
|
+
stats_dict[key][f'{field}_rank'] = rank
|
100
|
+
|
101
|
+
def get_fake_skill(session):
|
102
|
+
# Create a special fake Skill with org_id == -1 and skill_value == -1
|
103
|
+
fake_skill = session.query(Level).filter_by(org_id=1, level_name='Fake Skill').first()
|
104
|
+
if not fake_skill:
|
105
|
+
fake_skill = Level(
|
106
|
+
org_id=1,
|
107
|
+
skill_value=-1,
|
108
|
+
level_name='Fake Skill',
|
109
|
+
level_alternative_name='',
|
110
|
+
is_seed=False
|
111
|
+
)
|
112
|
+
session.add(fake_skill)
|
113
|
+
session.commit()
|
114
|
+
print("Created special fake Skill record.")
|
115
|
+
return fake_skill
|
116
|
+
|
85
117
|
#TEST DB CONNECTION, PERMISSIONS...
|
86
118
|
# from hockey_blast_common_lib.db_connection import create_session
|
87
119
|
# session = create_session("frontend")
|
@@ -0,0 +1,23 @@
|
|
1
|
+
hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
hockey_blast_common_lib/aggregate_all_stats.py,sha256=MUjT23mdOMfCTx-kRSY-LGrLHZ9HNlR6OMqv5KLdzR4,1056
|
3
|
+
hockey_blast_common_lib/aggregate_goalie_stats.py,sha256=xDjCYaGLXh5UgkhoUvWKcsnv__QmbCzqLvYNHREFyFY,11937
|
4
|
+
hockey_blast_common_lib/aggregate_human_stats.py,sha256=di3h_nQjgMaNnGDPW6LQavnrYOxnZDMohNZEh3ixYNM,23700
|
5
|
+
hockey_blast_common_lib/aggregate_referee_stats.py,sha256=ATKBId0Hhzy0FVGmAFDTMgRftYNBDOOA9Z2yPhFA06U,11546
|
6
|
+
hockey_blast_common_lib/aggregate_skater_stats.py,sha256=LY6temy5zzqJ85ENymt9nEfpKHqL8Isk_kozfWqHNFI,15803
|
7
|
+
hockey_blast_common_lib/assign_skater_skill.py,sha256=p-0fbodGpM8BCjKHDpxNb7BH2FcIlBsJwON844KNrUY,1817
|
8
|
+
hockey_blast_common_lib/db_connection.py,sha256=HvPxDvOj7j5H85RfslGvHVNevfg7mKCd0syJ6NX21mU,1890
|
9
|
+
hockey_blast_common_lib/dump_sample_db.sh,sha256=MHPA-Ciod7wsvAlMbRtXFiyajgnEqU1xR59sJQ9UWR0,738
|
10
|
+
hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz,sha256=tBb-6pB9cDL3KyDJHiYzpbzRI-wsG6UMgCxbH6VZnNw,1033693
|
11
|
+
hockey_blast_common_lib/models.py,sha256=WLFPFoI3Rr_M58Vn8Ear2GrKW0bYPmBZFpYNb_sVRls,16039
|
12
|
+
hockey_blast_common_lib/options.py,sha256=6na8fo-5A2RBPpd_h-7dsqetOLSLoNEJg1QMYgl4jNs,792
|
13
|
+
hockey_blast_common_lib/restore_sample_db.sh,sha256=u2zKazC6vNMULkpYzI64nlneCWaGUtDHPBAU-gWgRbw,1861
|
14
|
+
hockey_blast_common_lib/skills_in_divisions.py,sha256=o7JiZkLBJcnn6J7nD2Pqt5bAhZofasXpfHB3uHe2huI,7005
|
15
|
+
hockey_blast_common_lib/skills_propagation.py,sha256=x6yy7fJ6IX3YiHqiP_v7-p_S2Expb8JJ-mWuajEFBdY,16388
|
16
|
+
hockey_blast_common_lib/stats_models.py,sha256=qvkt-XRFb4ZW7yBj7vltedzUS_YwWagm_efMRcsioSA,25120
|
17
|
+
hockey_blast_common_lib/stats_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
+
hockey_blast_common_lib/utils.py,sha256=MgodsQYxssUE5Oaqq87-YBDQN22n5OYYbgKT65cCq98,5228
|
19
|
+
hockey_blast_common_lib/wsgi.py,sha256=7LGUzioigviJp-EUhSEaQcd4jBae0mxbkyBscQfZhlc,730
|
20
|
+
hockey_blast_common_lib-0.1.35.dist-info/METADATA,sha256=WaYlunsVftS-1sn_uq3HPjlhUG-bOhUsBSOchAw5Pb0,318
|
21
|
+
hockey_blast_common_lib-0.1.35.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
22
|
+
hockey_blast_common_lib-0.1.35.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
|
23
|
+
hockey_blast_common_lib-0.1.35.dist-info/RECORD,,
|
@@ -1,22 +0,0 @@
|
|
1
|
-
hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
hockey_blast_common_lib/aggregate_goalie_stats.py,sha256=GRlKfZcfQWLHfeVZjHSG4uc9RNVttJaOC9_-VncqDP8,12190
|
3
|
-
hockey_blast_common_lib/aggregate_human_stats.py,sha256=BlG-TDPEJyUsx3mYxEt50pVgCftCr1r9L0u5q9Zf4BU,23958
|
4
|
-
hockey_blast_common_lib/aggregate_referee_stats.py,sha256=BmvEiewtwT5z4GMrmhNKIPWDxPtFHLMuUZ_UNucu0YQ,11910
|
5
|
-
hockey_blast_common_lib/aggregate_skater_stats.py,sha256=jkBD5u-gJc1DTDIEuxM_qymKsrWtLagFKeEn__2rFgU,16009
|
6
|
-
hockey_blast_common_lib/assign_skater_skill.py,sha256=p-0fbodGpM8BCjKHDpxNb7BH2FcIlBsJwON844KNrUY,1817
|
7
|
-
hockey_blast_common_lib/db_connection.py,sha256=HvPxDvOj7j5H85RfslGvHVNevfg7mKCd0syJ6NX21mU,1890
|
8
|
-
hockey_blast_common_lib/dump_sample_db.sh,sha256=MHPA-Ciod7wsvAlMbRtXFiyajgnEqU1xR59sJQ9UWR0,738
|
9
|
-
hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz,sha256=fO5SsdPB6XYptPLx1rD2VVSTySLnJmyubeSS0A0HGyw,1033692
|
10
|
-
hockey_blast_common_lib/models.py,sha256=ebRnnvDOVNDfqAp8CA8u7uk3LCOfI3iUwOpHgzoBy0U,15984
|
11
|
-
hockey_blast_common_lib/options.py,sha256=6na8fo-5A2RBPpd_h-7dsqetOLSLoNEJg1QMYgl4jNs,792
|
12
|
-
hockey_blast_common_lib/restore_sample_db.sh,sha256=u2zKazC6vNMULkpYzI64nlneCWaGUtDHPBAU-gWgRbw,1861
|
13
|
-
hockey_blast_common_lib/skills_in_divisions.py,sha256=RR-x-D7V_lQX--2a2GHEYHtATtIOj2ACpvcEUDzVgkY,7487
|
14
|
-
hockey_blast_common_lib/skills_propagation.py,sha256=x6yy7fJ6IX3YiHqiP_v7-p_S2Expb8JJ-mWuajEFBdY,16388
|
15
|
-
hockey_blast_common_lib/stats_models.py,sha256=qvkt-XRFb4ZW7yBj7vltedzUS_YwWagm_efMRcsioSA,25120
|
16
|
-
hockey_blast_common_lib/stats_utils.py,sha256=Uv7xv9Eph2g7kQFOpTJujMm8P-UB42IDbAw5WkjJA0g,267
|
17
|
-
hockey_blast_common_lib/utils.py,sha256=odDJWCK0BgbResXeoUzxbVChjaxcXr168ZxbrAw3L_8,3752
|
18
|
-
hockey_blast_common_lib/wsgi.py,sha256=7LGUzioigviJp-EUhSEaQcd4jBae0mxbkyBscQfZhlc,730
|
19
|
-
hockey_blast_common_lib-0.1.33.dist-info/METADATA,sha256=AqXHHG_rYxzkm7oBWB7W1Ew94nm51nTCN1YCetrOX6Q,318
|
20
|
-
hockey_blast_common_lib-0.1.33.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
21
|
-
hockey_blast_common_lib-0.1.33.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
|
22
|
-
hockey_blast_common_lib-0.1.33.dist-info/RECORD,,
|
File without changes
|
{hockey_blast_common_lib-0.1.33.dist-info → hockey_blast_common_lib-0.1.35.dist-info}/top_level.txt
RENAMED
File without changes
|