hockey-blast-common-lib 0.1.63__py3-none-any.whl → 0.1.64__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.
Files changed (26) hide show
  1. hockey_blast_common_lib/aggregate_all_stats.py +7 -4
  2. hockey_blast_common_lib/aggregate_goalie_stats.py +301 -107
  3. hockey_blast_common_lib/aggregate_h2h_stats.py +64 -33
  4. hockey_blast_common_lib/aggregate_human_stats.py +565 -280
  5. hockey_blast_common_lib/aggregate_referee_stats.py +286 -135
  6. hockey_blast_common_lib/aggregate_s2s_stats.py +85 -25
  7. hockey_blast_common_lib/aggregate_scorekeeper_stats.py +228 -113
  8. hockey_blast_common_lib/aggregate_skater_stats.py +561 -238
  9. hockey_blast_common_lib/assign_skater_skill.py +21 -11
  10. hockey_blast_common_lib/db_connection.py +59 -8
  11. hockey_blast_common_lib/embedding_utils.py +309 -0
  12. hockey_blast_common_lib/h2h_models.py +150 -56
  13. hockey_blast_common_lib/models.py +305 -150
  14. hockey_blast_common_lib/options.py +30 -15
  15. hockey_blast_common_lib/progress_utils.py +21 -13
  16. hockey_blast_common_lib/skills_in_divisions.py +170 -33
  17. hockey_blast_common_lib/skills_propagation.py +164 -70
  18. hockey_blast_common_lib/stats_models.py +489 -245
  19. hockey_blast_common_lib/stats_utils.py +6 -3
  20. hockey_blast_common_lib/utils.py +89 -25
  21. hockey_blast_common_lib/wsgi.py +7 -5
  22. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/METADATA +1 -1
  23. hockey_blast_common_lib-0.1.64.dist-info/RECORD +29 -0
  24. hockey_blast_common_lib-0.1.63.dist-info/RECORD +0 -28
  25. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/WHEEL +0 -0
  26. {hockey_blast_common_lib-0.1.63.dist-info → hockey_blast_common_lib-0.1.64.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,9 @@
1
1
  def assign_ranks(stats_dict, field, reverse_rank=False):
2
- sorted_stats = sorted(stats_dict.items(), key=lambda x: x[1][field], reverse=not reverse_rank)
2
+ sorted_stats = sorted(
3
+ stats_dict.items(), key=lambda x: x[1][field], reverse=not reverse_rank
4
+ )
3
5
  for rank, (key, stat) in enumerate(sorted_stats, start=1):
4
- stats_dict[key][f'{field}_rank'] = rank
6
+ stats_dict[key][f"{field}_rank"] = rank
5
7
 
6
- ALL_ORGS_ID = -1
8
+
9
+ ALL_ORGS_ID = -1
@@ -1,21 +1,42 @@
1
- import sys
2
1
  import os
2
+ import sys
3
3
  from datetime import datetime, timedelta
4
4
 
5
5
  # Add the package directory to the Python path
6
6
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7
7
 
8
- from hockey_blast_common_lib.models import Organization, Human, Division, Level
9
8
  from sqlalchemy.sql import func
10
9
 
10
+ from hockey_blast_common_lib.models import Division, Human, Level, Organization
11
+
11
12
 
12
13
  def get_org_id_from_alias(session, org_alias):
13
14
  # Predefined organizations
14
15
  predefined_organizations = [
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"},
18
- {"id": 4, "organization_name": "Tacoma Twin Rinks", "alias": "ttr", "website": "https://psicesports.com"},
16
+ {
17
+ "id": 1,
18
+ "organization_name": "Sharks Ice",
19
+ "alias": "sharksice",
20
+ "website": "https://www.sharksice.com",
21
+ },
22
+ {
23
+ "id": 2,
24
+ "organization_name": "TriValley Ice",
25
+ "alias": "tvice",
26
+ "website": "https://www.trivalleyice.com",
27
+ },
28
+ {
29
+ "id": 3,
30
+ "organization_name": "CAHA",
31
+ "alias": "caha",
32
+ "website": "https://www.caha.com",
33
+ },
34
+ {
35
+ "id": 4,
36
+ "organization_name": "Tacoma Twin Rinks",
37
+ "alias": "ttr",
38
+ "website": "https://psicesports.com",
39
+ },
19
40
  ]
20
41
 
21
42
  # Check if the organization exists
@@ -27,7 +48,12 @@ def get_org_id_from_alias(session, org_alias):
27
48
  for org in predefined_organizations:
28
49
  existing_org = session.query(Organization).filter_by(id=org["id"]).first()
29
50
  if not existing_org:
30
- new_org = Organization(id=org["id"], organization_name=org["organization_name"], alias=org["alias"], website=org["website"])
51
+ new_org = Organization(
52
+ id=org["id"],
53
+ organization_name=org["organization_name"],
54
+ alias=org["alias"],
55
+ website=org["website"],
56
+ )
31
57
  session.add(new_org)
32
58
  session.commit()
33
59
 
@@ -38,6 +64,7 @@ def get_org_id_from_alias(session, org_alias):
38
64
  else:
39
65
  raise ValueError(f"Organization with alias '{org_alias}' not found.")
40
66
 
67
+
41
68
  def get_human_ids_by_names(session, names):
42
69
  human_ids = set()
43
70
  for first_name, middle_name, last_name in names:
@@ -52,6 +79,7 @@ def get_human_ids_by_names(session, names):
52
79
  human_ids.update([result.id for result in results])
53
80
  return human_ids
54
81
 
82
+
55
83
  def get_non_human_ids(session):
56
84
  """Get IDs of non-human entities (placeholder names, test accounts, etc.)
57
85
 
@@ -66,32 +94,56 @@ def get_non_human_ids(session):
66
94
  (None, None, "Goalie"),
67
95
  ("Unassigned", None, None),
68
96
  ("Not", "Signed", "In"),
69
- ("Incognito", None, None)
97
+ ("Incognito", None, None),
70
98
  ]
71
99
  return get_human_ids_by_names(session, not_human_names)
72
100
 
101
+
73
102
  def get_division_ids_for_last_season_in_all_leagues(session, org_id):
74
103
  # # TODO = remove tmp hack
75
104
  # return get_all_division_ids_for_org(session, org_id)
76
- league_numbers = session.query(Division.league_number).filter(Division.org_id == org_id).distinct().all()
105
+ league_numbers = (
106
+ session.query(Division.league_number)
107
+ .filter(Division.org_id == org_id)
108
+ .distinct()
109
+ .all()
110
+ )
77
111
  division_ids = []
78
- for league_number, in league_numbers:
79
- max_season_number = session.query(func.max(Division.season_number)).filter_by(league_number=league_number, org_id=org_id).scalar()
80
- division_ids_for_league = session.query(Division.id).filter_by(league_number=league_number, season_number=max_season_number, org_id=org_id).all()
112
+ for (league_number,) in league_numbers:
113
+ max_season_number = (
114
+ session.query(func.max(Division.season_number))
115
+ .filter_by(league_number=league_number, org_id=org_id)
116
+ .scalar()
117
+ )
118
+ division_ids_for_league = (
119
+ session.query(Division.id)
120
+ .filter_by(
121
+ league_number=league_number,
122
+ season_number=max_season_number,
123
+ org_id=org_id,
124
+ )
125
+ .all()
126
+ )
81
127
  division_ids.extend([division_id.id for division_id in division_ids_for_league])
82
128
  return division_ids
83
129
 
130
+
84
131
  def get_all_division_ids_for_org(session, org_id):
85
132
  division_ids_for_org = session.query(Division.id).filter_by(org_id=org_id).all()
86
133
  return [division_id.id for division_id in division_ids_for_org]
87
134
 
135
+
88
136
  def get_fake_human_for_stats(session):
89
137
  first_name = "Fake"
90
138
  middle_name = "Stats"
91
139
  last_name = "Human"
92
140
 
93
141
  # Check if the human already exists
94
- existing_human = session.query(Human).filter_by(first_name=first_name, middle_name=middle_name, last_name=last_name).first()
142
+ existing_human = (
143
+ session.query(Human)
144
+ .filter_by(first_name=first_name, middle_name=middle_name, last_name=last_name)
145
+ .first()
146
+ )
95
147
  if existing_human:
96
148
  return existing_human.id
97
149
 
@@ -102,18 +154,23 @@ def get_fake_human_for_stats(session):
102
154
 
103
155
  return human.id
104
156
 
157
+
105
158
  def get_start_datetime(last_game_datetime_str, aggregation_window):
106
- if aggregation_window == 'Weekly':
159
+ if aggregation_window == "Weekly":
107
160
  if last_game_datetime_str:
108
- last_game_datetime = datetime.strptime(last_game_datetime_str, '%Y-%m-%d %H:%M:%S')
161
+ last_game_datetime = datetime.strptime(
162
+ last_game_datetime_str, "%Y-%m-%d %H:%M:%S"
163
+ )
109
164
  # Check if the last game datetime is over 1 week from now
110
165
  if datetime.now() - last_game_datetime > timedelta(weeks=1):
111
166
  return None
112
167
  # Use current time as the start of the weekly window
113
168
  return datetime.now() - timedelta(weeks=1)
114
169
  if last_game_datetime_str:
115
- last_game_datetime = datetime.strptime(last_game_datetime_str, '%Y-%m-%d %H:%M:%S')
116
- if aggregation_window == 'Daily':
170
+ last_game_datetime = datetime.strptime(
171
+ last_game_datetime_str, "%Y-%m-%d %H:%M:%S"
172
+ )
173
+ if aggregation_window == "Daily":
117
174
  # Check if the last game datetime is over 24 hours from now
118
175
  if datetime.now() - last_game_datetime > timedelta(hours=24):
119
176
  return None
@@ -121,29 +178,36 @@ def get_start_datetime(last_game_datetime_str, aggregation_window):
121
178
  return last_game_datetime - timedelta(hours=14)
122
179
  return None
123
180
 
181
+
124
182
  def assign_ranks(stats_dict, field, reverse_rank=False):
125
- sorted_stats = sorted(stats_dict.items(), key=lambda x: x[1][field], reverse=not reverse_rank)
183
+ sorted_stats = sorted(
184
+ stats_dict.items(), key=lambda x: x[1][field], reverse=not reverse_rank
185
+ )
126
186
  for rank, (key, stat) in enumerate(sorted_stats, start=1):
127
- stats_dict[key][f'{field}_rank'] = rank
187
+ stats_dict[key][f"{field}_rank"] = rank
188
+
128
189
 
129
190
  def get_fake_level(session):
130
191
  # Create a special fake Skill with org_id == -1 and skill_value == -1
131
- fake_skill = session.query(Level).filter_by(org_id=1, level_name='Fake Skill').first()
192
+ fake_skill = (
193
+ session.query(Level).filter_by(org_id=1, level_name="Fake Skill").first()
194
+ )
132
195
  if not fake_skill:
133
196
  fake_skill = Level(
134
197
  org_id=1,
135
198
  skill_value=-1,
136
- level_name='Fake Skill',
137
- level_alternative_name='',
138
- is_seed=False
199
+ level_name="Fake Skill",
200
+ level_alternative_name="",
201
+ is_seed=False,
139
202
  )
140
203
  session.add(fake_skill)
141
204
  session.commit()
142
205
  print("Created special fake Skill record.")
143
206
  return fake_skill
144
207
 
145
- #TEST DB CONNECTION, PERMISSIONS...
208
+
209
+ # TEST DB CONNECTION, PERMISSIONS...
146
210
  # from hockey_blast_common_lib.db_connection import create_session
147
211
  # session = create_session("frontend")
148
212
  # human_id = get_fake_human_for_stats(session)
149
- # print(f"Human ID: {human_id}")
213
+ # print(f"Human ID: {human_id}")
@@ -1,20 +1,22 @@
1
- import sys, os
1
+ import os
2
+ import sys
2
3
 
3
4
  # Add the package directory to the Python path
4
5
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5
6
 
6
- from flask_migrate import Migrate
7
7
  from flask import Flask
8
- from hockey_blast_common_lib.models import *
8
+ from flask_migrate import Migrate
9
+
10
+ from hockey_blast_common_lib.db_connection import get_db_params
9
11
  from hockey_blast_common_lib.h2h_models import *
12
+ from hockey_blast_common_lib.models import *
10
13
  from hockey_blast_common_lib.stats_models import *
11
14
  from hockey_blast_common_lib.stats_models import db
12
- from hockey_blast_common_lib.db_connection import get_db_params
13
15
 
14
16
  app = Flask(__name__)
15
17
  db_params = get_db_params("boss")
16
18
  db_url = f"postgresql://{db_params['user']}:{db_params['password']}@{db_params['host']}:{db_params['port']}/{db_params['dbname']}"
17
- app.config['SQLALCHEMY_DATABASE_URI'] = db_url
19
+ app.config["SQLALCHEMY_DATABASE_URI"] = db_url
18
20
 
19
21
  db.init_app(app)
20
22
  migrate = Migrate(app, db)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hockey-blast-common-lib
3
- Version: 0.1.63
3
+ Version: 0.1.64
4
4
  Summary: Common library for shared functionality and DB models
5
5
  Author: Pavel Kletskov
6
6
  Author-email: kletskov@gmail.com
@@ -0,0 +1,29 @@
1
+ hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ hockey_blast_common_lib/aggregate_all_stats.py,sha256=ozILLB3-CRABYN9JHeH2sFeXw-sFhkXboU7sKTV2Ok8,1378
3
+ hockey_blast_common_lib/aggregate_goalie_stats.py,sha256=QPza_glSHcggt0KTwVB6USTkvEdP3yZj7GjpNeGjFE8,17433
4
+ hockey_blast_common_lib/aggregate_h2h_stats.py,sha256=nStyIm_be25pKDYbPCaOSHFTjbaMLFxFAa2mTU1tL_k,11486
5
+ hockey_blast_common_lib/aggregate_human_stats.py,sha256=uoGBkROBKh8n18TyzZ6vHX_viCTpHbRsiVLyflJq92g,29247
6
+ hockey_blast_common_lib/aggregate_referee_stats.py,sha256=YyFFHU2FJnXyUEzkzMnJoa5O28zjtF_spJeGedaI4QA,17389
7
+ hockey_blast_common_lib/aggregate_s2s_stats.py,sha256=gB3Oi1emtBWL3bKojUhHH01gAbQTSLvgqO1WcvLI6F8,7449
8
+ hockey_blast_common_lib/aggregate_scorekeeper_stats.py,sha256=r0CUsOSjeKwAEanrPSkqVufkxk9Iv_c125mKdhwR9Ns,14758
9
+ hockey_blast_common_lib/aggregate_skater_stats.py,sha256=chy-LcuNIGHP85h0FiXZT3nZrbGKbcr66_j-atrucXs,30706
10
+ hockey_blast_common_lib/assign_skater_skill.py,sha256=it3jiSyUq7XpKqxzs88lyB5t1c3t1idIS_JRwq_FQoo,2810
11
+ hockey_blast_common_lib/db_connection.py,sha256=KACyHaOMeTX9zPNztYy8uOeB1ubIUenZcEKAeD5gC24,3333
12
+ hockey_blast_common_lib/dump_sample_db.sh,sha256=MY3lnzTXBoWd76-ZlZr9nWsKMEVgyRsUn-LZ2d1JWZs,810
13
+ hockey_blast_common_lib/embedding_utils.py,sha256=XbJvJlq6BKE6_oLzhUKcCrx6-TM8P-xl-S1SVLr_teU,10222
14
+ hockey_blast_common_lib/h2h_models.py,sha256=DEmQnmuacBVRNWvpRvq2RlwmhQYrT7XPOSTDNVtchr0,8597
15
+ hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz,sha256=u5lGgEUTbJddCd-y2hu8LsMRoZW0Ox_jNzWYqNR1sbc,4648908
16
+ hockey_blast_common_lib/models.py,sha256=RQGUq8C8eJqUB2o3QCSs14W-9B4lMTUNvwNDM-Lc6j4,21687
17
+ hockey_blast_common_lib/options.py,sha256=wzfGWKK_dHBA_PfiOvbP_-HtdoJCR0E7DkA5_cYDb_k,1578
18
+ hockey_blast_common_lib/progress_utils.py,sha256=7Txjpx5G4vHbnPTvNYuBA_WtrY0QFA4mDEYUDuZyY1E,3923
19
+ hockey_blast_common_lib/restore_sample_db.sh,sha256=7W3lzRZeu9zXIu1Bvtnaw8EHc1ulHmFM4mMh86oUQJo,2205
20
+ hockey_blast_common_lib/skills_in_divisions.py,sha256=9sGtU6SLj8BXb5R74ue1oPWa2nbk4JfJz5VmcuxetzA,8542
21
+ hockey_blast_common_lib/skills_propagation.py,sha256=qBK84nzkn8ZQHum0bdxFQwLvdgVE7DtWoPP9cdbOmRo,20201
22
+ hockey_blast_common_lib/stats_models.py,sha256=t4nBxEr__dPJlO005jKvwQRWdUJwoXsALtVmW3crtdM,31100
23
+ hockey_blast_common_lib/stats_utils.py,sha256=PTZvykl1zfEcojnzDFa1J3V3F5gREmoFG1lQHLnYHgo,300
24
+ hockey_blast_common_lib/utils.py,sha256=18ThTgXliIPwBPBNAY6jU9fLUpKaiOwvsr6xBGtj4vg,7159
25
+ hockey_blast_common_lib/wsgi.py,sha256=oL9lPWccKLTAYIKPJkKZV5keVE-Dgosv74CBi770NNc,786
26
+ hockey_blast_common_lib-0.1.64.dist-info/METADATA,sha256=Pmli4OSe-AKxoOz3Eb0kptBpyK2dALHREZiRbTK2bhQ,318
27
+ hockey_blast_common_lib-0.1.64.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
28
+ hockey_blast_common_lib-0.1.64.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
29
+ hockey_blast_common_lib-0.1.64.dist-info/RECORD,,
@@ -1,28 +0,0 @@
1
- hockey_blast_common_lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- hockey_blast_common_lib/aggregate_all_stats.py,sha256=QhuSvGjuk4jVywNRcgxB-9ooJAoAbZRkaLjLe9Q1hEM,1363
3
- hockey_blast_common_lib/aggregate_goalie_stats.py,sha256=J0hY5mK6UATScjqtPqbTfEeApnZy6lC3qlMGN02qhpY,14831
4
- hockey_blast_common_lib/aggregate_h2h_stats.py,sha256=dC5TcJZGkpIQTiq3z40kOX6EjEhFbGv5EL0P1EClBQ0,11117
5
- hockey_blast_common_lib/aggregate_human_stats.py,sha256=wRw0X_57-AUWHHn5SXRLovC7KQwQtTJm7Twb7XIQv_M,25560
6
- hockey_blast_common_lib/aggregate_referee_stats.py,sha256=zwMpQxq-tONNKSv87hwM_l94L1wBpu2ZVW-bvyV-zjY,15561
7
- hockey_blast_common_lib/aggregate_s2s_stats.py,sha256=urYN0Q06twwLO-XWGlSMVAVOTVR_D2AWdmoGsxIYHXE,6737
8
- hockey_blast_common_lib/aggregate_scorekeeper_stats.py,sha256=SBwZ6kBMbgsBgyiLIuCTmgRHpseqjIlqjvR63rBvyiY,13500
9
- hockey_blast_common_lib/aggregate_skater_stats.py,sha256=d_4PRCZw458FMp6Yv4_QM8hbkXAH_dkX5O3_jMtaoU8,26547
10
- hockey_blast_common_lib/assign_skater_skill.py,sha256=Asq6iRMPsCMDnvuNSd-M3s4Gee4kDocP9Eznwju_9kA,2749
11
- hockey_blast_common_lib/db_connection.py,sha256=HvPxDvOj7j5H85RfslGvHVNevfg7mKCd0syJ6NX21mU,1890
12
- hockey_blast_common_lib/dump_sample_db.sh,sha256=MY3lnzTXBoWd76-ZlZr9nWsKMEVgyRsUn-LZ2d1JWZs,810
13
- hockey_blast_common_lib/h2h_models.py,sha256=0st4xoJO0U6ONfx3BV03BQvHjZE31e_PqZfphAJMoSU,7968
14
- hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz,sha256=u5lGgEUTbJddCd-y2hu8LsMRoZW0Ox_jNzWYqNR1sbc,4648908
15
- hockey_blast_common_lib/models.py,sha256=rbpgLI6iol_Eh-zvL1jSVqA7t08H6aFQoSJvMzjp81U,19724
16
- hockey_blast_common_lib/options.py,sha256=XecGGlizbul7BnMePrvIqvEq5_w49UoG3Yu9iv961gg,1499
17
- hockey_blast_common_lib/progress_utils.py,sha256=7cqyUTMmW3xAIh5JKFlhnBiybCJ9WvGDz7ihH59Lc_0,3953
18
- hockey_blast_common_lib/restore_sample_db.sh,sha256=7W3lzRZeu9zXIu1Bvtnaw8EHc1ulHmFM4mMh86oUQJo,2205
19
- hockey_blast_common_lib/skills_in_divisions.py,sha256=m-UEwMwn1KM7wOYvDstgsOEeH57M9V6yrkBoghzGYKE,7005
20
- hockey_blast_common_lib/skills_propagation.py,sha256=nUxntyK8M4xWjHpkfze8f0suaBeunxicgDCduGmNJ-A,18468
21
- hockey_blast_common_lib/stats_models.py,sha256=yLfsR0RhSc95-8ULdJ8tuvLd6RjIFkgZ74ejubJYVUw,28187
22
- hockey_blast_common_lib/stats_utils.py,sha256=DXsPO4jw8XsdRUN46TGF_IiBAfz3GCIVBswCGp5ELDk,284
23
- hockey_blast_common_lib/utils.py,sha256=1YJRAj1lhftjIAM2frFi4A4K90kCJaxWlgBQ1-77xZY,6486
24
- hockey_blast_common_lib/wsgi.py,sha256=y3NxoJfWjdzX3iP7RGvDEer6zcnPyCanpqSgW1BlXgg,779
25
- hockey_blast_common_lib-0.1.63.dist-info/METADATA,sha256=VFQNc4UUo8qUlyk2Bd_kykrsxVYwclpckA2eq2OCTgc,318
26
- hockey_blast_common_lib-0.1.63.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
27
- hockey_blast_common_lib-0.1.63.dist-info/top_level.txt,sha256=wIR4LIkE40npoA2QlOdfCYlgFeGbsHR8Z6r0h46Vtgc,24
28
- hockey_blast_common_lib-0.1.63.dist-info/RECORD,,