fix: deliver validated AI insight responses
This commit is contained in:
@@ -2,69 +2,12 @@ package growth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const officialCalendarSource = "https://calendar.ut.ac.ir/"
|
||||
const curatedCommercialSource = "CURATED_COMMERCIAL_1405_V1"
|
||||
const officialCalendarVersion = "IR_OFFICIAL_1404_1405_REVIEWED_2026-08-21"
|
||||
|
||||
var importedMerchantCategories = []string{
|
||||
"ارائه دهنده خدمات اینترنت",
|
||||
"مراکز آموزشی مجازی",
|
||||
"کیف و کفش فروشی",
|
||||
"خدمات شبکههای کامپیوتری و اینترنت",
|
||||
"فروشگاه لوازم آرایشی و بهداشتی",
|
||||
}
|
||||
|
||||
// Catalog1405 returns a defensive copy of the reviewed initial catalog. Dates are
|
||||
// Gregorian Tehran-local calendar dates and cover the imported 1405 history plus
|
||||
// the first 90 forecast days after 2026-06-30.
|
||||
func Catalog1405() []Event {
|
||||
events := []Event{
|
||||
officialEvent("fathers-day-1404", "روز پدر", "2026-01-03", "2026-01-03", "appreciation", true, []string{"هدیه", "قدردانی"}),
|
||||
officialEvent("mabath-1404", "مبعث پیامبر اکرم", "2026-01-17", "2026-01-17", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("imam-mahdi-birthday-1404", "نیمه شعبان", "2026-02-04", "2026-02-04", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("revolution-day-1404", "پیروزی انقلاب اسلامی", "2026-02-11", "2026-02-11", "national-holiday", true, []string{"تعطیل", "مناسبت-ملی"}),
|
||||
officialEvent("imam-ali-martyrdom-1404", "شهادت امام علی", "2026-03-11", "2026-03-11", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("oil-nationalization-1404", "ملی شدن صنعت نفت", "2026-03-19", "2026-03-19", "national-holiday", true, []string{"تعطیل", "مناسبت-ملی"}),
|
||||
officialEvent("nowruz-1405", "نوروز", "2026-03-21", "2026-03-24", "new-year", true, []string{"هدیه", "خرید", "سال-نو", "تعطیل"}),
|
||||
officialEvent("islamic-republic-day-1405", "روز جمهوری اسلامی", "2026-04-01", "2026-04-01", "national-holiday", true, []string{"تعطیل", "مناسبت-ملی"}),
|
||||
officialEvent("nature-day-1405", "روز طبیعت", "2026-04-02", "2026-04-02", "leisure", true, []string{"تفریح", "خرید", "تعطیل"}),
|
||||
officialEvent("imam-sadegh-martyrdom-1405", "شهادت امام جعفر صادق", "2026-04-14", "2026-04-14", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("teachers-day-1405", "روز معلم", "2026-05-02", "2026-05-02", "appreciation", false, []string{"هدیه", "آموزش", "قدردانی"}),
|
||||
officialEvent("eid-al-adha-1405", "عید قربان", "2026-05-27", "2026-05-27", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("khomeini-ghadir-1405", "رحلت امام خمینی و عید غدیر", "2026-06-04", "2026-06-04", "official-holiday", true, []string{"تعطیل", "مناسبت-ملی", "مناسبت-مذهبی"}),
|
||||
officialEvent("khordad-15-1405", "قیام پانزده خرداد", "2026-06-05", "2026-06-05", "national-holiday", true, []string{"تعطیل", "مناسبت-ملی"}),
|
||||
officialEvent("tasua-1405", "تاسوعای حسینی", "2026-06-24", "2026-06-24", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("ashura-1405", "عاشورای حسینی", "2026-06-25", "2026-06-25", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
commercialEvent("summer-midseason-1405", "میانه فصل تابستان", "2026-07-15", "2026-07-17", "seasonal-shopping", []string{"خرید", "تابستان", "پیشنهاد-فصلی"}, importedMerchantCategories),
|
||||
officialEvent("arbaeen-1405", "اربعین حسینی", "2026-08-04", "2026-08-04", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("prophet-demise-1405", "رحلت پیامبر اکرم و شهادت امام حسن", "2026-08-12", "2026-08-12", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
officialEvent("doctors-day-1405", "روز پزشک", "2026-08-23", "2026-08-23", "appreciation", false, []string{"هدیه", "قدردانی", "حرفهای"}),
|
||||
officialEvent("prophet-birthday-1405", "میلاد پیامبر اکرم و امام جعفر صادق", "2026-08-30", "2026-08-30", "religious-holiday", true, []string{"تعطیل", "مناسبت-مذهبی"}),
|
||||
commercialEvent("back-to-school-1405", "آمادگی بازگشایی مدارس", "2026-09-10", "2026-09-22", "education-season", []string{"آموزش", "خرید", "مدرسه"}, []string{"مراکز آموزشی مجازی", "کیف و کفش فروشی"}),
|
||||
commercialEvent("autumn-opening-1405", "آغاز فصل پاییز", "2026-09-23", "2026-09-28", "seasonal-shopping", []string{"خرید", "پاییز", "پیشنهاد-فصلی"}, importedMerchantCategories),
|
||||
}
|
||||
result := make([]Event, len(events))
|
||||
for index, event := range events {
|
||||
result[index] = event
|
||||
result[index].Tags = slices.Clone(event.Tags)
|
||||
result[index].Categories = slices.Clone(event.Categories)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func officialEvent(id, title, start, end, family string, holiday bool, tags []string) Event {
|
||||
return Event{ID: id, TitleFA: title, StartDate: mustCatalogDate(start), EndDate: mustCatalogDate(end), Family: family, Tags: slices.Clone(tags), Source: officialCalendarSource, SourceVersion: officialCalendarVersion, Kind: EventOfficial, OfficialHoliday: holiday, Universal: true}
|
||||
}
|
||||
|
||||
func commercialEvent(id, title, start, end, family string, tags, categories []string) Event {
|
||||
return Event{ID: id, TitleFA: title, StartDate: mustCatalogDate(start), EndDate: mustCatalogDate(end), Family: family, Tags: slices.Clone(tags), Source: curatedCommercialSource, SourceVersion: CatalogVersion, Categories: slices.Clone(categories), Kind: EventCommercial, Universal: false}
|
||||
}
|
||||
|
||||
// ValidateCatalog validates the database-backed catalog after it has been
|
||||
// mapped into the deterministic growth model. Production catalog contents are
|
||||
// intentionally not embedded here; calendar_events is the sole source.
|
||||
func ValidateCatalog(events []Event) error {
|
||||
seen := make(map[string]struct{}, len(events))
|
||||
for index, event := range events {
|
||||
@@ -93,11 +36,3 @@ func ValidateCatalog(events []Event) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func mustCatalogDate(value string) time.Time {
|
||||
parsed, err := time.Parse(time.DateOnly, value)
|
||||
if err != nil {
|
||||
panic("invalid reviewed event catalog date: " + value)
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user