Skip to content

Commit

Permalink
feat: rename and enhance range filter function with debug logging
Browse files Browse the repository at this point in the history
- Renamed ReloadRangeFilter to BuildRangeFilter for improved clarity.
- Added detailed logging to track species and scores during the filter build process.
- Introduced a debug mode that writes included species to a file when enabled, enhancing traceability for debugging purposes.
  • Loading branch information
tphakala committed Jan 11, 2025
1 parent bce4d04 commit 09b1b7b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion internal/analysis/processor/range_filter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package processor

import (
"fmt"
"log"
"os"
"time"
)

// Add or update the updateIncludedSpecies function
func (p *Processor) ReloadRangeFilter() error {
func (p *Processor) BuildRangeFilter() error {
today := time.Now().Truncate(24 * time.Hour)

// Update location based species list
Expand All @@ -17,9 +20,25 @@ func (p *Processor) ReloadRangeFilter() error {
// Convert the speciesScores slice to a slice of species labels
var includedSpecies []string
for _, speciesScore := range speciesScores {
// debug species and score
log.Printf(" Species: %s, Score: %f\n", speciesScore.Label, speciesScore.Score)
includedSpecies = append(includedSpecies, speciesScore.Label)
}

if p.Settings.BirdNET.RangeFilter.Debug {
// Debug: Write included species to file
debugFile := "debug_included_species.txt"
content := fmt.Sprintf("Updated at: %s\nSpecies count: %d\n\nSpecies list:\n",
time.Now().Format("2006-01-02 15:04:05"),
len(includedSpecies))
for _, species := range includedSpecies {
content += species + "\n"
}
if err := os.WriteFile(debugFile, []byte(content), 0644); err != nil {
log.Printf("❌ [range_filter/rebuild] Warning: Failed to write included species file: %v\n", err)
}
}

p.Settings.UpdateIncludedSpecies(includedSpecies)

return nil
Expand Down

0 comments on commit 09b1b7b

Please sign in to comment.