hkjc 0.1.0__py3-none-any.whl → 0.2.1__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.
hkjc/__init__.py CHANGED
@@ -5,7 +5,8 @@ This module re-exports commonly used symbols from the submodules.
5
5
  from importlib.metadata import version as _version
6
6
 
7
7
  __all__ = ["live_odds", "qpbanker",
8
- "generate_all_qp_trades", "generate_pareto_qp_trades"]
8
+ "generate_all_qp_trades", "generate_pareto_qp_trades",
9
+ "speedpro_df", "speedmap"]
9
10
 
10
11
  try:
11
12
  __version__ = _version(__name__)
@@ -14,3 +15,4 @@ except Exception: # pragma: no cover - best-effort version resolution
14
15
 
15
16
  from .live_odds import live_odds
16
17
  from .processing import generate_all_qp_trades, generate_pareto_qp_trades
18
+ from .speedpro import speedmap, speedpro_df
hkjc/speedpro.py ADDED
@@ -0,0 +1,55 @@
1
+ """Functions to scrap SpeedPro data.
2
+ """
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime as dt
6
+
7
+ import polars as pl
8
+ import requests
9
+ import json
10
+
11
+ ENERGY_XLS_TEMPLATE = "https://racing.hkjc.com/racing/speedpro/assets/excel/{date}_energygrid_en.xls"
12
+ SPEEDMAP_URL_TEMPLATE = "https://racing.hkjc.com/racing/speedpro/assets/json/speedguide/race_{race_num}.json"
13
+
14
+
15
+ def speedpro_df(race_date: str) -> pl.DataFrame:
16
+ """Fetch and process SpeedPro scores for a given race date.
17
+
18
+ Args:
19
+ race_date (str): Date in 'YYYY-MM-DD' format.
20
+
21
+ Returns:
22
+ pl.DataFrame: Processed DataFrame with SpeedPro scores.
23
+ """
24
+ # validate date format
25
+ try:
26
+ dt.strptime(race_date, "%Y-%m-%d")
27
+ except Exception:
28
+ raise ValueError("Date must be in 'YYYY-MM-DD' format")
29
+
30
+ df = pl.read_excel(ENERGY_XLS_TEMPLATE.format(
31
+ date=dt.strptime(race_date, "%Y-%m-%d").strftime("%Y%m%d")))
32
+
33
+ # Clean column names
34
+ df.columns = [col.strip().replace(" ", "").replace(
35
+ "\n", "_").replace('.', '') for col in df.columns]
36
+
37
+ return df
38
+
39
+
40
+ def speedmap(race_num: int) -> str:
41
+ """Fetch SpeedMap as base64 encoded string.
42
+
43
+ Args:
44
+ race_date (str): Date in 'YYYY-MM-DD' format.
45
+ race_num (int): Race number.
46
+
47
+ Returns:
48
+ str: Base64 encoded string of the SpeedMap image.
49
+ """
50
+ r = requests.get(SPEEDMAP_URL_TEMPLATE.format(race_num=race_num))
51
+ if r.status_code != 200:
52
+ raise RuntimeError(f"Request failed: {r.status_code} - {r.text}")
53
+ # Decode with 'utf-8-sig' to strip a possible UTF-8 BOM before JSON parsing
54
+ content = r.content.decode("utf-8-sig")
55
+ return json.loads(content)['en-us']['RaceMap']
@@ -1,11 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hkjc
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Library for scrapping HKJC data and perform basic analysis
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: cachetools>=6.2.0
7
+ Requires-Dist: fastexcel>=0.16.0
7
8
  Requires-Dist: numpy>=2.3.3
8
9
  Requires-Dist: polars>=1.33.1
10
+ Requires-Dist: pyarrow>=21.0.0
9
11
  Requires-Dist: requests>=2.32.5
10
12
  Requires-Dist: scipy>=1.16.2
11
13
  Requires-Dist: tqdm>=4.67.1
@@ -1,4 +1,4 @@
1
- hkjc/__init__.py,sha256=_boKRSn7A1On4Uwh4Ds-UoS2-dAfbyHoXB9XLp6Efrc,499
1
+ hkjc/__init__.py,sha256=LPSYUYKnXLM7A6AC8Le8DJRP-D5smO6w9SXhYUJXbi8,572
2
2
  hkjc/analysis.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  hkjc/live_odds.py,sha256=i_g9ckQKA9GWbwPXNvbmNvm-dPbF9UJoGiWv6_bHzwA,4603
4
4
  hkjc/odds_fitting.py,sha256=abHa19Vv3yAjX4PPFhwoMldmG1DF1tXGXtYVaFszhJI,33
@@ -6,7 +6,8 @@ hkjc/optimization.py,sha256=OArQ3w9bwcIV_lTNuE5za6AROoa90xk_gwAoGwQ-8RE,3784
6
6
  hkjc/processing.py,sha256=9AiTkjsx51sZtyA4XcfK-werwFWxdea0BeIEuNvGQYQ,2983
7
7
  hkjc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  hkjc/qpbanker.py,sha256=vhvYb5_nGrKgYgre9gGF6tgswovca5C9pZVOPGxEP1Q,4804
9
+ hkjc/speedpro.py,sha256=vKnSz9yY1rfVmRo7GVxXLjsiQN-YgwxSbV0B7yuszS4,1702
9
10
  hkjc/visualization.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- hkjc-0.1.0.dist-info/METADATA,sha256=fsrs2M07EvjjNyLqXMAQnyRg8Ebk-IcVq415v2QZEBQ,320
11
- hkjc-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
- hkjc-0.1.0.dist-info/RECORD,,
11
+ hkjc-0.2.1.dist-info/METADATA,sha256=l4xH-xAdWLN8yDKwBg27J2o1Tpw42u0UfCIzMGji_xk,384
12
+ hkjc-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ hkjc-0.2.1.dist-info/RECORD,,
File without changes