Wideband autonomous SDR analysis engine forked from sdr-visual-suite
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

55 строки
1.4KB

  1. package pipeline
  2. import "strings"
  3. func WantsClass(values []string, class string) bool {
  4. if len(values) == 0 || class == "" {
  5. return false
  6. }
  7. for _, v := range values {
  8. if strings.EqualFold(strings.TrimSpace(v), class) {
  9. return true
  10. }
  11. }
  12. return false
  13. }
  14. func CandidatePriorityBoost(policy Policy, hint string) float64 {
  15. boost := hintMatchBoost(policy.SignalPriorities, hint, 3.0)
  16. boost += hintMatchBoost(policy.AutoRecordClasses, hint, 1.5)
  17. boost += hintMatchBoost(policy.AutoDecodeClasses, hint, 1.0)
  18. return boost
  19. }
  20. func DecisionPriorityBoost(policy Policy, hint string, class string, queue string) float64 {
  21. tag := strings.TrimSpace(hint)
  22. if tag == "" {
  23. tag = strings.TrimSpace(class)
  24. }
  25. boost := CandidatePriorityBoost(policy, tag)
  26. switch strings.ToLower(strings.TrimSpace(queue)) {
  27. case "record":
  28. boost += hintMatchBoost(policy.AutoRecordClasses, tag, 3.0)
  29. case "decode":
  30. boost += hintMatchBoost(policy.AutoDecodeClasses, tag, 3.0)
  31. }
  32. return boost
  33. }
  34. func hintMatchBoost(values []string, hint string, weight float64) float64 {
  35. h := strings.ToLower(strings.TrimSpace(hint))
  36. if h == "" || len(values) == 0 {
  37. return 0
  38. }
  39. for i, want := range values {
  40. w := strings.ToLower(strings.TrimSpace(want))
  41. if w == "" {
  42. continue
  43. }
  44. if strings.Contains(h, w) || strings.Contains(w, h) {
  45. return float64(len(values)-i) * weight
  46. }
  47. }
  48. return 0
  49. }