Relabel Policy¶
Policy data table and score-to-label mapping for axis relabelling.
app/relabel_policy.py¶
Server-side policy table and score-to-label mapping for the Axis Descriptor Lab.
This module owns the lab’s score-to-label mapping and the canonical axis ordering used by the standalone UI. The definitions here are intentionally aligned with the current Pipe-Works mud-server policy files:
pipeworks_mud_server/data/worlds/pipeworks_web/policies/axes.yamlpipeworks_mud_server/data/worlds/pipeworks_web/policies/thresholds.yaml
The mud server remains the runtime authority. Axis Lab keeps a checked-in lab-side copy of the current rules so the UI can perform deterministic local inspection and relabelling without keeping the older mirror-heavy file model alive.
Exports¶
- AXIS_ORDERlist[str]
Canonical full-axis ordering, matching the mud-server
axes.yamlkey order for the bundled worlds.- AXIS_LABEL_ORDERdict[str, list[str]]
Canonical low-to-high ordinal label sequence for each axis, matching the mud-server
ordering.valuespayloads.- RELABEL_POLICYdict[str, list[tuple[float, float, str]]]
Module-level constant mapping each known axis name to an ordered list of inclusive
(min_score, max_score, label)tuples derived from the mud-serverthresholds.yamlranges.- apply_relabel_policy(payload) -> AxisPayload
Walk the payload’s axes, recompute labels from
RELABEL_POLICYfor known axes, and return a newAxisPayloadwith updated labels. Unknown axes are passed through unchanged. Scores are never modified.
Design notes¶
The policy table lives in its own module (rather than inline in a route handler) so that:
Unit tests can validate the current mud-server-aligned policy in isolation without hitting the HTTP layer.
The table can be imported by other modules (e.g. future CLI tools) without pulling in all of FastAPI.
main.pystays a thin routing layer — it callsapply_relabel_policy(payload)and returns the result.
- app.relabel_policy.resolve_axis_label(axis_name, score, fallback_label)[source]¶
Resolve
scoreto the mud-server-aligned label foraxis_name.The lookup uses inclusive
min <= score <= maxrange checks to mirror the mud server’s axis-value resolution logic. If the axis is unknown, or if the score falls outside every configured range,fallback_labelis returned unchanged.Returning the existing label for unmatched scores is intentional: the lab’s schema requires a non-empty label string, while the mud server stores label absence as
Nonein the database layer.- Parameters:
- Returns:
The resolved canonical label, or
fallback_labelwhen the axis or score is not covered by the configured policy.- Return type:
- app.relabel_policy.apply_relabel_policy(payload)[source]¶
Recompute axis labels from the policy table and return an updated payload.
For each axis in payload, if the axis name appears in
RELABEL_POLICY, the label is rewritten to the matching mud-server threshold range. Unknown axes (those not in the policy table) are passed through with their existing labels intact.Scores are never modified — only labels change. All non-axis fields (
policy_hash,seed,world_id) are preserved verbatim.- Parameters:
payload (AxisPayload) – The current axis payload with scores and (possibly stale) labels.
- Returns:
A new payload instance with labels recomputed from scores.
- Return type: