-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement control signal handling and range filter reloading
- Added a new control signal monitor in the Processor to handle reload requests for the range filter. - Introduced a ReloadRangeFilter function to update the species list based on the current date. - Enhanced the Handlers to include a control channel for sending reload signals when relevant settings change. - Implemented a check for changes in range filter settings to trigger reloads, improving configuration management.
- Loading branch information
Showing
4 changed files
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package processor | ||
|
||
import "log" | ||
|
||
// Control signal types | ||
const ( | ||
ReloadRangeFilter = "reload_range_filter" | ||
ReloadBirdNET = "reload_birdnet" | ||
) | ||
|
||
// controlSignalMonitor handles various control signals for the processor | ||
func (p *Processor) controlSignalMonitor() { | ||
go func() { | ||
for signal := range p.controlChan { | ||
switch signal { | ||
case ReloadRangeFilter: | ||
if err := p.ReloadRangeFilter(); err != nil { | ||
log.Printf("\033[31m❌ Error handling range filter reload: %v\033[0m", err) | ||
} else { | ||
log.Printf("\033[32m🔄 Range filter reloaded successfully\033[0m") | ||
} | ||
default: | ||
log.Printf("Received unknown control signal: %v", signal) | ||
} | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,26 @@ | ||
package processor | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
"time" | ||
) | ||
|
||
// Add or update the updateIncludedSpecies function | ||
func (p *Processor) updateIncludedSpecies(date time.Time) { | ||
speciesScores, err := p.Bn.GetProbableSpecies(date, 0.0) | ||
func (p *Processor) ReloadRangeFilter() error { | ||
today := time.Now().Truncate(24 * time.Hour) | ||
|
||
// Update location based species list | ||
speciesScores, err := p.Bn.GetProbableSpecies(today, 0.0) | ||
if err != nil { | ||
log.Printf("Failed to get probable species: %s", err) | ||
return | ||
return err | ||
} | ||
|
||
// Convert the speciesScores slice to a slice of species labels | ||
var includedSpecies []string | ||
for _, speciesScore := range speciesScores { | ||
includedSpecies = append(includedSpecies, speciesScore.Label) | ||
} | ||
|
||
p.Settings.UpdateIncludedSpecies(includedSpecies) | ||
p.Settings.BirdNET.RangeFilter.LastUpdated = date | ||
|
||
// Update dynamic thresholds if enabled | ||
if p.Settings.Realtime.DynamicThreshold.Enabled { | ||
p.updateDynamicThresholds() | ||
} | ||
} | ||
|
||
// Add a new function to update dynamic thresholds | ||
func (p *Processor) updateDynamicThresholds() { | ||
newDynamicThresholds := make(map[string]*DynamicThreshold) | ||
for _, species := range p.Settings.BirdNET.RangeFilter.Species { | ||
speciesLowercase := strings.ToLower(species) | ||
if dt, exists := p.DynamicThresholds[speciesLowercase]; exists { | ||
newDynamicThresholds[speciesLowercase] = dt | ||
} else { | ||
newDynamicThresholds[speciesLowercase] = &DynamicThreshold{ | ||
Level: 0, | ||
CurrentValue: float64(p.Settings.BirdNET.Threshold), | ||
Timer: time.Now(), | ||
HighConfCount: 0, | ||
ValidHours: p.Settings.Realtime.DynamicThreshold.ValidHours, | ||
} | ||
} | ||
} | ||
p.DynamicThresholds = newDynamicThresholds | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters