github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/storage/score.go (about) 1 package storage 2 3 import ( 4 "time" 5 6 "github.com/keybase/client/go/protocol/gregor1" 7 ) 8 9 const ( 10 minScoringMinutes = 1 // one minute 11 maxScoringMinutes = 7 * 24 * 60 // one week 12 frequencyWeight = 2 13 mtimeWeight = 1 14 ) 15 16 func ScoreByFrequencyAndMtime(freq int, mtime gregor1.Time) float64 { 17 // if we are missing an mtime just backdate to a week ago 18 if mtime == 0 { 19 mtime = gregor1.ToTime(time.Now().Add(-time.Hour * 24 * 7)) 20 } 21 minutes := time.Since(mtime.Time()).Minutes() 22 var mtimeScore float64 23 if minutes > maxScoringMinutes { 24 mtimeScore = 0 25 } else if minutes < minScoringMinutes { 26 mtimeScore = 1 27 } else { 28 mtimeScore = 1 - minutes/(maxScoringMinutes-minScoringMinutes) 29 } 30 return float64(freq*frequencyWeight) + mtimeScore*mtimeWeight 31 }