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

78 строки
2.1KB

  1. package pipeline
  2. import "strings"
  3. type BudgetQueue struct {
  4. Max int `json:"max"`
  5. IntentBias float64 `json:"intent_bias,omitempty"`
  6. Source string `json:"source,omitempty"`
  7. }
  8. type BudgetModel struct {
  9. Refinement BudgetQueue `json:"refinement"`
  10. Record BudgetQueue `json:"record"`
  11. Decode BudgetQueue `json:"decode"`
  12. HoldMs int `json:"hold_ms"`
  13. Intent string `json:"intent,omitempty"`
  14. Profile string `json:"profile,omitempty"`
  15. Strategy string `json:"strategy,omitempty"`
  16. }
  17. func BudgetModelFromPolicy(policy Policy) BudgetModel {
  18. recordBias, decodeBias := budgetIntentBias(policy.Intent)
  19. refBudget, refSource := refinementBudgetFromPolicy(policy)
  20. return BudgetModel{
  21. Refinement: BudgetQueue{
  22. Max: refBudget,
  23. Source: refSource,
  24. },
  25. Record: BudgetQueue{
  26. Max: policy.MaxRecordingStreams,
  27. IntentBias: recordBias,
  28. Source: "resources.max_recording_streams",
  29. },
  30. Decode: BudgetQueue{
  31. Max: policy.MaxDecodeJobs,
  32. IntentBias: decodeBias,
  33. Source: "resources.max_decode_jobs",
  34. },
  35. HoldMs: policy.DecisionHoldMs,
  36. Intent: policy.Intent,
  37. Profile: policy.Profile,
  38. Strategy: policy.RefinementStrategy,
  39. }
  40. }
  41. func refinementBudgetFromPolicy(policy Policy) (int, string) {
  42. budget := policy.MaxRefinementJobs
  43. source := "resources.max_refinement_jobs"
  44. if policy.RefinementMaxConcurrent > 0 && (budget <= 0 || policy.RefinementMaxConcurrent < budget) {
  45. budget = policy.RefinementMaxConcurrent
  46. source = "refinement.max_concurrent"
  47. }
  48. return budget, source
  49. }
  50. func budgetIntentBias(intent string) (float64, float64) {
  51. if intent == "" {
  52. return 0, 0
  53. }
  54. recordBias := 0.0
  55. decodeBias := 0.0
  56. intent = strings.ToLower(intent)
  57. if strings.Contains(intent, "archive") || strings.Contains(intent, "record") {
  58. recordBias += 1.5
  59. }
  60. if strings.Contains(intent, "triage") {
  61. recordBias += 0.5
  62. decodeBias += 0.5
  63. }
  64. if strings.Contains(intent, "decode") || strings.Contains(intent, "analysis") {
  65. decodeBias += 1.0
  66. }
  67. if strings.Contains(intent, "digital") {
  68. decodeBias += 0.5
  69. }
  70. return recordBias, decodeBias
  71. }