mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 08:54:19 +00:00
refactor: optimize timestamp handling in FindMatches function
This commit is contained in:
parent
f1430ffb8b
commit
3f8f1b0514
1 changed files with 7 additions and 8 deletions
|
|
@ -47,8 +47,8 @@ func FindMatches(audioSample []float64, audioDuration float64, sampleRate int) (
|
||||||
return nil, time.Since(startTime), err
|
return nil, time.Since(startTime), err
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := map[uint32][][2]uint32{} // songID -> [(sampleTime, dbTime)]
|
matches := map[uint32][][2]uint32{} // songID -> [(sampleTime, dbTime)]
|
||||||
timestamps := map[uint32][]uint32{}
|
timestamps := map[uint32]uint32{} // songID -> earliest timestamp
|
||||||
targetZones := map[uint32]map[uint32]int{} // songID -> timestamp -> count
|
targetZones := map[uint32]map[uint32]int{} // songID -> timestamp -> count
|
||||||
|
|
||||||
for address, couples := range m {
|
for address, couples := range m {
|
||||||
|
|
@ -57,7 +57,10 @@ func FindMatches(audioSample []float64, audioDuration float64, sampleRate int) (
|
||||||
matches[couple.SongID],
|
matches[couple.SongID],
|
||||||
[2]uint32{sampleFingerprint[address].AnchorTimeMs, couple.AnchorTimeMs},
|
[2]uint32{sampleFingerprint[address].AnchorTimeMs, couple.AnchorTimeMs},
|
||||||
)
|
)
|
||||||
timestamps[couple.SongID] = append(timestamps[couple.SongID], couple.AnchorTimeMs)
|
|
||||||
|
if existingTime, ok := timestamps[couple.SongID]; !ok || couple.AnchorTimeMs < existingTime {
|
||||||
|
timestamps[couple.SongID] = couple.AnchorTimeMs
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := targetZones[couple.SongID]; !ok {
|
if _, ok := targetZones[couple.SongID]; !ok {
|
||||||
targetZones[couple.SongID] = make(map[uint32]int)
|
targetZones[couple.SongID] = make(map[uint32]int)
|
||||||
|
|
@ -83,11 +86,7 @@ func FindMatches(audioSample []float64, audioDuration float64, sampleRate int) (
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(timestamps[songID], func(i, j int) bool {
|
match := Match{songID, song.Title, song.Artist, song.YouTubeID, timestamps[songID], points}
|
||||||
return timestamps[songID][i] < timestamps[songID][j]
|
|
||||||
})
|
|
||||||
|
|
||||||
match := Match{songID, song.Title, song.Artist, song.YouTubeID, timestamps[songID][0], points}
|
|
||||||
matchList = append(matchList, match)
|
matchList = append(matchList, match)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue