spells-mtg 0.10.8__tar.gz → 0.10.9__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.
Potentially problematic release.
This version of spells-mtg might be problematic. Click here for more details.
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/PKG-INFO +1 -1
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/pyproject.toml +1 -1
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/cache.py +70 -1
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/enums.py +1 -1
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/LICENSE +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/README.md +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/__init__.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/cards.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/columns.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/config.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/draft_data.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/extension.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/external.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/filter.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/log.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/manifest.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/schema.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/spells/utils.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/tests/__init__.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/tests/filter_test.py +0 -0
- {spells_mtg-0.10.8 → spells_mtg-0.10.9}/tests/utils_test.py +0 -0
|
@@ -10,10 +10,17 @@ Caches are cleared per-set when new files are downloaded.
|
|
|
10
10
|
from enum import StrEnum
|
|
11
11
|
import os
|
|
12
12
|
import sys
|
|
13
|
-
|
|
14
13
|
import polars as pl
|
|
15
14
|
|
|
16
15
|
|
|
16
|
+
class Env(StrEnum):
|
|
17
|
+
PROD = "prod"
|
|
18
|
+
TEST = "test"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
env = Env.PROD
|
|
22
|
+
|
|
23
|
+
|
|
17
24
|
class EventType(StrEnum):
|
|
18
25
|
PREMIER = "PremierDraft"
|
|
19
26
|
TRADITIONAL = "TradDraft"
|
|
@@ -28,8 +35,30 @@ def spells_print(mode, content):
|
|
|
28
35
|
print(f" 🪄 {mode} ✨ {content}")
|
|
29
36
|
|
|
30
37
|
|
|
38
|
+
def set_test_env():
|
|
39
|
+
global env
|
|
40
|
+
env = Env.TEST
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def set_prod_env():
|
|
44
|
+
global env
|
|
45
|
+
env = Env.PROD
|
|
46
|
+
|
|
47
|
+
|
|
31
48
|
def data_home() -> str:
|
|
32
49
|
is_win = sys.platform == "win32"
|
|
50
|
+
global env
|
|
51
|
+
|
|
52
|
+
if env == Env.TEST:
|
|
53
|
+
return os.path.expanduser(
|
|
54
|
+
os.environ.get(
|
|
55
|
+
"SPELLS_TEST_HOME",
|
|
56
|
+
r"~\AppData\Local\SpellsTest"
|
|
57
|
+
if is_win
|
|
58
|
+
else "~/.local/share/spellstest/",
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
|
|
33
62
|
return os.path.expanduser(
|
|
34
63
|
os.environ.get(
|
|
35
64
|
"SPELLS_DATA_HOME",
|
|
@@ -41,6 +70,46 @@ def data_home() -> str:
|
|
|
41
70
|
)
|
|
42
71
|
|
|
43
72
|
|
|
73
|
+
def create_test_data(set_code: str, test_num_drafts: int = 100):
|
|
74
|
+
"""
|
|
75
|
+
run from prod environment to write test data for `set_code` into
|
|
76
|
+
the test environment. Then set `SPELLS_DATA_HOME=test_data_home`
|
|
77
|
+
to run from the test environment
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
context_df = pl.scan_parquet(data_file_path(set_code, "context")).collect()
|
|
81
|
+
picks_per_pack = context_df["picks_per_pack"][0]
|
|
82
|
+
|
|
83
|
+
draft_df = (
|
|
84
|
+
pl.scan_parquet(data_file_path(set_code, "draft"))
|
|
85
|
+
.head(50 * (test_num_drafts + 2))
|
|
86
|
+
.collect()
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
sample_draft_ids = (
|
|
90
|
+
draft_df.group_by("draft_id")
|
|
91
|
+
.len()
|
|
92
|
+
.filter(pl.col("len") == picks_per_pack * 3)["draft_id"][0:test_num_drafts]
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
draft_sample_df = draft_df.filter(pl.col("draft_id").is_in(sample_draft_ids))
|
|
96
|
+
game_sample_df = (
|
|
97
|
+
pl.scan_parquet(data_file_path(set_code, "game"))
|
|
98
|
+
.filter(pl.col("draft_id").is_in(sample_draft_ids))
|
|
99
|
+
.collect()
|
|
100
|
+
)
|
|
101
|
+
card_df = pl.scan_parquet(data_file_path(set_code, "card")).collect()
|
|
102
|
+
|
|
103
|
+
set_test_env()
|
|
104
|
+
if not os.path.isdir(set_dir := external_set_path(set_code)):
|
|
105
|
+
os.makedirs(set_dir)
|
|
106
|
+
context_df.write_parquet(data_file_path(set_code, "context"))
|
|
107
|
+
draft_sample_df.write_parquet(data_file_path(set_code, "draft"))
|
|
108
|
+
game_sample_df.write_parquet(data_file_path(set_code, "game"))
|
|
109
|
+
card_df.write_parquet(data_file_path(set_code, "card"))
|
|
110
|
+
set_prod_env()
|
|
111
|
+
|
|
112
|
+
|
|
44
113
|
def data_dir_path(cache_dir: DataDir) -> str:
|
|
45
114
|
"""
|
|
46
115
|
Where 17Lands data is stored. MDU_DATA_DIR environment variable is used, if it exists,
|
|
@@ -60,7 +60,7 @@ class ColName(StrEnum):
|
|
|
60
60
|
PACK_NUM = "pack_num" # pack_number plus 1
|
|
61
61
|
PICK_NUMBER = "pick_number"
|
|
62
62
|
PICK_NUM = "pick_num" # pick_number plus 1
|
|
63
|
-
PICK_INDEX = "pick_index"
|
|
63
|
+
PICK_INDEX = "pick_index" # 0 - 3 * picks_per_pack - 1
|
|
64
64
|
TAKEN_AT = "taken_at"
|
|
65
65
|
NUM_TAKEN = "num_taken"
|
|
66
66
|
NUM_DRAFTS = "num_drafts"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|