Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add day_to_exclude var into periodic jam patch #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions troi/patches/periodic_jams.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from troi import Playlist
from troi.playlist import PlaylistMakerElement

DAYS_OF_RECENT_LISTENS_TO_EXCLUDE = 60 # Exclude tracks listened in last X days from the daily jams playlist
DAILY_JAMS_MIN_RECORDINGS = 25 # the minimum number of recordings we aspire to have in a daily jam, this is not a hard limit
# Exclude tracks listened in last X days from the daily jams playlist
DAYS_OF_RECENT_LISTENS_TO_EXCLUDE = 60
# the minimum number of recordings we aspire to have in a daily jam, this is not a hard limit
DAILY_JAMS_MIN_RECORDINGS = 25
BATCH_SIZE_RECS = 100 # the number of recommendations fetched in 1 go
MAX_RECS_LIMIT = 1000 # the maximum of recommendations available in LB

Expand Down Expand Up @@ -59,6 +61,7 @@ def inputs():
TYPE Must be one of "daily-jams", "weekly-jams" or "weekly-exploration".
JAM_DATE is the date for which the jam is created (this is needed to account for the fact different timezones
can be on different dates). Required formatting for the date is 'YYYY-MM-DD'.
DAYS_TO_EXCLUDE exclude tracks listened in last X days from the daily jams playlist. if 0, no tracks are exclude.
"""
return [{
"type": "argument",
Expand All @@ -75,6 +78,11 @@ def inputs():
"kwargs": {
"required": False
}
}, {
"type": "argument",
"args": ["days_to_exclude"],
"kwargs": {"required": False},

}]

@staticmethod
Expand All @@ -100,7 +108,8 @@ def create(self, inputs):
else:
jam_types = jam_type.lower()
if jam_type not in self.JAM_TYPES:
raise RuntimeError("Jam type must be one of %s" % ", ".join(jam_types))
raise RuntimeError("Jam type must be one of %s" %
", ".join(jam_types))

recs = troi.listenbrainz.recs.UserRecordingRecommendationsElement(user_name,
"raw",
Expand All @@ -123,17 +132,27 @@ def create(self, inputs):
jam_date = "week of " + jam_date
elif jam_type == "weekly-exploration":
# Remove tracks that have been listened to before.
never_listened = troi.filters.NeverListenedFilterElement(remove_unlistened=False)
never_listened = troi.filters.NeverListenedFilterElement(
remove_unlistened=False)
never_listened.set_sources(recent_listens_lookup)
jam_name = "Weekly Exploration"
jam_date = "week of " + jam_date
else:
raise RuntimeError("someone goofed up!")

latest_filter = troi.filters.LatestListenedAtFilterElement(DAYS_OF_RECENT_LISTENS_TO_EXCLUDE)
if "days_to_exclude" in inputs:
latest_filter = troi.filters.LatestListenedAtFilterElement(
inputs["days_to_exclude"]
)
else:
latest_filter = troi.filters.LatestListenedAtFilterElement(
DAYS_OF_RECENT_LISTENS_TO_EXCLUDE
)

latest_filter.set_sources(never_listened)

feedback_lookup = troi.listenbrainz.feedback.ListensFeedbackLookup(user_name, auth_token=inputs.get("token"))
feedback_lookup = troi.listenbrainz.feedback.ListensFeedbackLookup(
user_name, auth_token=inputs.get("token"))
feedback_lookup.set_sources(latest_filter)

recs_lookup = troi.musicbrainz.recording_lookup.RecordingLookupElement()
Expand Down
Loading