Update trade listings
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
# First ValueList
|
||||
|
||||
Run `py calculate_valuelist.py` to regenerate `valuelist.csv` from the existing
|
||||
`trades.csv`. The script reads the CSV and does not change it. Use `--input`,
|
||||
`--output`, and `--minimum-mentions` to choose other files or a different
|
||||
total-mention threshold.
|
||||
|
||||
The `interest_index` is a **relative market-interest signal**, not a trade
|
||||
price. An index of 100 is the median among included variants. Higher numbers
|
||||
mean that a variant is requested more often relative to how often it is
|
||||
offered in this set of listings. It does not tell you how many of one unit
|
||||
should be exchanged for another.
|
||||
|
||||
The calculation:
|
||||
|
||||
1. Finds explicitly named unit variants with `Evo` or `Unevo` and keeps
|
||||
`Shiny` separate. It uses the names and aliases in
|
||||
`discord_trade_parser.py`.
|
||||
2. Counts distinct authors offering each variant and distinct authors
|
||||
requesting it in `lf` or `mlf`. Reposts, quantities, and repeated mentions
|
||||
from the same author count once. `nlf` is excluded, as are direct `my`
|
||||
mentions in requests.
|
||||
3. Includes variants with at least 20 total author mentions and at least
|
||||
five authors on each side.
|
||||
4. Computes `(requested_by + 3) / (offered_by + 3)` and scales it so the
|
||||
median included variant has index 100. The added three on each side
|
||||
reduces the effect of small counts.
|
||||
|
||||
These are **asking listings**, not completed trades. Broad requests such as
|
||||
“offers” and variants without an explicit evolution state are not counted.
|
||||
The source has no trade date or accepted exchange value, so the index is a
|
||||
first comparison of interest, not an absolute game ValueList. Review the
|
||||
`requested_by` and `offered_by` columns before using entries with low counts.
|
||||
@@ -1,126 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build a first, evidence-backed market-interest list from trades.csv.
|
||||
|
||||
This is a relative asking-interest index, not a price or a record of completed
|
||||
trades. Only explicitly named Evo and Unevo units are compared.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from collections import defaultdict
|
||||
import csv
|
||||
from pathlib import Path
|
||||
import re
|
||||
from statistics import median
|
||||
|
||||
from discord_trade_parser import KNOWN_UNIT_NAMES, normalize_unit_names
|
||||
|
||||
|
||||
UNIT_NAMES = tuple(
|
||||
name for name in KNOWN_UNIT_NAMES if name.casefold() != "shiny skull knight"
|
||||
)
|
||||
CANONICAL_NAMES = {name.casefold(): normalize_unit_names(name) for name in UNIT_NAMES}
|
||||
UNIT_PATTERN = re.compile(
|
||||
r"(?<!\w)(?P<shiny>Shiny\s+)?(?P<unit>"
|
||||
+ "|".join(re.escape(name).replace(r"\ ", r"\s+") for name in UNIT_NAMES)
|
||||
+ r")\s+(?P<evolution>Evo|Unevo)\b",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
MY_PREFIX = re.compile(r"\bmy\s+$", re.IGNORECASE)
|
||||
|
||||
|
||||
def variants(text: str, *, request: bool = False) -> set[str]:
|
||||
"""Find explicit unit variants, counting each at most once per side."""
|
||||
found: set[str] = set()
|
||||
for match in UNIT_PATTERN.finditer(text):
|
||||
if request and MY_PREFIX.search(text[max(0, match.start() - 12):match.start()]):
|
||||
continue
|
||||
name = CANONICAL_NAMES[match.group("unit").casefold()]
|
||||
shiny = "Shiny " if match.group("shiny") else ""
|
||||
evolution = match.group("evolution").capitalize()
|
||||
found.add(f"{shiny}{name} {evolution}")
|
||||
return found
|
||||
|
||||
|
||||
def calculate(input_path: Path, minimum_mentions: int = 20) -> tuple[list[dict], dict]:
|
||||
if minimum_mentions < 1:
|
||||
raise ValueError("minimum mentions must be positive")
|
||||
|
||||
offered_by: dict[str, set[str]] = defaultdict(set)
|
||||
requested_by: dict[str, set[str]] = defaultdict(set)
|
||||
rows = 0
|
||||
authors: set[str] = set()
|
||||
with input_path.open(encoding="utf-8-sig", newline="") as stream:
|
||||
reader = csv.DictReader(stream)
|
||||
required = {"offer", "lf", "mlf", "author_hash"}
|
||||
if not required.issubset(reader.fieldnames or []):
|
||||
raise ValueError(f"CSV needs columns: {', '.join(sorted(required))}")
|
||||
for row in reader:
|
||||
rows += 1
|
||||
author = row["author_hash"].strip()
|
||||
if not author:
|
||||
# An untracked listing cannot be deduplicated reliably.
|
||||
continue
|
||||
authors.add(author)
|
||||
for unit in variants(row["offer"]):
|
||||
offered_by[unit].add(author)
|
||||
for unit in variants(" | ".join((row["lf"], row["mlf"])), request=True):
|
||||
requested_by[unit].add(author)
|
||||
|
||||
candidates = []
|
||||
for unit in offered_by.keys() | requested_by.keys():
|
||||
supply = len(offered_by[unit])
|
||||
demand = len(requested_by[unit])
|
||||
if supply + demand < minimum_mentions or min(supply, demand) < 5:
|
||||
continue
|
||||
# Three mentions on either side shrink extreme ratios from small samples.
|
||||
pressure = (demand + 3) / (supply + 3)
|
||||
candidates.append((unit, supply, demand, pressure))
|
||||
|
||||
baseline = median(item[3] for item in candidates) if candidates else 1.0
|
||||
result = [
|
||||
{
|
||||
"unit_variant": unit,
|
||||
"interest_index": round(100 * pressure / baseline),
|
||||
"requested_by": demand,
|
||||
"offered_by": supply,
|
||||
"total_mentions": demand + supply,
|
||||
}
|
||||
for unit, supply, demand, pressure in candidates
|
||||
]
|
||||
result.sort(key=lambda item: (-item["interest_index"], -item["total_mentions"], item["unit_variant"]))
|
||||
summary = {
|
||||
"source_rows": rows,
|
||||
"distinct_authors": len(authors),
|
||||
"ranked_variants": len(result),
|
||||
"minimum_mentions": minimum_mentions,
|
||||
}
|
||||
return result, summary
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--input", type=Path, default=Path("trades.csv"))
|
||||
parser.add_argument("--output", type=Path, default=Path("valuelist.csv"))
|
||||
parser.add_argument("--minimum-mentions", type=int, default=20)
|
||||
args = parser.parse_args()
|
||||
if args.input.resolve() == args.output.resolve():
|
||||
parser.error("input and output paths must differ")
|
||||
try:
|
||||
result, summary = calculate(args.input, args.minimum_mentions)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.error(str(error))
|
||||
args.output.parent.mkdir(parents=True, exist_ok=True)
|
||||
with args.output.open("w", encoding="utf-8-sig", newline="") as stream:
|
||||
writer = csv.DictWriter(stream, fieldnames=[
|
||||
"unit_variant", "interest_index", "requested_by", "offered_by", "total_mentions"
|
||||
])
|
||||
writer.writeheader()
|
||||
writer.writerows(result)
|
||||
print(f"Saved {len(result)} variants to {args.output} from "
|
||||
f"{summary['source_rows']} listings and {summary['distinct_authors']} authors.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,42 +0,0 @@
|
||||
import csv
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from calculate_valuelist import calculate, variants
|
||||
|
||||
|
||||
class ValueListTests(unittest.TestCase):
|
||||
def test_variant_extraction_keeps_shiny_separate_and_normalizes_case(self):
|
||||
self.assertEqual(
|
||||
variants("ROGER Evo | Shiny Roger Evo | Roger Unevo"),
|
||||
{"Roger Evo", "Shiny Roger Evo", "Roger Unevo"},
|
||||
)
|
||||
self.assertEqual(
|
||||
variants("my Aizen Evo for Homura Evo", request=True),
|
||||
{"Homura Evo"},
|
||||
)
|
||||
|
||||
def test_counts_authors_once_and_excludes_nlf(self):
|
||||
stream = StringIO(newline="")
|
||||
writer = csv.DictWriter(stream, fieldnames=[
|
||||
"offer", "lf", "mlf", "nlf", "author_hash"
|
||||
])
|
||||
writer.writeheader()
|
||||
for i in range(5):
|
||||
writer.writerow({"offer": "2 Aizen Evo | Aizen Evo", "author_hash": f"seller{i}"})
|
||||
writer.writerow({"offer": "Aizen Evo", "author_hash": f"seller{i}"})
|
||||
writer.writerow({"lf": "Aizen Evo", "nlf": "Homura Evo", "author_hash": f"buyer{i}"})
|
||||
stream.seek(0)
|
||||
with patch.object(Path, "open", return_value=stream):
|
||||
path = Path("fixture.csv")
|
||||
result, summary = calculate(path, minimum_mentions=10)
|
||||
self.assertEqual(summary["source_rows"], 15)
|
||||
self.assertEqual(result[0]["unit_variant"], "Aizen Evo")
|
||||
self.assertEqual((result[0]["offered_by"], result[0]["requested_by"]), (5, 5))
|
||||
self.assertEqual(len(result), 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,21 +0,0 @@
|
||||
unit_variant,interest_index,requested_by,offered_by,total_mentions
|
||||
Aizen Evo,270,93,112,205
|
||||
Homura Evo,221,104,154,258
|
||||
Mamy Evo,198,8,15,23
|
||||
Shiny Cid Evo,180,7,15,22
|
||||
Shiny Homura Evo,162,6,15,21
|
||||
Alucard Evo,144,30,71,101
|
||||
Shiny Aizen Evo,144,5,15,20
|
||||
Roger Evo,116,11,36,47
|
||||
Shiny Dark Mage Evo,114,15,48,63
|
||||
Shiny Chuuni Evo,105,18,62,80
|
||||
Chuuni Evo,95,33,119,152
|
||||
Shiny Mamy Evo,86,6,31,37
|
||||
Dark Mage Evo,73,45,209,254
|
||||
Gilgamesh Evo,59,19,118,137
|
||||
Shiny Nagumo Evo,52,5,47,52
|
||||
Shiny Elf Mage Evo,50,6,55,61
|
||||
Poseidon Evo,41,7,76,83
|
||||
Buddha Evo,40,15,141,156
|
||||
Cid Evo,37,12,128,140
|
||||
Nagumo Evo,26,10,156,166
|
||||
|
Reference in New Issue
Block a user