diff --git a/packages/discovery-provider/integration_tests/challenges/test_trending_challenge.py b/packages/discovery-provider/integration_tests/challenges/test_trending_challenge.py index 8d617fbe948..84fd6650416 100644 --- a/packages/discovery-provider/integration_tests/challenges/test_trending_challenge.py +++ b/packages/discovery-provider/integration_tests/challenges/test_trending_challenge.py @@ -85,7 +85,7 @@ def test_trending_challenge_should_update(app): rank=1, id="1", type="tracks", - version="pnagD", + version="AnlGe", week="2021-08-20", ) ) diff --git a/packages/discovery-provider/integration_tests/tasks/test_index_trending_notification.py b/packages/discovery-provider/integration_tests/tasks/test_index_trending_notification.py index 00db2924a66..a63a764d642 100644 --- a/packages/discovery-provider/integration_tests/tasks/test_index_trending_notification.py +++ b/packages/discovery-provider/integration_tests/tasks/test_index_trending_notification.py @@ -35,7 +35,7 @@ def test_index_trending_notification(app): { "track_id": i, "score": 100 - i, - "version": TrendingVersion.pnagD.value, + "version": TrendingVersion.AnlGe.value, "time_range": "week", "type": TrendingType.TRACKS.name, } @@ -100,7 +100,7 @@ def test_index_trending_notification(app): { "track_id": track_id, "score": 100 - i, - "version": TrendingVersion.pnagD.value, + "version": TrendingVersion.AnlGe.value, "time_range": "week", "type": TrendingType.TRACKS.name, } diff --git a/packages/discovery-provider/integration_tests/tasks/test_index_trending_underground_notification.py b/packages/discovery-provider/integration_tests/tasks/test_index_trending_underground_notification.py index 04a479f0fe1..354a6c6e827 100644 --- a/packages/discovery-provider/integration_tests/tasks/test_index_trending_underground_notification.py +++ b/packages/discovery-provider/integration_tests/tasks/test_index_trending_underground_notification.py @@ -36,7 +36,7 @@ def test_index_trending_underground_notification(app): { "track_id": i, "score": 1000 - i, - "version": TrendingVersion.pnagD.value, + "version": TrendingVersion.AnlGe.value, "time_range": "week", "type": TrendingType.TRACKS.name, } @@ -101,7 +101,7 @@ def test_index_trending_underground_notification(app): { "track_id": track_id, "score": 1000 - i, - "version": TrendingVersion.pnagD.value, + "version": TrendingVersion.AnlGe.value, "time_range": "week", "type": TrendingType.TRACKS.name, } diff --git a/packages/discovery-provider/integration_tests/tasks/test_update_trending.py b/packages/discovery-provider/integration_tests/tasks/test_update_trending.py index 4ff33ee9fdb..cf1aa309ec3 100644 --- a/packages/discovery-provider/integration_tests/tasks/test_update_trending.py +++ b/packages/discovery-provider/integration_tests/tasks/test_update_trending.py @@ -5,8 +5,8 @@ from src.models.social.aggregate_interval_plays import t_aggregate_interval_plays from src.models.tracks.track_trending_score import TrackTrendingScore from src.models.tracks.trending_param import t_trending_params -from src.trending_strategies.pnagD_trending_tracks_strategy import ( - TrendingTracksStrategypnagD, +from src.trending_strategies.AnlGe_trending_tracks_strategy import ( + TrendingTracksStrategyAnlGe, ) from src.utils.db_session import get_db @@ -341,7 +341,7 @@ def test_update_track_score_query(app): # setup setup_trending(db) - updated_strategy = TrendingTracksStrategypnagD() + updated_strategy = TrendingTracksStrategyAnlGe() with db.scoped_session() as session: session.execute("REFRESH MATERIALIZED VIEW aggregate_interval_plays") diff --git a/packages/discovery-provider/integration_tests/utils.py b/packages/discovery-provider/integration_tests/utils.py index 25ec38aea30..43bec9dbcf1 100644 --- a/packages/discovery-provider/integration_tests/utils.py +++ b/packages/discovery-provider/integration_tests/utils.py @@ -991,7 +991,7 @@ def populate_mock_db(db, entities, block_offset=None): track_id=track_trending_score.get("track_id", i), type=track_trending_score.get("type", TrendingType.TRACKS.name), score=track_trending_score.get("score", 0), - version=track_trending_score.get("version", TrendingVersion.pnagD.name), + version=track_trending_score.get("version", TrendingVersion.AnlGe.name), genre=track_trending_score.get("genre", ""), time_range=track_trending_score.get("time_range", "week"), created_at=track_trending_score.get("created_at", datetime.now()), diff --git a/packages/discovery-provider/src/trending_strategies/pnagD_trending_tracks_strategy.py b/packages/discovery-provider/src/trending_strategies/pnagD_trending_tracks_strategy.py deleted file mode 100644 index 2607b8a83dc..00000000000 --- a/packages/discovery-provider/src/trending_strategies/pnagD_trending_tracks_strategy.py +++ /dev/null @@ -1,201 +0,0 @@ -import logging -import time - -from sqlalchemy.sql import text - -from src.trending_strategies.base_trending_strategy import BaseTrendingStrategy -from src.trending_strategies.trending_type_and_version import ( - TrendingType, - TrendingVersion, -) - -logger = logging.getLogger(__name__) - - -# Trending Parameters -N = 1 -a = max -M = pow -F = 50 -O = 1 -R = 0.25 -i = 0.01 -q = 100000.0 -T = {"day": 1, "week": 7, "month": 30, "year": 365, "allTime": 100000} -y = 3 - - -class TrendingTracksStrategypnagD(BaseTrendingStrategy): - def __init__(self): - super().__init__(TrendingType.TRACKS, TrendingVersion.pnagD) - - def get_track_score(self, time_range, track): - logger.error( - f"get_track_score not implemented for Trending Tracks Strategy with version {TrendingVersion.pnagD}" - ) - - def update_track_score_query(self, session): - start_time = time.time() - trending_track_query = text( - """ - begin; - DELETE FROM track_trending_scores WHERE type=:type AND version=:version; - INSERT INTO track_trending_scores - (track_id, genre, type, version, time_range, score, created_at) - select - tp.track_id, - tp.genre, - :type, - :version, - :week_time_range, - CASE - WHEN tp.owner_follower_count < :y - THEN 0 - WHEN EXTRACT(DAYS FROM now() - ( - CASE - WHEN tp.release_date > now() THEN aip.created_at - ELSE GREATEST(tp.release_date, aip.created_at) - END - )) > :week - THEN GREATEST( - 1.0 / :q, - POW( - :q, - GREATEST( - -10, - 1.0 - 1.0 * EXTRACT(DAYS FROM now() - ( - CASE - WHEN tp.release_date > now() THEN aip.created_at - ELSE GREATEST(tp.release_date, aip.created_at) - END - )) / :week - ) - ) - ) * ( - :N * aip.week_listen_counts + - :F * tp.repost_week_count + - :O * tp.save_week_count + - :R * tp.repost_count + - :i * tp.save_count - ) * tp.karma - ELSE ( - :N * aip.week_listen_counts + - :F * tp.repost_week_count + - :O * tp.save_week_count + - :R * tp.repost_count + - :i * tp.save_count - ) * tp.karma - END as week_score, - now() - from trending_params tp - inner join aggregate_interval_plays aip - on tp.track_id = aip.track_id; - INSERT INTO track_trending_scores - (track_id, genre, type, version, time_range, score, created_at) - select - tp.track_id, - tp.genre, - :type, - :version, - :month_time_range, - CASE - WHEN tp.owner_follower_count < :y - THEN 0 - WHEN EXTRACT(DAYS FROM now() - ( - CASE - WHEN tp.release_date > now() THEN aip.created_at - ELSE GREATEST(tp.release_date, aip.created_at) - END - )) > :month - THEN GREATEST( - 1.0 / :q, - POW( - :q, - GREATEST( - -10, - 1.0 - 1.0 * EXTRACT(DAYS FROM now() - ( - CASE - WHEN tp.release_date > now() THEN aip.created_at - ELSE GREATEST(tp.release_date, aip.created_at) - END - )) / :month - ) - ) - ) * ( - :N * aip.month_listen_counts + - :F * tp.repost_month_count + - :O * tp.save_month_count + - :R * tp.repost_count + - :i * tp.save_count - ) * tp.karma - ELSE ( - :N * aip.month_listen_counts + - :F * tp.repost_month_count + - :O * tp.save_month_count + - :R * tp.repost_count + - :i * tp.save_count - ) * tp.karma - END as month_score, - now() - from trending_params tp - inner join aggregate_interval_plays aip - on tp.track_id = aip.track_id; - INSERT INTO track_trending_scores - (track_id, genre, type, version, time_range, score, created_at) - select - tp.track_id, - tp.genre, - :type, - :version, - :all_time_time_range, - CASE - WHEN tp.owner_follower_count < :y - THEN 0 - ELSE (:N * ap.count + :R * tp.repost_count + :i * tp.save_count) * tp.karma - END as all_time_score, - now() - from trending_params tp - inner join aggregate_plays ap - on tp.track_id = ap.play_item_id - inner join tracks t - on ap.play_item_id = t.track_id - where -- same filtering for aggregate_interval_plays - t.is_current is True AND - t.is_delete is False AND - t.is_unlisted is False AND - t.stem_of is Null; - commit; - """ - ) - session.execute( - trending_track_query, - { - "week": T["week"], - "month": T["month"], - "N": N, - "F": F, - "O": O, - "R": R, - "i": i, - "q": q, - "y": y, - "type": self.trending_type.name, - "version": self.version.name, - "week_time_range": "week", - "month_time_range": "month", - "all_time_time_range": "allTime", - }, - ) - duration = time.time() - start_time - logger.info( - f"trending_tracks_strategy | Finished calculating trending scores in {duration} seconds", - extra={ - "id": "trending_strategy", - "type": self.trending_type.name, - "version": self.version.name, - "duration": duration, - }, - ) - - def get_score_params(self): - return {"xf": True, "pt": 0, "nm": 5} diff --git a/packages/discovery-provider/src/trending_strategies/trending_strategy_factory.py b/packages/discovery-provider/src/trending_strategies/trending_strategy_factory.py index f79e1681e76..25b6453f5e9 100644 --- a/packages/discovery-provider/src/trending_strategies/trending_strategy_factory.py +++ b/packages/discovery-provider/src/trending_strategies/trending_strategy_factory.py @@ -4,17 +4,14 @@ from src.trending_strategies.pnagD_trending_playlists_strategy import ( TrendingPlaylistsStrategypnagD, ) -from src.trending_strategies.pnagD_trending_tracks_strategy import ( - TrendingTracksStrategypnagD, -) from src.trending_strategies.trending_type_and_version import ( TrendingType, TrendingVersion, ) DEFAULT_TRENDING_VERSIONS = { - TrendingType.TRACKS: TrendingVersion.pnagD, - TrendingType.UNDERGROUND_TRACKS: TrendingVersion.pnagD, + TrendingType.TRACKS: TrendingVersion.AnlGe, + TrendingType.UNDERGROUND_TRACKS: TrendingVersion.AnlGe, TrendingType.PLAYLISTS: TrendingVersion.pnagD, } @@ -23,11 +20,10 @@ class TrendingStrategyFactory: def __init__(self): self.strategies = { TrendingType.TRACKS: { - TrendingVersion.pnagD: TrendingTracksStrategypnagD(), TrendingVersion.AnlGe: TrendingTracksStrategyAnlGe(), }, TrendingType.UNDERGROUND_TRACKS: { - TrendingVersion.pnagD: TrendingTracksStrategypnagD(), + TrendingVersion.AnlGe: TrendingTracksStrategyAnlGe(), }, TrendingType.PLAYLISTS: { TrendingVersion.pnagD: TrendingPlaylistsStrategypnagD(),