spells-mtg 0.10.8__py3-none-any.whl → 0.10.10__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.

Potentially problematic release.


This version of spells-mtg might be problematic. Click here for more details.

spells/cache.py CHANGED
@@ -9,11 +9,20 @@ Caches are cleared per-set when new files are downloaded.
9
9
 
10
10
  from enum import StrEnum
11
11
  import os
12
+ from pathlib import Path
12
13
  import sys
13
14
 
14
15
  import polars as pl
15
16
 
16
17
 
18
+ class Env(StrEnum):
19
+ PROD = "prod"
20
+ TEST = "test"
21
+
22
+
23
+ env = Env.PROD
24
+
25
+
17
26
  class EventType(StrEnum):
18
27
  PREMIER = "PremierDraft"
19
28
  TRADITIONAL = "TradDraft"
@@ -28,8 +37,30 @@ def spells_print(mode, content):
28
37
  print(f" 🪄 {mode} ✨ {content}")
29
38
 
30
39
 
40
+ def set_test_env():
41
+ global env
42
+ env = Env.TEST
43
+
44
+
45
+ def set_prod_env():
46
+ global env
47
+ env = Env.PROD
48
+
49
+
31
50
  def data_home() -> str:
32
51
  is_win = sys.platform == "win32"
52
+ global env
53
+
54
+ if env == Env.TEST:
55
+ return os.path.expanduser(
56
+ os.environ.get(
57
+ "SPELLS_TEST_HOME",
58
+ r"~\AppData\Local\SpellsTest"
59
+ if is_win
60
+ else "~/.local/share/spellstest/",
61
+ )
62
+ )
63
+
33
64
  return os.path.expanduser(
34
65
  os.environ.get(
35
66
  "SPELLS_DATA_HOME",
@@ -41,6 +72,65 @@ def data_home() -> str:
41
72
  )
42
73
 
43
74
 
75
+ def ad_hoc_dir():
76
+ ad_hoc_dir = Path(data_home()) / "ad_hoc"
77
+ if not os.path.isdir(ad_hoc_dir):
78
+ os.makedirs(ad_hoc_dir)
79
+ return ad_hoc_dir
80
+
81
+
82
+ def save_ad_hoc_dataset(df: pl.DataFrame, key: str):
83
+ df.write_parquet(ad_hoc_dir() / f"{key}.parquet")
84
+
85
+
86
+ def read_ad_hoc_dataset(key: str):
87
+ path = ad_hoc_dir() / f"{key}.parquet"
88
+ if os.path.exists(path):
89
+ return pl.read_parquet(ad_hoc_dir() / f"{key}.parquet")
90
+ else:
91
+ return None
92
+
93
+
94
+ def create_test_data(set_code: str, test_num_drafts: int = 100):
95
+ """
96
+ run from prod environment to write test data for `set_code` into
97
+ the test environment. Then set `SPELLS_DATA_HOME=test_data_home`
98
+ to run from the test environment
99
+ """
100
+
101
+ context_df = pl.scan_parquet(data_file_path(set_code, "context")).collect()
102
+ picks_per_pack = context_df["picks_per_pack"][0]
103
+
104
+ draft_df = (
105
+ pl.scan_parquet(data_file_path(set_code, "draft"))
106
+ .head(50 * (test_num_drafts + 2))
107
+ .collect()
108
+ )
109
+
110
+ sample_draft_ids = (
111
+ draft_df.group_by("draft_id")
112
+ .len()
113
+ .filter(pl.col("len") == picks_per_pack * 3)["draft_id"][0:test_num_drafts]
114
+ )
115
+
116
+ draft_sample_df = draft_df.filter(pl.col("draft_id").is_in(sample_draft_ids))
117
+ game_sample_df = (
118
+ pl.scan_parquet(data_file_path(set_code, "game"))
119
+ .filter(pl.col("draft_id").is_in(sample_draft_ids))
120
+ .collect()
121
+ )
122
+ card_df = pl.scan_parquet(data_file_path(set_code, "card")).collect()
123
+
124
+ set_test_env()
125
+ if not os.path.isdir(set_dir := external_set_path(set_code)):
126
+ os.makedirs(set_dir)
127
+ context_df.write_parquet(data_file_path(set_code, "context"))
128
+ draft_sample_df.write_parquet(data_file_path(set_code, "draft"))
129
+ game_sample_df.write_parquet(data_file_path(set_code, "game"))
130
+ card_df.write_parquet(data_file_path(set_code, "card"))
131
+ set_prod_env()
132
+
133
+
44
134
  def data_dir_path(cache_dir: DataDir) -> str:
45
135
  """
46
136
  Where 17Lands data is stored. MDU_DATA_DIR environment variable is used, if it exists,
spells/draft_data.py CHANGED
@@ -19,7 +19,7 @@ from polars.exceptions import ColumnNotFoundError
19
19
 
20
20
  from spells import cache
21
21
  import spells.filter
22
- import spells.manifest
22
+ from spells import manifest
23
23
  from spells.columns import ColDef, ColSpec, get_specs
24
24
  from spells.enums import View, ColName, ColType
25
25
  from spells.log import make_verbose
@@ -379,7 +379,7 @@ def _fetch_or_cache(
379
379
 
380
380
  def _base_agg_df(
381
381
  set_code: str,
382
- m: spells.manifest.Manifest,
382
+ m: manifest.Manifest,
383
383
  use_streaming: bool = True,
384
384
  ) -> pl.DataFrame:
385
385
  join_dfs = []
@@ -516,7 +516,7 @@ def summon(
516
516
  this_set_context = None
517
517
 
518
518
  col_def_map = _hydrate_col_defs(code, specs, set_card_context, this_set_context)
519
- m = spells.manifest.create(col_def_map, columns, group_by, filter_spec)
519
+ m = manifest.create(col_def_map, columns, group_by, filter_spec)
520
520
 
521
521
  calc_fn = functools.partial(_base_agg_df, code, m, use_streaming=use_streaming)
522
522
  agg_df = _fetch_or_cache(
spells/enums.py CHANGED
@@ -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" # 0 - 3 * picks_per_pack - 1
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"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spells-mtg
3
- Version: 0.10.8
3
+ Version: 0.10.10
4
4
  Summary: analaysis of 17Lands.com public datasets
5
5
  Author-Email: Joel Barnes <oelarnes@gmail.com>
6
6
  License: MIT
@@ -1,10 +1,10 @@
1
1
  spells/__init__.py,sha256=0pnh2NLn9FrNKncE9-tBsighp3e8YAsN--_ovUpgWGs,333
2
- spells/cache.py,sha256=7XDcltmlpagK2nkhuCCcAQVyrFMYkw9Acr7iVsLs3JU,3799
2
+ spells/cache.py,sha256=CjMsIOdUz43heJ4IZ5kTWfS_rAeOMFQ1qVAuq3mTWao,6192
3
3
  spells/cards.py,sha256=6stFPhJOzHqvQnkSv9cDeylRa_7L9Y8sOaowiZhzz6I,4174
4
4
  spells/columns.py,sha256=s_PYyg2QaRL6kLWFNKCBEfbMF0x7O7-Yd9SeG1ttYL4,18206
5
5
  spells/config.py,sha256=ixAe_raxKYvJBXyvNBJ-mm6ziRiAvtKLJihyFMnashs,224
6
- spells/draft_data.py,sha256=xoL82NTgTJWxZK1p-6LjxnYzkeYOr-Dc9-_T0m-WZ1Y,19946
7
- spells/enums.py,sha256=n-LEeYwp4ZMJuKJFKtyhDKJggspZkhReryf-IJsXO-I,4990
6
+ spells/draft_data.py,sha256=1HKYjDu0O8fD2AhUL9Zgw0jVu4lKweJ4KBFMDkH5JLU,19937
7
+ spells/enums.py,sha256=gbwfon6tQCoKDb-m4hSaHWi9slj82yqaH3qhYMVrsck,4991
8
8
  spells/extension.py,sha256=LBqGbJbe7iSRQkxJK7npkADCfzhdnIwwVvlmTn8xvjQ,8454
9
9
  spells/external.py,sha256=USqOtOVY7Mn39rdUPhmIeGm08s6TDnEV8-N3D14qJzE,11844
10
10
  spells/filter.py,sha256=J-YTOOAzOQpvIX29tviYL04RVoOUlfsbjBXoQBDCEdQ,3380
@@ -12,8 +12,8 @@ spells/log.py,sha256=3avmg65hru8K9npKLvPp1wWWxq-hoEYDUCbxqhPkKUw,2175
12
12
  spells/manifest.py,sha256=iOmhxIVMHu_Av3nd23zGjmUwLvZ2hAM0oc1ErPzZ_oE,8341
13
13
  spells/schema.py,sha256=DbMvV8PIThJTp0Xzp_XIorlW6JhE1ud1kWRGf5SQ4_c,6406
14
14
  spells/utils.py,sha256=IO3brrXVvZla0LRTEB5v6NgGqZb_rYA46XtKBURGMNk,1944
15
- spells_mtg-0.10.8.dist-info/METADATA,sha256=UbUMaRNAYLbiacfde7wXlT08AbaIgJB90OnPKf5YQME,47369
16
- spells_mtg-0.10.8.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
17
- spells_mtg-0.10.8.dist-info/entry_points.txt,sha256=a9Y1omdl9MdnKuIj3aOodgrp-zZII6OCdvqwgP6BFvI,63
18
- spells_mtg-0.10.8.dist-info/licenses/LICENSE,sha256=tS54XYbJSgmq5zuHhbsQGbNQLJPVgXqhF5nu2CSRMig,1068
19
- spells_mtg-0.10.8.dist-info/RECORD,,
15
+ spells_mtg-0.10.10.dist-info/METADATA,sha256=i6Ieaevmfs4OwJD76esBteKTKaf02Miuz_WUUt92WD8,47370
16
+ spells_mtg-0.10.10.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
17
+ spells_mtg-0.10.10.dist-info/entry_points.txt,sha256=a9Y1omdl9MdnKuIj3aOodgrp-zZII6OCdvqwgP6BFvI,63
18
+ spells_mtg-0.10.10.dist-info/licenses/LICENSE,sha256=tS54XYbJSgmq5zuHhbsQGbNQLJPVgXqhF5nu2CSRMig,1068
19
+ spells_mtg-0.10.10.dist-info/RECORD,,