Spaces:
Running
Running
Commit Β·
5351d38
1
Parent(s): 669970c
Add real range/agreement-count to dimension-event card copy
Browse filesContinuous signals (pace, vocabulary richness, etc.) now show their
actual mean+-std band alongside the point value ("170 words per
minute (typically between 155 and 185)"); categorical ones (energy
arc, pacing arc) show how many of the recent sessions actually agreed
("decreasing, showing up in 3 of your last 5 sessions"). Both numbers
were already computed to decide steadiness in the first place, just
never surfaced in the card copy before now.
Existing dimension_events rows were backfilled directly (one-time
script, not committed) using each row's own previous_value/label as
prior and freshly recomputed current evidence, since card_copy_json
freezes permanently at fire time and wouldn't have picked up this
change otherwise.
backend/pipeline/trigger_detector.py
CHANGED
|
@@ -177,6 +177,46 @@ def _value_str(dimension_key: str, value) -> str:
|
|
| 177 |
return f"{value}"
|
| 178 |
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
def _phrase_event(dimension_key, label, trigger_type, direction, prior, current, cfg, scope) -> dict:
|
| 181 |
"""Deterministic string templates, no LLM call β matches home_feed.py's
|
| 182 |
existing f-string convention (e.g. the old build_progress_cards)."""
|
|
@@ -184,23 +224,24 @@ def _phrase_event(dimension_key, label, trigger_type, direction, prior, current,
|
|
| 184 |
n = current["sample_count"]
|
| 185 |
scope_phrase = "" if scope == "overall" else f" in your {scope.replace('_', ' ')} conversations"
|
| 186 |
curr_str = current["mode_label"] if is_categorical else _value_str(dimension_key, current["mean"])
|
|
|
|
| 187 |
|
| 188 |
if trigger_type == "first_time_steady":
|
| 189 |
note = (f"Over your last {n} sessions, your {label} has settled into a steady "
|
| 190 |
-
f"pattern β {curr_str}.")
|
| 191 |
elif trigger_type == "context_shift":
|
| 192 |
note = (f"Your {label} has also settled into a steady pattern specifically"
|
| 193 |
-
f"{scope_phrase} β {curr_str}.")
|
| 194 |
elif trigger_type == "recurring" and direction == "back_to_usual":
|
| 195 |
note = (f"Your {label} had been varying more than usual for a bit, but it's "
|
| 196 |
-
f"settled back to your usual {curr_str}.")
|
| 197 |
elif trigger_type == "recurring": # direction == "drift"
|
| 198 |
note = (f"After a stretch of inconsistency, your {label} has settled into a new "
|
| 199 |
-
f"pattern β {curr_str}.")
|
| 200 |
elif trigger_type == "drift":
|
| 201 |
prev_str = (prior.get("last_steady_mode_label") if is_categorical
|
| 202 |
else _value_str(dimension_key, prior.get("last_steady_mean")))
|
| 203 |
-
note = f"Your {label} has shifted β from {prev_str} to {curr_str} over your last {n} sessions."
|
| 204 |
else:
|
| 205 |
note = f"Your {label} showed a new pattern this session."
|
| 206 |
|
|
|
|
| 177 |
return f"{value}"
|
| 178 |
|
| 179 |
|
| 180 |
+
def _range_str(dimension_key: str, mean: float, cv: float) -> str:
|
| 181 |
+
"""The actual meanΒ±std band behind a continuous signal's steady value β
|
| 182 |
+
e.g. "between 155 and 185" for a pace whose mean is 170 and cv is ~0.09.
|
| 183 |
+
No unit repeated here β curr_str right before it already states the unit
|
| 184 |
+
once. Grounded in data already computed to decide steadiness β not a new
|
| 185 |
+
measurement."""
|
| 186 |
+
try:
|
| 187 |
+
from pipeline.portrait_synthesizer import _SIGNAL_FORMAT
|
| 188 |
+
scale, fmt, _unit = _SIGNAL_FORMAT[dimension_key]
|
| 189 |
+
std = cv * abs(mean)
|
| 190 |
+
low, high = fmt.format((mean - std) * scale), fmt.format((mean + std) * scale)
|
| 191 |
+
return f"typically between {low} and {high}"
|
| 192 |
+
except (ImportError, KeyError):
|
| 193 |
+
return ""
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _agreement_str(current: dict) -> str:
|
| 197 |
+
"""How many of the recent sessions actually showed this β e.g. "8 of
|
| 198 |
+
your last 10 sessions" for a categorical trend's agreement_ratio, which
|
| 199 |
+
is already computed to decide steadiness, just never surfaced before."""
|
| 200 |
+
window_n = min(current["sample_count"], 10) # matches evidence_gate.py's ROLLING_WINDOW
|
| 201 |
+
agreement_ratio = current.get("agreement_ratio")
|
| 202 |
+
if agreement_ratio is None or window_n == 0:
|
| 203 |
+
return ""
|
| 204 |
+
agree_count = round(agreement_ratio * window_n)
|
| 205 |
+
return f"showing up in {agree_count} of your last {window_n} sessions"
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def _extra_clause(dimension_key: str, current: dict, is_categorical: bool) -> str:
|
| 209 |
+
"""The one added fact β a real range for continuous signals, a real
|
| 210 |
+
session count for categorical ones β never an interpretation of what it
|
| 211 |
+
means, just more of what was already measured."""
|
| 212 |
+
if is_categorical:
|
| 213 |
+
extra = _agreement_str(current)
|
| 214 |
+
else:
|
| 215 |
+
extra = (_range_str(dimension_key, current["mean"], current["cv"])
|
| 216 |
+
if current.get("cv") is not None else "")
|
| 217 |
+
return f" ({extra})" if extra else ""
|
| 218 |
+
|
| 219 |
+
|
| 220 |
def _phrase_event(dimension_key, label, trigger_type, direction, prior, current, cfg, scope) -> dict:
|
| 221 |
"""Deterministic string templates, no LLM call β matches home_feed.py's
|
| 222 |
existing f-string convention (e.g. the old build_progress_cards)."""
|
|
|
|
| 224 |
n = current["sample_count"]
|
| 225 |
scope_phrase = "" if scope == "overall" else f" in your {scope.replace('_', ' ')} conversations"
|
| 226 |
curr_str = current["mode_label"] if is_categorical else _value_str(dimension_key, current["mean"])
|
| 227 |
+
extra = _extra_clause(dimension_key, current, is_categorical)
|
| 228 |
|
| 229 |
if trigger_type == "first_time_steady":
|
| 230 |
note = (f"Over your last {n} sessions, your {label} has settled into a steady "
|
| 231 |
+
f"pattern β {curr_str}{extra}.")
|
| 232 |
elif trigger_type == "context_shift":
|
| 233 |
note = (f"Your {label} has also settled into a steady pattern specifically"
|
| 234 |
+
f"{scope_phrase} β {curr_str}{extra}.")
|
| 235 |
elif trigger_type == "recurring" and direction == "back_to_usual":
|
| 236 |
note = (f"Your {label} had been varying more than usual for a bit, but it's "
|
| 237 |
+
f"settled back to your usual {curr_str}{extra}.")
|
| 238 |
elif trigger_type == "recurring": # direction == "drift"
|
| 239 |
note = (f"After a stretch of inconsistency, your {label} has settled into a new "
|
| 240 |
+
f"pattern β {curr_str}{extra}.")
|
| 241 |
elif trigger_type == "drift":
|
| 242 |
prev_str = (prior.get("last_steady_mode_label") if is_categorical
|
| 243 |
else _value_str(dimension_key, prior.get("last_steady_mean")))
|
| 244 |
+
note = f"Your {label} has shifted β from {prev_str} to {curr_str}{extra} over your last {n} sessions."
|
| 245 |
else:
|
| 246 |
note = f"Your {label} showed a new pattern this session."
|
| 247 |
|