Update Discord trade listings
This commit is contained in:
@@ -24,9 +24,11 @@ SHINY_AIZEN = "Shiny Aizen Evo"
|
||||
ANCHOR_VALUE = 1000.0
|
||||
RIDGE = 0.03
|
||||
COMPLETED_WEIGHT = 9.0
|
||||
INFERRED_WEIGHT_FACTOR = 1.0 / 3.0
|
||||
MAX_STABLE_CHANGE_PCT = 25.0
|
||||
CONFLICT_RATIO = 1.25
|
||||
CONFIDENCE_FIELDS = ("unit_variant", "quote_count", "asking_quote_count",
|
||||
"explicit_ask_count", "inferred_ask_count",
|
||||
"completed_trade_count", "full_fit_value",
|
||||
"leave_one_out_min", "leave_one_out_max", "max_change_pct",
|
||||
"most_influential_source_row", "most_influential_evidence_type",
|
||||
@@ -37,6 +39,10 @@ CONFLICT_FIELDS = ("unit_a", "unit_b", "source_row_a", "source_row_b",
|
||||
"source_text_a", "source_text_b")
|
||||
IMPACT_FIELDS = ("unit_variant", "removed_source_row", "removed_evidence_type", "removed_quote",
|
||||
"leave_one_out_value", "change_pct", "disconnected")
|
||||
COMPARISON_FIELDS = ("unit_variant", "all_fit", "all_ranked_value", "all_confidence",
|
||||
"all_explicit_asks", "all_inferred_asks", "explicit_only_fit",
|
||||
"explicit_only_ranked_value", "explicit_only_confidence",
|
||||
"change_pct_without_inferred", "explicit_only_connection")
|
||||
|
||||
|
||||
def source_order(source: int | str) -> tuple[int, int | str]:
|
||||
@@ -143,12 +149,18 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
*, include_report: bool = False) -> tuple:
|
||||
quotes = []
|
||||
for item in direct:
|
||||
inferred = item.get("quote_type") == "listing_pair"
|
||||
quotes.append(({item["offered_unit"]: int(item["offered_qty"])},
|
||||
{item["requested_unit"]: int(item["requested_qty"])},
|
||||
int(item["source_row"]), 3.0, item.get("source_text", ""), "asking_direct"))
|
||||
int(item["source_row"]), 3.0 * (INFERRED_WEIGHT_FACTOR if inferred else 1.0),
|
||||
item.get("source_text", ""),
|
||||
"asking_direct_inferred" if inferred else "asking_direct_explicit"))
|
||||
for item in bundles:
|
||||
inferred = item.get("quote_type") == "listing_pair"
|
||||
quotes.append((item["offered"], item["requested"], int(item["source_row"]),
|
||||
1.0, item.get("source_text", ""), "asking_bundle"))
|
||||
INFERRED_WEIGHT_FACTOR if inferred else 1.0,
|
||||
item.get("source_text", ""),
|
||||
"asking_bundle_inferred" if inferred else "asking_bundle_explicit"))
|
||||
for item in completed or []:
|
||||
quotes.append((item["offered"], item["requested"], item["source_row"],
|
||||
COMPLETED_WEIGHT, item.get("source_text", ""), "completed_trade"))
|
||||
@@ -168,6 +180,10 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
completed_count = len({q[2] for q in connected if q[5] == "completed_trade"
|
||||
and unit in set(q[0]) | set(q[1])})
|
||||
asking_count = count - completed_count
|
||||
explicit_sources = {q[2] for q in connected if q[5].endswith("_explicit")
|
||||
and unit in set(q[0]) | set(q[1])}
|
||||
inferred_sources = {q[2] for q in connected if q[5].endswith("_inferred")
|
||||
and unit in set(q[0]) | set(q[1])} - explicit_sources
|
||||
omitted_values = [(quote, fitted.get(unit)) for quote, fitted in omissions]
|
||||
for quote, fitted in omitted_values:
|
||||
impacts.append({
|
||||
@@ -197,6 +213,8 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
report.append({
|
||||
"unit_variant": unit, "quote_count": count,
|
||||
"asking_quote_count": asking_count, "completed_trade_count": completed_count,
|
||||
"explicit_ask_count": len(explicit_sources),
|
||||
"inferred_ask_count": len(inferred_sources),
|
||||
"full_fit_value": round(value, 1),
|
||||
"leave_one_out_min": round(min(fitted for _, fitted in retained), 1) if retained else "",
|
||||
"leave_one_out_max": round(max(fitted for _, fitted in retained), 1) if retained else "",
|
||||
@@ -214,6 +232,8 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
"confidence": confidence,
|
||||
"quote_count": count,
|
||||
"asking_quote_count": asking_count,
|
||||
"explicit_ask_count": len(explicit_sources),
|
||||
"inferred_ask_count": len(inferred_sources),
|
||||
"completed_trade_count": completed_count,
|
||||
"source_rows": source_list(sources[unit]),
|
||||
"basis": ("completed_and_asking" if completed_count and asking_count else
|
||||
@@ -234,6 +254,8 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
"confidence": "constraint_only",
|
||||
"quote_count": 0,
|
||||
"asking_quote_count": 0,
|
||||
"explicit_ask_count": 0,
|
||||
"inferred_ask_count": 0,
|
||||
"completed_trade_count": 0,
|
||||
"source_rows": "",
|
||||
"basis": "user_supplied_ordering",
|
||||
@@ -259,6 +281,40 @@ def fit_values(direct: list[dict], bundles: list[dict], completed: list[dict] |
|
||||
return result, summary
|
||||
|
||||
|
||||
def compare_evidence_modes(all_values: list[dict], all_report: list[dict],
|
||||
explicit_values: list[dict], explicit_report: list[dict]) -> list[dict]:
|
||||
"""Show the diagnostic fit and published value with inferred asks removed."""
|
||||
all_rows = {row["unit_variant"]: row for row in all_values}
|
||||
explicit_rows = {row["unit_variant"]: row for row in explicit_values}
|
||||
all_fits = {row["unit_variant"]: row for row in all_report}
|
||||
explicit_fits = {row["unit_variant"]: row for row in explicit_report}
|
||||
result = []
|
||||
for unit in sorted(all_rows.keys() | explicit_rows.keys()):
|
||||
full = all_rows.get(unit, {})
|
||||
reduced = explicit_rows.get(unit, {})
|
||||
full_fit = all_fits.get(unit, {}).get("full_fit_value", "")
|
||||
reduced_fit = explicit_fits.get(unit, {}).get("full_fit_value", "")
|
||||
change = (round(100 * (reduced_fit - full_fit) / full_fit, 1)
|
||||
if isinstance(full_fit, (int, float)) and full_fit
|
||||
and isinstance(reduced_fit, (int, float)) else "")
|
||||
result.append({
|
||||
"unit_variant": unit,
|
||||
"all_fit": full_fit,
|
||||
"all_ranked_value": full.get("relative_value", ""),
|
||||
"all_confidence": full.get("confidence", ""),
|
||||
"all_explicit_asks": full.get("explicit_ask_count", 0),
|
||||
"all_inferred_asks": full.get("inferred_ask_count", 0),
|
||||
"explicit_only_fit": reduced_fit,
|
||||
"explicit_only_ranked_value": reduced.get("relative_value", ""),
|
||||
"explicit_only_confidence": reduced.get(
|
||||
"confidence", "disconnected" if unit in all_fits else ""),
|
||||
"change_pct_without_inferred": change,
|
||||
"explicit_only_connection": ("connected" if unit in explicit_fits else
|
||||
"disconnected" if unit in all_fits else "constraint_only"),
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--input", type=Path, default=Path("trades.csv"))
|
||||
@@ -269,10 +325,11 @@ def main() -> None:
|
||||
parser.add_argument("--confidence-output", type=Path, default=Path("confidence_report.csv"))
|
||||
parser.add_argument("--conflicts-output", type=Path, default=Path("quote_conflicts.csv"))
|
||||
parser.add_argument("--impact-output", type=Path, default=Path("quote_impact.csv"))
|
||||
parser.add_argument("--comparison-output", type=Path, default=Path("evidence_comparison.csv"))
|
||||
args = parser.parse_args()
|
||||
destinations = [args.output.resolve(), args.bundle_output.resolve(), args.direct_output.resolve(),
|
||||
args.confidence_output.resolve(), args.conflicts_output.resolve(),
|
||||
args.impact_output.resolve()]
|
||||
args.impact_output.resolve(), args.comparison_output.resolve()]
|
||||
inputs = {args.input.resolve(), args.completed_trades.resolve()}
|
||||
if len(inputs) != 2 or len(set(destinations)) != len(destinations) or inputs.intersection(destinations):
|
||||
parser.error("input and output paths must all differ")
|
||||
@@ -288,6 +345,11 @@ def main() -> None:
|
||||
completed = load_completed_trades(args.completed_trades)
|
||||
values, summary, report, conflicts, impacts = fit_values(
|
||||
direct, bundles, completed, include_report=True)
|
||||
explicit_values, _, explicit_report, _, _ = fit_values(
|
||||
[quote for quote in direct if quote["quote_type"] == "explicit_for"],
|
||||
[quote for quote in bundles if quote["quote_type"] == "explicit_for"],
|
||||
completed, include_report=True)
|
||||
comparison = compare_evidence_modes(values, report, explicit_values, explicit_report)
|
||||
for destination in destinations:
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
with args.direct_output.open("w", encoding="utf-8-sig", newline="") as stream:
|
||||
@@ -305,6 +367,7 @@ def main() -> None:
|
||||
with args.output.open("w", encoding="utf-8-sig", newline="") as stream:
|
||||
writer = csv.DictWriter(stream, fieldnames=("rank", "unit_variant", "relative_value",
|
||||
"confidence", "quote_count", "asking_quote_count",
|
||||
"explicit_ask_count", "inferred_ask_count",
|
||||
"completed_trade_count", "source_rows",
|
||||
"basis", "note"))
|
||||
writer.writeheader()
|
||||
@@ -321,6 +384,10 @@ def main() -> None:
|
||||
writer = csv.DictWriter(stream, fieldnames=IMPACT_FIELDS)
|
||||
writer.writeheader()
|
||||
writer.writerows(impacts)
|
||||
with args.comparison_output.open("w", encoding="utf-8-sig", newline="") as stream:
|
||||
writer = csv.DictWriter(stream, fieldnames=COMPARISON_FIELDS)
|
||||
writer.writeheader()
|
||||
writer.writerows(comparison)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.error(str(error))
|
||||
print(f"Saved {len(values)} provisional entries from {len(rows)} listings; "
|
||||
|
||||
Reference in New Issue
Block a user