mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 22:58:54 +02:00
59 lines
2.7 KiB
Scala
59 lines
2.7 KiB
Scala
package com.twitter.home_mixer.product.scored_tweets.feature_hydrator.real_time_aggregates
|
|
|
|
import com.google.inject.name.Named
|
|
import com.twitter.finagle.stats.StatsReceiver
|
|
import com.twitter.home_mixer.param.HomeMixerInjectionNames.TweetCountryEngagementCache
|
|
import com.twitter.home_mixer.util.CandidatesUtil
|
|
import com.twitter.ml.api.DataRecord
|
|
import com.twitter.product_mixer.component_library.model.candidate.TweetCandidate
|
|
import com.twitter.product_mixer.core.feature.FeatureWithDefaultOnFailure
|
|
import com.twitter.product_mixer.core.feature.datarecord.DataRecordInAFeature
|
|
import com.twitter.product_mixer.core.model.common.CandidateWithFeatures
|
|
import com.twitter.product_mixer.core.model.common.identifier.FeatureHydratorIdentifier
|
|
import com.twitter.product_mixer.core.pipeline.PipelineQuery
|
|
import com.twitter.servo.cache.ReadCache
|
|
import com.twitter.timelines.data_processing.ml_util.aggregation_framework.AggregateGroup
|
|
import com.twitter.timelines.prediction.common.aggregates.real_time.TimelinesOnlineAggregationFeaturesOnlyConfig._
|
|
import javax.inject.Inject
|
|
import javax.inject.Singleton
|
|
|
|
object TweetCountryEngagementRealTimeAggregateFeature
|
|
extends DataRecordInAFeature[TweetCandidate]
|
|
with FeatureWithDefaultOnFailure[TweetCandidate, DataRecord] {
|
|
override def defaultValue: DataRecord = new DataRecord()
|
|
}
|
|
|
|
@Singleton
|
|
class TweetCountryEngagementRealTimeAggregateFeatureHydrator @Inject() (
|
|
@Named(TweetCountryEngagementCache) override val client: ReadCache[(Long, String), DataRecord],
|
|
override val statsReceiver: StatsReceiver)
|
|
extends BaseRealTimeAggregateBulkCandidateFeatureHydrator[(Long, String)] {
|
|
|
|
override val identifier: FeatureHydratorIdentifier =
|
|
FeatureHydratorIdentifier("TweetCountryEngagementRealTimeAggregate")
|
|
|
|
override val outputFeature: DataRecordInAFeature[TweetCandidate] =
|
|
TweetCountryEngagementRealTimeAggregateFeature
|
|
|
|
override val aggregateGroups: Seq[AggregateGroup] = Seq(
|
|
tweetCountryRealTimeAggregates,
|
|
tweetCountryPrivateEngagementsRealTimeAggregates
|
|
)
|
|
|
|
override val aggregateGroupToPrefix: Map[AggregateGroup, String] = Map(
|
|
tweetCountryRealTimeAggregates -> "tweet-country_code.timelines.tweet_country_engagement_real_time_aggregates.",
|
|
tweetCountryPrivateEngagementsRealTimeAggregates -> "tweet-country_code.timelines.tweet_country_private_engagement_real_time_aggregates."
|
|
)
|
|
|
|
override def keysFromQueryAndCandidates(
|
|
query: PipelineQuery,
|
|
candidates: Seq[CandidateWithFeatures[TweetCandidate]]
|
|
): Seq[Option[(Long, String)]] = {
|
|
val countryCode = query.clientContext.countryCode
|
|
candidates.map { candidate =>
|
|
val originalTweetId = CandidatesUtil.getOriginalTweetId(candidate)
|
|
countryCode.map((originalTweetId, _))
|
|
}
|
|
}
|
|
}
|