the-algorithm/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/candidate_sources/recent_engagement/RecentEngagementDirectFollowSource.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

39 lines
1.5 KiB
Scala

package com.twitter.follow_recommendations.common.candidate_sources.recent_engagement
import com.twitter.follow_recommendations.common.clients.real_time_real_graph.RealTimeRealGraphClient
import com.twitter.follow_recommendations.common.models.CandidateUser
import com.twitter.hermit.model.Algorithm
import com.twitter.product_mixer.core.functional_component.candidate_source.CandidateSource
import com.twitter.product_mixer.core.model.common.identifier.CandidateSourceIdentifier
import com.twitter.stitch.Stitch
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class RecentEngagementDirectFollowSource @Inject() (
realTimeRealGraphClient: RealTimeRealGraphClient)
extends CandidateSource[Long, CandidateUser] {
val identifier: CandidateSourceIdentifier =
RecentEngagementDirectFollowSource.Identifier
/**
* Generate a list of candidates for the target using RealtimeGraphClient
* and RecentEngagementStore.
*/
override def apply(targetUserId: Long): Stitch[Seq[CandidateUser]] = {
realTimeRealGraphClient
.getUsersRecentlyEngagedWith(
userId = targetUserId,
engagementScoreMap = RealTimeRealGraphClient.EngagementScoreMap,
includeDirectFollowCandidates = true,
includeNonDirectFollowCandidates = false
)
.map(_.map(_.withCandidateSource(identifier)).sortBy(-_.score.getOrElse(0.0)))
}
}
object RecentEngagementDirectFollowSource {
val Identifier = CandidateSourceIdentifier(Algorithm.RecentEngagementDirectFollow.toString)
}