diff --git a/agent.py b/agent.py index 87ca724..f5cf8e5 100644 --- a/agent.py +++ b/agent.py @@ -455,14 +455,32 @@ async def _save_comparison(tenant_key: str, comparison_id: str, result: dict[str with conn.cursor() as cur: cur.execute( """ - INSERT INTO quote_comparisons (tenant_key, comparison_id, recommendation_vendor, result) - VALUES (%s, %s, %s, %s) + INSERT INTO quote_comparisons ( + tenant_key, comparison_id, recommendation_vendor, recommended_vendor, + result, payload, weighted_score, score, normalized_total + ) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s) ON CONFLICT (tenant_key, comparison_id) DO UPDATE SET recommendation_vendor = EXCLUDED.recommendation_vendor, + recommended_vendor = EXCLUDED.recommended_vendor, result = EXCLUDED.result, + payload = EXCLUDED.payload, + weighted_score = EXCLUDED.weighted_score, + score = EXCLUDED.score, + normalized_total = EXCLUDED.normalized_total, updated_at = NOW() """, - (tenant_key, comparison_id, result["recommendation"]["vendor"], json.dumps(result)), + ( + tenant_key, + comparison_id, + result["recommendation"]["vendor"], + result["recommendation"]["vendor"], + json.dumps(result), + json.dumps(result), + result["recommendation"]["score"], + result["recommendation"]["score"], + result["recommendation"]["score"], + ), )