hkjc 0.1.0__py3-none-any.whl → 0.2.0__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/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.
|
3
|
+
Version: 0.2.0
|
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
|
@@ -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.
|
11
|
-
hkjc-0.
|
12
|
-
hkjc-0.
|
11
|
+
hkjc-0.2.0.dist-info/METADATA,sha256=6rH6BxIZ1KMMh_TO_Br3o3IM9zjsrZMrr_zbBbL8Em0,384
|
12
|
+
hkjc-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
13
|
+
hkjc-0.2.0.dist-info/RECORD,,
|
File without changes
|