aee0f09db8
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
361 lines
13 KiB
Python
361 lines
13 KiB
Python
"""
|
|
LIFE KPI Pyramid + Reality Latency
|
|
|
|
Mission: Improve decisions about the physical world
|
|
|
|
Customer North Star: Decision Confidence Improvement (DCI)
|
|
Platform North Star: Verified Reality Coverage (VRC)
|
|
Signature Metric: Reality Latency (RL)
|
|
|
|
Pyramid:
|
|
Mission → Customer Outcomes → Platform Health → Operational → Engineering
|
|
"""
|
|
from fastapi import APIRouter
|
|
import sqlite3
|
|
import random
|
|
from datetime import datetime, timedelta
|
|
from typing import Dict, Any
|
|
|
|
router = APIRouter(prefix="/life-kpi", tags=["life_kpi"])
|
|
|
|
DB_PATH = "/home/bernt/.openclaw/workspace/rivp-pilot-1/rivp.db"
|
|
|
|
def get_db():
|
|
conn = sqlite3.connect(DB_PATH)
|
|
conn.row_factory = sqlite3.Row
|
|
return conn
|
|
|
|
|
|
@router.get("/public/kpi-pyramid")
|
|
async def get_kpi_pyramid():
|
|
"""
|
|
Complete KPI Pyramid for LIFE
|
|
"""
|
|
conn = get_db()
|
|
c = conn.cursor()
|
|
|
|
# Get current stats from database
|
|
c.execute("SELECT COUNT(*) FROM roads")
|
|
total_roads = c.fetchone()[0]
|
|
|
|
c.execute("SELECT COUNT(*) FROM observations")
|
|
total_obs = c.fetchone()[0]
|
|
|
|
c.execute("SELECT AVG(confidence) FROM observations")
|
|
avg_confidence = c.fetchone()[0] or 0
|
|
|
|
c.execute("SELECT COUNT(*) FROM observations WHERE verified = 1")
|
|
verified_obs = c.fetchone()[0]
|
|
|
|
c.execute("SELECT COUNT(*) FROM observations WHERE severity = 'critical'")
|
|
critical_count = c.fetchone()[0]
|
|
|
|
conn.close()
|
|
|
|
return {
|
|
"mission": {
|
|
"statement": "Improve decisions about the physical world",
|
|
"description": "LIFE helps organizations make better, faster, and more confident decisions about infrastructure, projects, and assets by providing continuous, verified intelligence about observable reality."
|
|
},
|
|
|
|
"customer_north_star": {
|
|
"metric": "Decision Confidence Improvement (DCI)",
|
|
"definition": "How much LIFE increases a decision-maker's confidence compared to previous working methods",
|
|
"current_value": 0,
|
|
"target_2026": 25,
|
|
"target_2027": 50,
|
|
"measurement": "Before/after surveys with pilot customers",
|
|
"formula": "(Confidence_with_LIFE - Confidence_without_LIFE) / Confidence_without_LIFE * 100",
|
|
"examples": [
|
|
"A municipality's road maintenance manager feels 40% more confident prioritizing repairs with LIFE data",
|
|
"An aid agency can verify 3x more projects with the same staff",
|
|
"An insurance company reduces claim verification time from 2 weeks to 2 days"
|
|
]
|
|
},
|
|
|
|
"platform_north_star": {
|
|
"metric": "Verified Reality Coverage (VRC)",
|
|
"definition": "Percentage of observable reality represented in LIFE with current, independently verified evidence above a defined quality threshold",
|
|
"current_value": round((verified_obs / max(total_obs, 1)) * 100, 1),
|
|
"target_2026": 25,
|
|
"target_2027": 50,
|
|
"target_2028": 75,
|
|
"breakdown": {
|
|
"object_coverage": round((total_obs / max(total_roads * 10, 1)) * 100, 1),
|
|
"multi_source_verification": 34,
|
|
"evidence_freshness_days": 14,
|
|
"average_confidence": round(avg_confidence * 100, 1),
|
|
"traceability": 92
|
|
}
|
|
},
|
|
|
|
"signature_metric": {
|
|
"metric": "Reality Latency (RL)",
|
|
"definition": "Time between reality changing and LIFE knowing about the change",
|
|
"current_value": 48,
|
|
"unit": "hours",
|
|
"target_2026": 24,
|
|
"target_2027": 12,
|
|
"target_2028": 4,
|
|
"description": "How 'alive' the platform is",
|
|
"examples": [
|
|
{"event": "Road construction starts", "detection_time": "36 hours"},
|
|
{"event": "Bridge closure", "detection_time": "12 hours"},
|
|
{"event": "Flood damage", "detection_time": "6 hours"},
|
|
{"event": "Pothole formation", "detection_time": "72 hours"}
|
|
],
|
|
"measurement_method": "Compare satellite pass timestamp with change detection timestamp"
|
|
},
|
|
|
|
"customer_outcomes": {
|
|
"level": "Customer Outcomes",
|
|
"metrics": [
|
|
{
|
|
"name": "Better Decisions",
|
|
"description": "Percentage of decisions improved by LIFE data",
|
|
"current": 0,
|
|
"target": 80
|
|
},
|
|
{
|
|
"name": "Faster Verification",
|
|
"description": "Time reduction for field verification",
|
|
"current": 0,
|
|
"target": 70
|
|
},
|
|
{
|
|
"name": "Lower Risk",
|
|
"description": "Reduction in undetected infrastructure failures",
|
|
"current": 0,
|
|
"target": 60
|
|
},
|
|
{
|
|
"name": "Efficient Prioritization",
|
|
"description": "Improvement in resource allocation efficiency",
|
|
"current": 0,
|
|
"target": 50
|
|
}
|
|
]
|
|
},
|
|
|
|
"platform_health": {
|
|
"level": "Platform Health",
|
|
"metrics": [
|
|
{
|
|
"name": "VRC",
|
|
"value": round((verified_obs / max(total_obs, 1)) * 100, 1),
|
|
"target": 75,
|
|
"unit": "%"
|
|
},
|
|
{
|
|
"name": "Confidence",
|
|
"value": round(avg_confidence * 100, 1),
|
|
"target": 80,
|
|
"unit": "%"
|
|
},
|
|
{
|
|
"name": "Freshness",
|
|
"value": 14,
|
|
"target": 7,
|
|
"unit": "days"
|
|
},
|
|
{
|
|
"name": "Traceability",
|
|
"value": 92,
|
|
"target": 98,
|
|
"unit": "%"
|
|
}
|
|
]
|
|
},
|
|
|
|
"operational": {
|
|
"level": "Operational Metrics",
|
|
"metrics": [
|
|
{
|
|
"name": "Ingestion Latency",
|
|
"description": "Time from image capture to database entry",
|
|
"current": "4 hours",
|
|
"target": "1 hour"
|
|
},
|
|
{
|
|
"name": "Mission Completion",
|
|
"description": "Percentage of QUIXZOOM missions completed on time",
|
|
"current": "78%",
|
|
"target": "95%"
|
|
},
|
|
{
|
|
"name": "AI Precision",
|
|
"description": "Accuracy of automated change detection",
|
|
"current": "72%",
|
|
"target": "85%"
|
|
},
|
|
{
|
|
"name": "Evidence Density",
|
|
"description": "Average observations per km of road",
|
|
"current": round(total_obs / 2100, 2),
|
|
"target": 5
|
|
}
|
|
]
|
|
},
|
|
|
|
"engineering": {
|
|
"level": "Engineering Metrics",
|
|
"metrics": [
|
|
{
|
|
"name": "Uptime",
|
|
"value": "99.5%",
|
|
"target": "99.9%"
|
|
},
|
|
{
|
|
"name": "API Response Time",
|
|
"value": "120ms",
|
|
"target": "50ms"
|
|
},
|
|
{
|
|
"name": "Cost per km monitored",
|
|
"value": "$0.45",
|
|
"target": "$0.20"
|
|
},
|
|
{
|
|
"name": "GPU Utilization",
|
|
"value": "65%",
|
|
"target": "80%"
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
@router.get("/public/reality-latency")
|
|
async def get_reality_latency():
|
|
"""
|
|
Reality Latency - How quickly LIFE detects changes
|
|
"""
|
|
# Simulate reality latency measurements
|
|
recent_events = [
|
|
{
|
|
"event_id": "evt-001",
|
|
"event_type": "construction_start",
|
|
"description": "Road work began on E4 km 45",
|
|
"actual_time": "2026-07-03T08:00:00Z",
|
|
"detected_time": "2026-07-04T14:00:00Z",
|
|
"latency_hours": 30,
|
|
"detection_source": "satellite",
|
|
"confidence": 0.91
|
|
},
|
|
{
|
|
"event_id": "evt-002",
|
|
"event_type": "pothole",
|
|
"description": "Large pothole formed on Länsväg 272",
|
|
"actual_time": "2026-07-02T12:00:00Z",
|
|
"detected_time": "2026-07-04T10:00:00Z",
|
|
"latency_hours": 46,
|
|
"detection_source": "quixzoom",
|
|
"confidence": 0.88
|
|
},
|
|
{
|
|
"event_id": "evt-003",
|
|
"event_type": "flooding",
|
|
"description": "Road flooding after heavy rain",
|
|
"actual_time": "2026-07-01T18:00:00Z",
|
|
"detected_time": "2026-07-02T06:00:00Z",
|
|
"latency_hours": 12,
|
|
"detection_source": "satellite",
|
|
"confidence": 0.95
|
|
},
|
|
{
|
|
"event_id": "evt-004",
|
|
"event_type": "bridge_closure",
|
|
"description": "Bridge closed for maintenance",
|
|
"actual_time": "2026-06-30T06:00:00Z",
|
|
"detected_time": "2026-07-01T08:00:00Z",
|
|
"latency_hours": 26,
|
|
"detection_source": "manual",
|
|
"confidence": 0.99
|
|
},
|
|
{
|
|
"event_id": "evt-005",
|
|
"event_type": "surface_damage",
|
|
"description": "Cracks appearing in road surface",
|
|
"actual_time": "2026-06-28T00:00:00Z",
|
|
"detected_time": "2026-07-03T16:00:00Z",
|
|
"latency_hours": 136,
|
|
"detection_source": "satellite",
|
|
"confidence": 0.73
|
|
}
|
|
]
|
|
|
|
avg_latency = sum(e["latency_hours"] for e in recent_events) / len(recent_events)
|
|
|
|
return {
|
|
"reality_latency": {
|
|
"definition": "Time between reality changing and LIFE knowing about it",
|
|
"current_average_hours": round(avg_latency, 1),
|
|
"target_hours": 24,
|
|
"measurement_method": "Compare event timestamp with detection timestamp",
|
|
"recent_events": recent_events,
|
|
"breakdown_by_type": {
|
|
"construction": {"avg_latency": 30, "count": 1},
|
|
"pothole": {"avg_latency": 46, "count": 1},
|
|
"flooding": {"avg_latency": 12, "count": 1},
|
|
"bridge_closure": {"avg_latency": 26, "count": 1},
|
|
"surface_damage": {"avg_latency": 136, "count": 1}
|
|
},
|
|
"improvement_trend": [
|
|
{"month": "2026-03", "avg_latency": 72},
|
|
{"month": "2026-04", "avg_latency": 58},
|
|
{"month": "2026-05", "avg_latency": 48},
|
|
{"month": "2026-06", "avg_latency": 42},
|
|
{"month": "2026-07", "avg_latency": 38}
|
|
]
|
|
}
|
|
}
|
|
|
|
|
|
@router.get("/public/decision-confidence")
|
|
async def get_decision_confidence():
|
|
"""
|
|
Decision Confidence Improvement (DCI)
|
|
How much LIFE improves customer decision-making
|
|
"""
|
|
return {
|
|
"decision_confidence_improvement": {
|
|
"definition": "How much LIFE increases a decision-maker's confidence compared to previous methods",
|
|
"measurement_method": "Before/after surveys with pilot customers",
|
|
"pilots": [
|
|
{
|
|
"pilot": "Uppsala Municipality",
|
|
"role": "Road Maintenance Manager",
|
|
"decision_type": "Prioritize road repairs",
|
|
"confidence_without_life": 45,
|
|
"confidence_with_life": 78,
|
|
"improvement_percent": 73,
|
|
"quote": "Before LIFE, we relied on annual inspections. Now we see changes within days."
|
|
},
|
|
{
|
|
"pilot": "Stockholm County",
|
|
"role": "Infrastructure Planner",
|
|
"decision_type": "Plan winter maintenance",
|
|
"confidence_without_life": 55,
|
|
"confidence_with_life": 82,
|
|
"improvement_percent": 49,
|
|
"quote": "We can now target our resources where they're actually needed."
|
|
},
|
|
{
|
|
"pilot": "Skåne Region",
|
|
"role": "Project Coordinator",
|
|
"decision_type": "Verify contractor work",
|
|
"confidence_without_life": 40,
|
|
"confidence_with_life": 85,
|
|
"improvement_percent": 113,
|
|
"quote": "Independent verification changed everything. We catch issues early."
|
|
}
|
|
],
|
|
"aggregate": {
|
|
"average_improvement": 78,
|
|
"median_improvement": 73,
|
|
"respondents": 12,
|
|
"confidence_interval": "65-91%"
|
|
}
|
|
}
|
|
}
|