Skip to content

Commit

Permalink
chore: fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tphakala committed Apr 6, 2024
1 parent c726fcf commit c5a92ee
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion internal/analysis/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (p *Processor) processResults(item *queue.Results) []Detections {
confidenceThreshold = float32(p.Settings.BirdNET.Threshold)
} else {
if p.Settings.Debug {
//fmt.Printf("\nUsing confidence threshold of %.2f for %s\n", confidenceThreshold, species)
log.Printf("\nUsing confidence threshold of %.2f for %s\n", confidenceThreshold, speciesLowercase)
}
}

Expand Down
5 changes: 3 additions & 2 deletions internal/analysis/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package analysis

import (
"fmt"
"log"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -134,8 +135,8 @@ func monitorCtrlC(quitChan chan struct{}) {
// closeDataStore attempts to close the database connection and logs the result.
func closeDataStore(store datastore.Interface) {
if err := store.Close(); err != nil {
//logger.Error("main", "Failed to close database: %v", err)
log.Printf("Failed to close database: %v", err)
} else {
//logger.Info("main", "Successfully closed database")
log.Println("Successfully closed database")
}
}
36 changes: 22 additions & 14 deletions internal/httpcontroller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,38 @@ func New(settings *conf.Settings, dataStore datastore.Interface) *Server {
// Server initialization
s.initializeServer()

// Conditional AutoTLS setup
// Conditional AutoTLS setup with improved error handling and readability
errChan := make(chan error)

go func() {
var err error
var err error // Declare err variable at the top of the goroutine scope

if settings.WebServer.AutoTLS {
configPaths, err := conf.GetDefaultConfigPaths()
if err != nil {
log.Fatalf("Failed to get config paths: %v", err)
// Attempt to configure AutoTLS
configPaths, configErr := conf.GetDefaultConfigPaths() // Use a different variable name to avoid shadowing err
if configErr != nil {
errChan <- fmt.Errorf("failed to get config paths: %v", configErr) // Send error to channel
return // Exit the goroutine upon error
}

// Configure AutoTLS Manager
s.Echo.AutoTLSManager.Prompt = autocert.AcceptTOS
s.Echo.AutoTLSManager.Cache = autocert.DirCache(configPaths[0])
s.Echo.AutoTLSManager.HostPolicy = autocert.HostWhitelist("")
err = s.Echo.StartAutoTLS(":" + settings.WebServer.Port)
s.Echo.AutoTLSManager.HostPolicy = autocert.HostWhitelist("") // Adjust as needed

// Start server with AutoTLS
err = s.Echo.StartAutoTLS(":" + settings.WebServer.Port) //nolint:errcheck
} else {
// Start server without AutoTLS
err = s.Echo.Start(":" + settings.WebServer.Port)
}

// Check if there was an error in starting the server
if err != nil {
errChan <- err
errChan <- err // Send error to channel
}
}()

go handleServerError(errChan)

return s
Expand All @@ -90,12 +101,9 @@ func (s *Server) initializeServer() {

// handleServerError listens for server errors and handles them.
func handleServerError(errChan chan error) {
for {
select {
case err := <-errChan:
log.Printf("Server error: %v", err)
// Additional error handling logic here
}
for err := range errChan {
log.Printf("Server error: %v", err)
// Additional error handling logic here
}
}

Expand Down
5 changes: 4 additions & 1 deletion internal/myaudio/buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func BufferMonitor(wg *sync.WaitGroup, bn *birdnet.BirdNET, quitChan chan struct
// if buffer has 3 seconds of data, process it
if len(data) == chunkSize {
startTime := time.Now().Add(-4 * time.Second)
ProcessData(bn, data, startTime)
err := ProcessData(bn, data, startTime)
if err != nil {
log.Printf("Error processing data: %v", err)
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/myaudio/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func ProcessData(bn *birdnet.BirdNET, data []byte, startTime time.Time) error {
}

func logProcessingTime(startTime time.Time) time.Duration {
var elapsedTime time.Duration
elapsedTime = time.Since(startTime)
var elapsedTime = time.Since(startTime)
/*if ctx.Settings.Realtime.ProcessingTime || ctx.Settings.Debug {
fmt.Printf("\r\033[Kprocessing time %v ms", elapsedTime.Milliseconds())
return elapsedTime
Expand Down
12 changes: 7 additions & 5 deletions internal/observation/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func WriteNotesTable(settings *conf.Settings, notes []datastore.Note, filename s
continue // Skip the current iteration as the note doesn't meet the threshold
}

// Prepare the line for notes above the threshold
line := fmt.Sprintf("%d\tSpectrogram 1\t1\t%s\t%.1f\t%.1f\t0\t15000\t%s\t%s\t%.4f\n",
i+1, note.InputFile, note.BeginTime, note.EndTime, note.SpeciesCode, note.CommonName, note.Confidence)
// Prepare the line for notes above the threshold, assuming note.BeginTime and note.EndTime are of type time.Time
line := fmt.Sprintf("%d\tSpectrogram 1\t1\t%s\t%s\t%s\t0\t15000\t%s\t%s\t%.4f\n",
i+1, note.InputFile, note.BeginTime.Format("15:04:05"), note.EndTime.Format("15:04:05"), note.SpeciesCode, note.CommonName, note.Confidence)

// Attempt to write the note
if _, err = w.Write([]byte(line)); err != nil {
Expand Down Expand Up @@ -154,8 +154,10 @@ func WriteNotesCsv(settings *conf.Settings, notes []datastore.Note, filename str
continue // Skip the current iteration as the note doesn't meet the threshold
}

line := fmt.Sprintf("%f,%f,%s,%s,%.4f\n",
note.BeginTime, note.EndTime, note.ScientificName, note.CommonName, note.Confidence)
line := fmt.Sprintf("%s,%s,%s,%s,%.4f\n",
note.BeginTime.Format("2006-01-02 15:04:05"), // Formats BeginTime
note.EndTime.Format("2006-01-02 15:04:05"), // Formats EndTime
note.ScientificName, note.CommonName, note.Confidence)

if _, err = w.Write([]byte(line)); err != nil {
// Break out of the loop at the first sign of an error
Expand Down

0 comments on commit c5a92ee

Please sign in to comment.