From 9ea9a4291c6b5db5e26755c2e72360b782e89ea6 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Wed, 16 Sep 2026 16:54:27 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20scheduler=20tangkap=20company=20name=20?= =?UTF-8?q?dari=20top-changes=20(n=3D750)=20=E2=80=94=20gratis,=20isi=20ya?= =?UTF-8?q?ng=20kosong=20saja?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/scheduler/scheduler.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/internal/scheduler/scheduler.go b/backend/internal/scheduler/scheduler.go index 3e3ccdb..e8e1e18 100644 --- a/backend/internal/scheduler/scheduler.go +++ b/backend/internal/scheduler/scheduler.go @@ -12,6 +12,7 @@ import ( "log" "net/url" "strconv" + "strings" "time" "github.com/robfig/cron/v3" @@ -295,13 +296,31 @@ func (s *Scheduler) universe(ctx context.Context) error { } // market pulls top-changes (1 class x 2 periods), most-traded, idx-total, -// brokers/top — the cheap context block of the cycle. +// brokers/top — the cheap context block of the cycle. The top-changes call +// also enriches universe company names (MoverRow.Name) at no extra credit — +// n_stock is free; cost is classes×periods only. func (s *Scheduler) market(ctx context.Context) error { if g, l, err := s.Sectors.TopChanges(ctx, - []string{"top_gainers"}, []string{"1d", "7d"}, "", 5); err == nil { + []string{"top_gainers"}, []string{"1d", "7d"}, "", 750); err == nil { if raw, err := json.Marshal(map[string]any{"top_gainers": g, "top_losers": l}); err == nil { _ = s.DB.SaveSnapshot("IDX", time.Now().Format("2006-01-02"), "top-changes", string(raw)) } + // Capture company names from whatever mover rows came back. + names := map[string]string{} + collect := func(rows map[string][]sectors.MoverRow) { + for _, rs := range rows { + for _, r := range rs { + if r.Name != "" { + names[strings.TrimSuffix(r.Symbol, ".JK")] = r.Name + } + } + } + } + collect(g) + collect(l) + if err := s.DB.SetCompanyNames(names); err != nil { + log.Printf("scheduler: set company names: %v", err) + } } else { return err }