fix: address PR review findings — rename evolution_tier to refractor_tier
- Rename `evolution_tier` parameter to `refractor_tier` in compute_variant_hash() to match the refractor naming convention established in PR #131 - Update hash input dict key accordingly (safe: function is new, no stored hashes) - Update test docstrings referencing the old parameter name - Remove redundant parentheses on boost_delta_json TextField declaration Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4a1251a734
commit
776f1a5302
@ -282,12 +282,12 @@ def apply_pitcher_boost(ratings_dict: dict, tb_budget: float = 1.5) -> dict:
|
||||
|
||||
def compute_variant_hash(
|
||||
player_id: int,
|
||||
evolution_tier: int,
|
||||
refractor_tier: int,
|
||||
cosmetics: list[str] | None = None,
|
||||
) -> int:
|
||||
"""Compute a stable, deterministic variant identifier for a boosted card.
|
||||
|
||||
Hashes the combination of player_id, evolution_tier, and an optional sorted
|
||||
Hashes the combination of player_id, refractor_tier, and an optional sorted
|
||||
list of cosmetic identifiers to produce a compact integer suitable for use
|
||||
as a database variant key. The result is derived from the first 8 hex
|
||||
characters of a SHA-256 digest, so collisions are extremely unlikely in
|
||||
@ -298,7 +298,7 @@ def compute_variant_hash(
|
||||
|
||||
Args:
|
||||
player_id: Player primary key.
|
||||
evolution_tier: Refractor tier (0–4) the card has reached.
|
||||
refractor_tier: Refractor tier (0–4) the card has reached.
|
||||
cosmetics: Optional list of cosmetic tag strings (e.g. special art
|
||||
identifiers). Order is normalised — callers need not sort.
|
||||
|
||||
@ -307,7 +307,7 @@ def compute_variant_hash(
|
||||
"""
|
||||
inputs = {
|
||||
"player_id": player_id,
|
||||
"evolution_tier": evolution_tier,
|
||||
"refractor_tier": refractor_tier,
|
||||
"cosmetics": sorted(cosmetics or []),
|
||||
}
|
||||
raw = hashlib.sha256(json.dumps(inputs, sort_keys=True).encode()).hexdigest()
|
||||
|
||||
@ -809,7 +809,7 @@ class TestVariantHash:
|
||||
"""
|
||||
|
||||
def test_deterministic(self):
|
||||
"""Same (player_id, evolution_tier, cosmetics) inputs produce the
|
||||
"""Same (player_id, refractor_tier, cosmetics) inputs produce the
|
||||
same hash on every call.
|
||||
|
||||
What: Call compute_variant_hash 20 times with the same arguments and
|
||||
@ -827,8 +827,8 @@ class TestVariantHash:
|
||||
def test_different_tiers_different_hash(self):
|
||||
"""Tier 1 and tier 2 for the same player produce different hashes.
|
||||
|
||||
What: Compare compute_variant_hash(player_id=1, evolution_tier=1)
|
||||
vs compute_variant_hash(player_id=1, evolution_tier=2).
|
||||
What: Compare compute_variant_hash(player_id=1, refractor_tier=1)
|
||||
vs compute_variant_hash(player_id=1, refractor_tier=2).
|
||||
|
||||
Why: Each Refractor tier represents a distinct card version. If two
|
||||
tiers produced the same hash, the DB unique-key constraint on variant
|
||||
@ -841,8 +841,8 @@ class TestVariantHash:
|
||||
def test_different_players_different_hash(self):
|
||||
"""Same tier for different players produces different hashes.
|
||||
|
||||
What: Compare compute_variant_hash(player_id=10, evolution_tier=1)
|
||||
vs compute_variant_hash(player_id=11, evolution_tier=1).
|
||||
What: Compare compute_variant_hash(player_id=10, refractor_tier=1)
|
||||
vs compute_variant_hash(player_id=11, refractor_tier=1).
|
||||
|
||||
Why: Each player's Refractor card is a distinct asset. If two players
|
||||
at the same tier shared a hash, their boosted variants could not be
|
||||
|
||||
Loading…
Reference in New Issue
Block a user