Wideband autonomous SDR analysis engine forked from sdr-visual-suite
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

62 líneas
1.7KB

  1. package pipeline
  2. import "sort"
  3. type ScheduledCandidate struct {
  4. Candidate Candidate `json:"candidate"`
  5. Priority float64 `json:"priority"`
  6. }
  7. // BuildRefinementPlan scores and budgets candidates for costly local refinement.
  8. // Current heuristic is intentionally simple and deterministic; later phases can add
  9. // richer scoring (novelty, persistence, profile-aware band priorities, decoder value).
  10. func BuildRefinementPlan(candidates []Candidate, policy Policy) RefinementPlan {
  11. plan := RefinementPlan{
  12. TotalCandidates: len(candidates),
  13. MinCandidateSNRDb: policy.MinCandidateSNRDb,
  14. Budget: policy.MaxRefinementJobs,
  15. }
  16. if len(candidates) == 0 {
  17. return plan
  18. }
  19. scored := make([]ScheduledCandidate, 0, len(candidates))
  20. for _, c := range candidates {
  21. if c.SNRDb < policy.MinCandidateSNRDb {
  22. plan.DroppedBySNR++
  23. continue
  24. }
  25. priority := c.SNRDb + CandidatePriorityBoost(policy, c.Hint)
  26. if c.BandwidthHz > 0 {
  27. priority += minFloat64(c.BandwidthHz/25000.0, 6)
  28. }
  29. if c.PeakDb > 0 {
  30. priority += c.PeakDb / 20.0
  31. }
  32. scored = append(scored, ScheduledCandidate{Candidate: c, Priority: priority})
  33. }
  34. sort.Slice(scored, func(i, j int) bool {
  35. if scored[i].Priority == scored[j].Priority {
  36. return scored[i].Candidate.CenterHz < scored[j].Candidate.CenterHz
  37. }
  38. return scored[i].Priority > scored[j].Priority
  39. })
  40. limit := policy.MaxRefinementJobs
  41. if limit <= 0 || limit > len(scored) {
  42. limit = len(scored)
  43. }
  44. plan.Selected = scored[:limit]
  45. plan.DroppedByBudget = len(scored) - len(plan.Selected)
  46. return plan
  47. }
  48. func ScheduleCandidates(candidates []Candidate, policy Policy) []ScheduledCandidate {
  49. return BuildRefinementPlan(candidates, policy).Selected
  50. }
  51. func minFloat64(a, b float64) float64 {
  52. if a < b {
  53. return a
  54. }
  55. return b
  56. }