mirror of
https://github.com/Xevion/vastly.git
synced 2026-01-31 04:26:38 -06:00
sort in internal scoring, extract latency keys in batch for top 100
This commit is contained in:
+4
-2
@@ -74,6 +74,10 @@ func (l *LatencyQueue) SetHandler(handler chan<- PingResult) {
|
||||
l.handlerChannel = handler
|
||||
}
|
||||
|
||||
func (l *LatencyQueue) GetSelfIP() net.IP {
|
||||
return l.ipSelf
|
||||
}
|
||||
|
||||
func (l *LatencyQueue) RefreshIP() error {
|
||||
resp, err := http.Get("https://api.ipify.org?format=text")
|
||||
if err != nil {
|
||||
@@ -145,8 +149,6 @@ func (l *LatencyQueue) Start(ctx context.Context) {
|
||||
pinger.Interval = time.Nanosecond
|
||||
pinger.Timeout = time.Millisecond * 500
|
||||
|
||||
l.logger.Debugw("Ping Request", "ip", ip)
|
||||
|
||||
// Process the request
|
||||
err = pinger.Run()
|
||||
if err != nil {
|
||||
|
||||
+13
-1
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -190,10 +191,21 @@ func ScoreOffers(offers []Offer) []ScoredOffer {
|
||||
}
|
||||
}
|
||||
newScore := score * multiplier
|
||||
// sugar.Infow("Multiplier Applied", "offer", offer.ID, "baseScore", score, "score", newScore, "multiplier", multiplier)
|
||||
score = newScore
|
||||
|
||||
scoredOffers = append(scoredOffers, ScoredOffer{Offer: offer, Score: score, Reasons: reasons})
|
||||
}
|
||||
|
||||
// Sort by score
|
||||
slices.SortStableFunc(scoredOffers, func(a, b ScoredOffer) int {
|
||||
if a.Score < b.Score {
|
||||
return 1
|
||||
} else if a.Score > b.Score {
|
||||
return -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
|
||||
return scoredOffers
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user