fix: competitor lookup uses ticker join instead of UUID comparison

This commit is contained in:
Celes Renata
2026-04-14 20:04:56 +00:00
parent 2a96c8338b
commit c438d0d60a
+10 -7
View File
@@ -58,10 +58,13 @@ class CompetitiveSignalRecord:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
_COMPETITOR_LOOKUP_QUERY = """ _COMPETITOR_LOOKUP_QUERY = """
SELECT company_a_id, company_b_id, strength SELECT cr.company_a_id, cr.company_b_id, cr.strength,
FROM competitor_relationships ca.ticker AS ticker_a, cb.ticker AS ticker_b
WHERE (company_a_id = $1 OR company_b_id = $1) FROM competitor_relationships cr
AND active = TRUE JOIN companies ca ON ca.id = cr.company_a_id
JOIN companies cb ON cb.id = cr.company_b_id
WHERE (ca.ticker = $1 OR cb.ticker = $1)
AND cr.active = TRUE
""" """
_INSERT_SIGNAL_QUERY = """ _INSERT_SIGNAL_QUERY = """
@@ -117,12 +120,12 @@ async def propagate_signals(
# Step 2: For each competitor, query cross-company patterns # Step 2: For each competitor, query cross-company patterns
for row in rows: for row in rows:
company_a = str(row["company_a_id"]) ticker_a = row["ticker_a"]
company_b = str(row["company_b_id"]) ticker_b = row["ticker_b"]
rel_strength = float(row["strength"]) rel_strength = float(row["strength"])
# Determine the competitor ticker (the other side of the relationship) # Determine the competitor ticker (the other side of the relationship)
competitor_ticker = company_b if company_a == ticker else company_a competitor_ticker = ticker_b if ticker_a == ticker else ticker_a
# Threshold gating (Req 4.5) # Threshold gating (Req 4.5)
if rel_strength < cfg.propagation_strength_threshold: if rel_strength < cfg.propagation_strength_threshold: