mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-14 07:08:53 +02:00
b389c3d302
Pushservice is the main recommendation service we use to surface recommendations to our users via notifications. It fetches candidates from various sources, ranks them in order of relevance, and applies filters to determine the best one to send.
78 lines
2.6 KiB
Scala
78 lines
2.6 KiB
Scala
package com.twitter.frigate.pushservice.refresh_handler
|
|
|
|
import com.twitter.finagle.stats.Stat
|
|
import com.twitter.finagle.stats.StatsReceiver
|
|
import com.twitter.frigate.common.base.CandidateDetails
|
|
import com.twitter.frigate.pushservice.model.PushTypes.PushCandidate
|
|
import com.twitter.frigate.thriftscala.CommonRecommendationType
|
|
|
|
class RFPHStatsRecorder(implicit statsReceiver: StatsReceiver) {
|
|
|
|
private val selectedCandidateScoreStats: StatsReceiver =
|
|
statsReceiver.scope("score_of_sent_candidate_times_10000")
|
|
|
|
private val emptyScoreStats: StatsReceiver =
|
|
statsReceiver.scope("score_of_sent_candidate_empty")
|
|
|
|
def trackPredictionScoreStats(candidate: PushCandidate): Unit = {
|
|
candidate.mrWeightedOpenOrNtabClickRankingProbability.foreach {
|
|
case Some(s) =>
|
|
selectedCandidateScoreStats
|
|
.stat("weighted_open_or_ntab_click_ranking")
|
|
.add((s * 10000).toFloat)
|
|
case None =>
|
|
emptyScoreStats.counter("weighted_open_or_ntab_click_ranking").incr()
|
|
}
|
|
candidate.mrWeightedOpenOrNtabClickFilteringProbability.foreach {
|
|
case Some(s) =>
|
|
selectedCandidateScoreStats
|
|
.stat("weighted_open_or_ntab_click_filtering")
|
|
.add((s * 10000).toFloat)
|
|
case None =>
|
|
emptyScoreStats.counter("weighted_open_or_ntab_click_filtering").incr()
|
|
}
|
|
candidate.mrWeightedOpenOrNtabClickRankingProbability.foreach {
|
|
case Some(s) =>
|
|
selectedCandidateScoreStats
|
|
.scope(candidate.commonRecType.toString)
|
|
.stat("weighted_open_or_ntab_click_ranking")
|
|
.add((s * 10000).toFloat)
|
|
case None =>
|
|
emptyScoreStats
|
|
.scope(candidate.commonRecType.toString)
|
|
.counter("weighted_open_or_ntab_click_ranking")
|
|
.incr()
|
|
}
|
|
}
|
|
|
|
def refreshRequestExceptionStats(
|
|
exception: Throwable,
|
|
bStats: StatsReceiver
|
|
): Unit = {
|
|
bStats.counter("failures").incr()
|
|
bStats.scope("failures").counter(exception.getClass.getCanonicalName).incr()
|
|
}
|
|
|
|
def loggedOutRequestExceptionStats(
|
|
exception: Throwable,
|
|
bStats: StatsReceiver
|
|
): Unit = {
|
|
bStats.counter("logged_out_failures").incr()
|
|
bStats.scope("failures").counter(exception.getClass.getCanonicalName).incr()
|
|
}
|
|
|
|
def rankDistributionStats(
|
|
candidatesDetails: Seq[CandidateDetails[PushCandidate]],
|
|
numRecsPerTypeStat: (CommonRecommendationType => Stat)
|
|
): Unit = {
|
|
candidatesDetails
|
|
.groupBy { c =>
|
|
c.candidate.commonRecType
|
|
}
|
|
.mapValues { s =>
|
|
s.size
|
|
}
|
|
.foreach { case (crt, numRecs) => numRecsPerTypeStat(crt).add(numRecs) }
|
|
}
|
|
}
|