Skip to content

Commit

Permalink
Rename trending challenges
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzatron committed Jan 14, 2022
1 parent 08a9aed commit 371f7b3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ def test_trending_challenge_job(app):
with db.scoped_session() as session:
session.query(Challenge).filter(
or_(
Challenge.id == "trending-playlist",
Challenge.id == "trending-track",
Challenge.id == "trending-underground-track",
Challenge.id == "tp",
Challenge.id == "tt",
Challenge.id == "tut",
)
).update({"active": True, "starting_block": BLOCK_NUMBER})
bus.process_events(session)
Expand All @@ -309,7 +309,7 @@ def test_trending_challenge_job(app):

user_trending_tracks_challenges = (
session.query(UserChallenge)
.filter(UserChallenge.challenge_id == "trending-track")
.filter(UserChallenge.challenge_id == "tt")
.all()
)
assert len(user_trending_tracks_challenges) == 5
Expand Down
1 change: 0 additions & 1 deletion discovery-provider/src/challenges/challenge_event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def _event_to_json(self, event: str, block_number: int, user_id: int, extra: Dic
def _json_to_event(self, event_json) -> InternalEvent:
return json.loads(event_json)


def setup_challenge_bus():
redis = get_redis()
bus = ChallengeEventBus(redis)
Expand Down
6 changes: 3 additions & 3 deletions discovery-provider/src/challenges/challenges.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@
"starting_block": 25346436
},
{
"id": "trending-track",
"id": "tt",
"type": "trending",
"amount": "100",
"active": true,
"starting_block": 25346436
},
{
"id": "trending-underground-track",
"id": "tut",
"type": "trending",
"amount": "100",
"active": true,
"starting_block": 25346436
},
{
"id": "trending-playlist",
"id": "tp",
"type": "trending",
"amount": "100",
"active": true,
Expand Down
6 changes: 3 additions & 3 deletions discovery-provider/src/challenges/challenges.stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
"starting_block": 0
},
{
"id": "trending-track",
"id": "tt",
"active": true,
"starting_block": 0
},
{
"id": "trending-underground-track",
"id": "tut",
"active": true,
"starting_block": 0
},
{
"id": "trending-playlist",
"id": "tp",
"active": true,
"starting_block": 0
}
Expand Down
8 changes: 4 additions & 4 deletions discovery-provider/src/challenges/trending_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def on_after_challenge_creation(self, session, metadatas: List[FullEventMetadata
session.add_all(trending_results)

def generate_specifier(self, user_id: int, extra: Dict) -> str:
return f"{extra['week']}:{extra['rank']}"
return f"{extra['week'].strftime('%Y-%m-%d')}:{extra['rank']}"


trending_track_challenge_manager = ChallengeManager(
"trending-track", TrendingChallengeUpdater()
"tt", TrendingChallengeUpdater()
)

trending_underground_track_challenge_manager = ChallengeManager(
"trending-underground-track", TrendingChallengeUpdater()
"tut", TrendingChallengeUpdater()
)

trending_playlist_challenge_manager = ChallengeManager(
"trending-playlist", TrendingChallengeUpdater()
"tp", TrendingChallengeUpdater()
)


Expand Down
6 changes: 4 additions & 2 deletions discovery-provider/src/tasks/calculate_trending_challenges.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

trending_strategy_factory = TrendingStrategyFactory()

def date_to_week(date: datetime) -> str:
return date.strftime('%Y-%m-%d')

def get_latest_blocknumber(session: Session, redis: Redis) -> Optional[int]:
# get latest db state from redis cache
Expand Down Expand Up @@ -65,7 +67,7 @@ def dispatch_trending_challenges(
"rank": idx + 1,
"type": str(type),
"version": str(version),
"week": str(date),
"week": date_to_week(date),
},
)

Expand Down Expand Up @@ -161,7 +163,7 @@ def enqueue_trending_challenges(
"rank": idx + 1,
"type": str(TrendingType.PLAYLISTS),
"version": str(version),
"week": str(date),
"week": date_to_week(date),
},
)

Expand Down

0 comments on commit 371f7b3

Please sign in to comment.