Implement deeper analysis of people and access to the underlying data in the database
This commit is contained in:
@@ -338,7 +338,7 @@ INSIGHT_METRICS = {
|
||||
"last_event": {
|
||||
"title": "Last Event",
|
||||
"group": "timeline",
|
||||
"history_field": "source_event_ts",
|
||||
"history_field": None,
|
||||
"calculation": "Unix ms timestamp of the newest message in this workspace.",
|
||||
"psychology": (
|
||||
"Long inactivity windows can indicate pause, repair distance, or "
|
||||
@@ -493,14 +493,6 @@ INSIGHT_GRAPH_SPECS = [
|
||||
"y_min": 0,
|
||||
"y_max": 100,
|
||||
},
|
||||
{
|
||||
"slug": "last_event",
|
||||
"title": "Last Event Timestamp",
|
||||
"field": "source_event_ts",
|
||||
"group": "timeline",
|
||||
"y_min": None,
|
||||
"y_max": None,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@@ -708,6 +700,36 @@ def _format_metric_value(conversation, metric_slug, latest_snapshot=None):
|
||||
|
||||
|
||||
def _metric_psychological_read(metric_slug, conversation):
|
||||
if metric_slug == "stability_state":
|
||||
state = conversation.stability_state
|
||||
if state == WorkspaceConversation.StabilityState.CALIBRATING:
|
||||
return (
|
||||
"Calibrating means the system does not yet have enough longitudinal "
|
||||
"signal to classify friction reliably. Prioritize collecting a few "
|
||||
"more days of normal interaction before drawing conclusions."
|
||||
)
|
||||
if state == WorkspaceConversation.StabilityState.STABLE:
|
||||
return (
|
||||
"Stable indicates low-friction reciprocity and predictable cadence in "
|
||||
"the sampled window. Keep routines consistent and focus on maintenance "
|
||||
"habits rather than heavy corrective interventions."
|
||||
)
|
||||
if state == WorkspaceConversation.StabilityState.WATCH:
|
||||
return (
|
||||
"Watch indicates meaningful strain without full collapse. This often "
|
||||
"matches early misunderstanding cycles: repair is still easy if you "
|
||||
"slow pace, validate first, and reduce escalation triggers."
|
||||
)
|
||||
if state == WorkspaceConversation.StabilityState.FRAGILE:
|
||||
return (
|
||||
"Fragile indicates high volatility or directional imbalance in recent "
|
||||
"interaction. Use short, clear, safety-first communication and avoid "
|
||||
"high-load conversations until cadence normalizes."
|
||||
)
|
||||
return (
|
||||
"State is an operational risk band, not a diagnosis. Read it alongside "
|
||||
"confidence and recent events."
|
||||
)
|
||||
if metric_slug == "stability_score":
|
||||
score = conversation.stability_score
|
||||
if score is None:
|
||||
@@ -760,6 +782,12 @@ def _history_points(conversation, field_name):
|
||||
return points
|
||||
|
||||
|
||||
def _metric_supports_history(metric_slug, metric_spec):
|
||||
if not metric_spec.get("history_field"):
|
||||
return False
|
||||
return any(graph["slug"] == metric_slug for graph in INSIGHT_GRAPH_SPECS)
|
||||
|
||||
|
||||
def _all_graph_payload(conversation):
|
||||
graphs = []
|
||||
for spec in INSIGHT_GRAPH_SPECS:
|
||||
@@ -2902,8 +2930,9 @@ class AIWorkspaceInsightDetail(LoginRequiredMixin, View):
|
||||
latest_snapshot = conversation.metric_snapshots.first()
|
||||
value = _format_metric_value(conversation, metric, latest_snapshot)
|
||||
group = INSIGHT_GROUPS[spec["group"]]
|
||||
graph_applicable = _metric_supports_history(metric, spec)
|
||||
points = []
|
||||
if spec["history_field"]:
|
||||
if graph_applicable:
|
||||
points = _history_points(conversation, spec["history_field"])
|
||||
|
||||
context = {
|
||||
@@ -2915,6 +2944,7 @@ class AIWorkspaceInsightDetail(LoginRequiredMixin, View):
|
||||
"metric_psychology_hint": _metric_psychological_read(metric, conversation),
|
||||
"metric_group": group,
|
||||
"graph_points": points,
|
||||
"graph_applicable": graph_applicable,
|
||||
"graphs_url": reverse(
|
||||
"ai_workspace_insight_graphs",
|
||||
kwargs={"type": "page", "person_id": person.id},
|
||||
|
||||
Reference in New Issue
Block a user