fix: deliver validated AI insight responses
This commit is contained in:
@@ -68,20 +68,37 @@ func buildOpportunities(wins []EventEffect, catalog []Event, forecast Forecast,
|
||||
}
|
||||
}
|
||||
}
|
||||
// Always surface high-intent commercial moments. Historical evidence enriches
|
||||
// the estimate when available, but its absence must not hide events merchants
|
||||
// routinely plan campaigns for.
|
||||
for _, event := range catalog {
|
||||
if event.Kind != EventCommercial || dateBefore(event.EndDate, start) {
|
||||
continue
|
||||
}
|
||||
if _, exists := best[event.ID]; exists {
|
||||
continue
|
||||
}
|
||||
point, ok := forecastByDate[dayKey(event.StartDate)]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
best[event.ID] = Opportunity{
|
||||
EvidenceID: EvidenceID("opportunity", event.ID), EventID: event.ID,
|
||||
EventTitleFA: event.TitleFA, Date: normalizeDate(event.StartDate),
|
||||
ExpectedSessions: point.PaidSessions, ExpectedAmountRial: point.PaidAmountRial,
|
||||
}
|
||||
}
|
||||
result := make([]Opportunity, 0, len(best))
|
||||
for _, opportunity := range best {
|
||||
result = append(result, opportunity)
|
||||
}
|
||||
slices.SortFunc(result, func(a, b Opportunity) int {
|
||||
if a.SimilarityBPS != b.SimilarityBPS {
|
||||
if a.SimilarityBPS > b.SimilarityBPS {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if comparison := a.Date.Compare(b.Date); comparison != 0 {
|
||||
return comparison
|
||||
}
|
||||
if a.SimilarityBPS != b.SimilarityBPS {
|
||||
return int(b.SimilarityBPS - a.SimilarityBPS)
|
||||
}
|
||||
return strings.Compare(a.EventID, b.EventID)
|
||||
})
|
||||
if len(result) > limit {
|
||||
|
||||
Reference in New Issue
Block a user