Skip to content

Commit

Permalink
Fix fmt.Sprintf time to float issue
Browse files Browse the repository at this point in the history
There used to be errors such as:
fmt.Sprintf format %.1f has arg note.BeginTime of wrong type time.Time

This commit fixes it by converting the time into unix nano seconds
then converts it into seconds.
  • Loading branch information
isZumpo committed Apr 6, 2024
1 parent e157c77 commit 866a37e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/observation/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ func WriteNotesTable(settings *conf.Settings, notes []datastore.Note, filename s
continue // Skip the current iteration as the note doesn't meet the threshold
}

beginTime := float64(note.BeginTime.UnixNano()) / 1e9
endTime := float64(note.EndTime.UnixNano()) / 1e9

// 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)
i+1, note.InputFile, beginTime, endTime, 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 +157,11 @@ func WriteNotesCsv(settings *conf.Settings, notes []datastore.Note, filename str
continue // Skip the current iteration as the note doesn't meet the threshold
}

beginTime := float64(note.BeginTime.UnixNano()) / 1e9
endTime := float64(note.EndTime.UnixNano()) / 1e9

line := fmt.Sprintf("%f,%f,%s,%s,%.4f\n",
note.BeginTime, note.EndTime, note.ScientificName, note.CommonName, note.Confidence)
beginTime, 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 866a37e

Please sign in to comment.