hockey-blast-common-lib 0.1.45__tar.gz → 0.1.47__tar.gz

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 (31) hide show
  1. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/PKG-INFO +1 -1
  2. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/aggregate_all_stats.py +7 -7
  3. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/aggregate_human_stats.py +11 -11
  4. hockey_blast_common_lib-0.1.47/hockey_blast_common_lib/find_leagues_seasons.py +53 -0
  5. hockey_blast_common_lib-0.1.47/hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz +0 -0
  6. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/models.py +1 -1
  7. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/restore_sample_db.sh +12 -5
  8. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib.egg-info/PKG-INFO +1 -1
  9. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib.egg-info/SOURCES.txt +1 -0
  10. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/setup.py +1 -1
  11. hockey_blast_common_lib-0.1.45/hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz +0 -0
  12. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/MANIFEST.in +0 -0
  13. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/README.md +0 -0
  14. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/__init__.py +0 -0
  15. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/aggregate_goalie_stats.py +0 -0
  16. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/aggregate_referee_stats.py +0 -0
  17. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/aggregate_skater_stats.py +0 -0
  18. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/assign_skater_skill.py +0 -0
  19. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/db_connection.py +0 -0
  20. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/dump_sample_db.sh +0 -0
  21. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/options.py +0 -0
  22. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/skills_in_divisions.py +0 -0
  23. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/skills_propagation.py +0 -0
  24. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/stats_models.py +0 -0
  25. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/stats_utils.py +0 -0
  26. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/utils.py +0 -0
  27. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib/wsgi.py +0 -0
  28. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib.egg-info/dependency_links.txt +0 -0
  29. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib.egg-info/requires.txt +0 -0
  30. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/hockey_blast_common_lib.egg-info/top_level.txt +0 -0
  31. {hockey_blast_common_lib-0.1.45 → hockey_blast_common_lib-0.1.47}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hockey-blast-common-lib
3
- Version: 0.1.45
3
+ Version: 0.1.47
4
4
  Summary: Common library for shared functionality and DB models
5
5
  Author: Pavel Kletskov
6
6
  Author-email: kletskov@gmail.com
@@ -9,18 +9,18 @@ from hockey_blast_common_lib.aggregate_goalie_stats import run_aggregate_goalie_
9
9
  from hockey_blast_common_lib.aggregate_referee_stats import run_aggregate_referee_stats
10
10
 
11
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...")
12
+ print("Running aggregate_skater_stats...", flush=True)
17
13
  run_aggregate_skater_stats()
18
14
  print("Finished running aggregate_skater_stats\n")
19
15
 
20
- print("Running aggregate_goalie_stats...")
16
+ print("Running aggregate_goalie_stats...", flush=True)
21
17
  run_aggregate_goalie_stats()
22
18
  print("Finished running aggregate_goalie_stats\n")
23
19
 
24
- print("Running aggregate_referee_stats...")
20
+ print("Running aggregate_referee_stats...", flush=True)
25
21
  run_aggregate_referee_stats()
26
22
  print("Finished running aggregate_referee_stats\n")
23
+
24
+ print("Running aggregate_human_stats...", flush=True)
25
+ run_aggregate_human_stats()
26
+ print("Finished running aggregate_human_stats\n")
@@ -440,17 +440,17 @@ def run_aggregate_human_stats():
440
440
  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')
441
441
 
442
442
  # Aggregate by level
443
- # level_ids = session.query(Division.level_id).distinct().all()
444
- # level_ids = [level_id[0] for level_id in level_ids]
445
- # total_levels = len(level_ids)
446
- # processed_levels = 0
447
- # for level_id in level_ids:
448
- # if level_id is None:
449
- # continue
450
- # if human_id_to_debug is None:
451
- # print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
452
- # processed_levels += 1
453
- # 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)
443
+ level_ids = session.query(Division.level_id).distinct().all()
444
+ level_ids = [level_id[0] for level_id in level_ids]
445
+ total_levels = len(level_ids)
446
+ processed_levels = 0
447
+ for level_id in level_ids:
448
+ if level_id is None:
449
+ continue
450
+ if human_id_to_debug is None:
451
+ print(f"\rProcessed {processed_levels}/{total_levels} levels ({(processed_levels/total_levels)*100:.2f}%)", end="")
452
+ processed_levels += 1
453
+ 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)
454
454
 
455
455
  if __name__ == "__main__":
456
456
  run_aggregate_human_stats()
@@ -0,0 +1,53 @@
1
+ import time
2
+ import json
3
+ import os
4
+ import requests
5
+ from bs4 import BeautifulSoup
6
+
7
+ def probe_leagues_and_seasons(min_league, max_league, min_season, max_season, interval_seconds, output_file):
8
+ results = []
9
+
10
+ for league_id in range(min_league, max_league + 1):
11
+ league_data = {"league": league_id, "seasons": set()}
12
+ for season_id in range(min_season, max_season + 1):
13
+ url = f"https://stats.sharksice.timetoscore.com/display-schedule.php?stat_class=1&league={league_id}&season={season_id}"
14
+ print(f"Probing URL: {url}")
15
+
16
+ try:
17
+ response = requests.get(url, timeout=10)
18
+ response.raise_for_status()
19
+ schedule_html = response.text
20
+
21
+ # Parse the schedule page to find all game links
22
+ soup = BeautifulSoup(schedule_html, "html.parser")
23
+ tables = soup.find_all('table')
24
+ top_level_tables = [table for table in tables if table.find_parent('table') is None]
25
+
26
+ if len(top_level_tables) > 0:
27
+ print(f"Data found for league {league_id}, season {season_id}")
28
+ league_data["seasons"].add(season_id)
29
+
30
+ # Save the fetched HTML to a subfolder
31
+ folder_path = os.path.join("schedules", f"league={league_id}", f"season={season_id}")
32
+ os.makedirs(folder_path, exist_ok=True)
33
+ with open(os.path.join(folder_path, "schedule.html"), "w") as f:
34
+ f.write(schedule_html)
35
+ else:
36
+ print(f"No data for league {league_id}, season {season_id}")
37
+ except Exception as e:
38
+ print(f"Error probing URL {url}: {e}")
39
+
40
+ # Wait for the specified interval before the next request
41
+ time.sleep(interval_seconds)
42
+
43
+ if league_data["seasons"]:
44
+ league_data["seasons"] = list(league_data["seasons"]) # Convert set to list for JSON serialization
45
+ results.append(league_data)
46
+
47
+ # Save results to a JSON file
48
+ with open(output_file, "w") as f:
49
+ json.dump(results, f, indent=4)
50
+ print(f"Results saved to {output_file}")
51
+
52
+ # Example usage
53
+ probe_leagues_and_seasons(min_league=1, max_league=70, min_season=1, max_season=70, interval_seconds=9, output_file="leagues_seasons_2_70_1_70.json")
@@ -18,7 +18,7 @@ class Division(db.Model):
18
18
  league_number = db.Column(db.Integer) # TODO: Deprecate usage and remove (get this info through Season->League)
19
19
  season_number = db.Column(db.Integer) # TODO: Deprecate usage and remove (get this info from Season by season_id)
20
20
  season_id = db.Column(db.Integer, db.ForeignKey('seasons.id'))
21
- level = db.Column(db.String(100)) # Obsolete, use skill_id instead
21
+ level = db.Column(db.String(100)) # Used to display original level name, however level_id may combine some levels with different name!
22
22
  level_id = db.Column(db.Integer, db.ForeignKey('levels.id')) # New field
23
23
  org_id = db.Column(db.Integer, db.ForeignKey('organizations.id'), nullable=False)
24
24
  __table_args__ = (
@@ -9,15 +9,22 @@ DB_PORT=${DB_PORT:-"5432"}
9
9
  COMPRESSED_DUMP_FILE="hockey_blast_sample_backup.sql.gz"
10
10
 
11
11
  # Superuser credentials
12
- SUPERUSER="boss"
13
- SUPERUSER_PASSWORD=${DB_PASSWORD_BOSS:-"your_superuser_password"}
12
+ SUPERUSER="your_superuser"
13
+ SUPERUSER_PASSWORD="your_superuser_password"
14
14
 
15
15
  # Export PGPASSWORD to avoid password prompt
16
16
  export PGPASSWORD=$SUPERUSER_PASSWORD
17
17
 
18
- # Drop the existing database if it exists
19
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$DB_NAME' AND pid <> pg_backend_pid();"
20
- psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="DROP DATABASE IF EXISTS $DB_NAME"
18
+ # Generate a unique timestamp
19
+ TIMESTAMP=$(date +%Y%m%d%H%M%S)
20
+ BACKUP_DB_NAME="${DB_NAME}_backup_${TIMESTAMP}"
21
+
22
+ # Check if the database exists and rename it if it does
23
+ DB_EXISTS=$(psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --tuples-only --command="SELECT 1 FROM pg_database WHERE datname = '$DB_NAME'")
24
+ if [ "$DB_EXISTS" = "1" ]; then
25
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$DB_NAME' AND pid <> pg_backend_pid();"
26
+ psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="ALTER DATABASE $DB_NAME RENAME TO $BACKUP_DB_NAME"
27
+ fi
21
28
 
22
29
  # Create a new database
23
30
  psql --username=$SUPERUSER --host=$DB_HOST --port=$DB_PORT -d postgres --command="CREATE DATABASE $DB_NAME OWNER $SUPERUSER"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hockey-blast-common-lib
3
- Version: 0.1.45
3
+ Version: 0.1.47
4
4
  Summary: Common library for shared functionality and DB models
5
5
  Author: Pavel Kletskov
6
6
  Author-email: kletskov@gmail.com
@@ -10,6 +10,7 @@ hockey_blast_common_lib/aggregate_skater_stats.py
10
10
  hockey_blast_common_lib/assign_skater_skill.py
11
11
  hockey_blast_common_lib/db_connection.py
12
12
  hockey_blast_common_lib/dump_sample_db.sh
13
+ hockey_blast_common_lib/find_leagues_seasons.py
13
14
  hockey_blast_common_lib/hockey_blast_sample_backup.sql.gz
14
15
  hockey_blast_common_lib/models.py
15
16
  hockey_blast_common_lib/options.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='hockey-blast-common-lib', # The name of your package
5
- version='0.1.45',
5
+ version='0.1.47',
6
6
  description='Common library for shared functionality and DB models',
7
7
  author='Pavel Kletskov',
8
8
  author_email='kletskov@gmail.com',