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.

114 líneas
3.2KB

  1. package main
  2. import (
  3. "sort"
  4. "sdr-wideband-suite/internal/pipeline"
  5. )
  6. type WindowSummary struct {
  7. Refinement *RefinementWindowStats `json:"refinement,omitempty"`
  8. MonitorWindows []pipeline.MonitorWindowStats `json:"monitor_windows,omitempty"`
  9. }
  10. func buildWindowSummary(plan pipeline.RefinementPlan, refinementWindows []pipeline.RefinementWindow, candidates []pipeline.Candidate) *WindowSummary {
  11. refinementStats := buildWindowStats(refinementWindows)
  12. monitorSummary := buildMonitorWindowSummary(plan.MonitorWindows, plan.MonitorWindowStats, candidates)
  13. if refinementStats == nil && len(monitorSummary) == 0 {
  14. return nil
  15. }
  16. return &WindowSummary{
  17. Refinement: refinementStats,
  18. MonitorWindows: monitorSummary,
  19. }
  20. }
  21. func buildMonitorWindowSummary(windows []pipeline.MonitorWindow, stats []pipeline.MonitorWindowStats, candidates []pipeline.Candidate) []pipeline.MonitorWindowStats {
  22. var summary []pipeline.MonitorWindowStats
  23. switch {
  24. case len(stats) > 0:
  25. summary = append([]pipeline.MonitorWindowStats(nil), stats...)
  26. case len(windows) > 0:
  27. summary = make([]pipeline.MonitorWindowStats, 0, len(windows))
  28. for _, win := range windows {
  29. summary = append(summary, pipeline.MonitorWindowStats{
  30. Index: win.Index,
  31. Label: win.Label,
  32. Zone: win.Zone,
  33. Source: win.Source,
  34. StartHz: win.StartHz,
  35. EndHz: win.EndHz,
  36. CenterHz: win.CenterHz,
  37. SpanHz: win.SpanHz,
  38. Priority: win.Priority,
  39. PriorityBias: win.PriorityBias,
  40. RecordBias: win.RecordBias,
  41. DecodeBias: win.DecodeBias,
  42. AutoRecord: win.AutoRecord,
  43. AutoDecode: win.AutoDecode,
  44. })
  45. }
  46. default:
  47. return nil
  48. }
  49. if len(candidates) > 0 && len(summary) > 0 {
  50. windowsForMatch := windows
  51. if len(windowsForMatch) == 0 {
  52. windowsForMatch = monitorWindowsFromStats(summary)
  53. }
  54. if len(windowsForMatch) > 0 {
  55. counts := map[int]int{}
  56. total := 0
  57. for _, cand := range candidates {
  58. matches := cand.MonitorMatches
  59. if len(matches) == 0 {
  60. matches = pipeline.MonitorWindowMatchesForCandidate(windowsForMatch, cand)
  61. }
  62. for _, match := range matches {
  63. counts[match.Index]++
  64. total++
  65. }
  66. }
  67. if total > 0 {
  68. for i := range summary {
  69. if summary[i].Candidates == 0 {
  70. summary[i].Candidates = counts[summary[i].Index]
  71. }
  72. }
  73. }
  74. }
  75. }
  76. sort.Slice(summary, func(i, j int) bool {
  77. return summary[i].Index < summary[j].Index
  78. })
  79. return summary
  80. }
  81. func monitorWindowsFromStats(stats []pipeline.MonitorWindowStats) []pipeline.MonitorWindow {
  82. if len(stats) == 0 {
  83. return nil
  84. }
  85. windows := make([]pipeline.MonitorWindow, 0, len(stats))
  86. for _, stat := range stats {
  87. windows = append(windows, pipeline.MonitorWindow{
  88. Index: stat.Index,
  89. Label: stat.Label,
  90. Zone: stat.Zone,
  91. Source: stat.Source,
  92. StartHz: stat.StartHz,
  93. EndHz: stat.EndHz,
  94. CenterHz: stat.CenterHz,
  95. SpanHz: stat.SpanHz,
  96. Priority: stat.Priority,
  97. PriorityBias: stat.PriorityBias,
  98. RecordBias: stat.RecordBias,
  99. DecodeBias: stat.DecodeBias,
  100. AutoRecord: stat.AutoRecord,
  101. AutoDecode: stat.AutoDecode,
  102. })
  103. }
  104. return windows
  105. }