Commit bd376cef authored by fred's avatar fred

stamina: wait 7 days before allowing same track

parent c3f21f38
......@@ -34,5 +34,9 @@ class AppSettings:
def ON_AIR_SWITCH_URL(self):
return self.get_setting('ON_AIR_SWITCH_URL', None)
@property
def NO_REPEAT_DELAY(self):
return self.get_setting('NO_REPEAT_DELAY', 7)
app_settings = AppSettings()
......@@ -40,6 +40,10 @@ class Command(BaseCommand):
except AttributeError:
jingles = []
recent_tracks_id = [x.track_id for x in
SomaLogLine.objects.exclude(on_air=False).filter(
track__isnull=False,
play_timestamp__gt=datetime.datetime.now() - datetime.timedelta(days=app_settings.NO_REPEAT_DELAY))]
t0 = datetime.datetime.now()
while current_datetime < end_datetime and adjustment_counter < 5:
if (current_datetime - start_datetime) > max_duration and (
......@@ -57,8 +61,12 @@ class Command(BaseCommand):
track = Track.objects.filter(
nonstop_zones=zone,
duration__isnull=False).exclude(
id__in=[x.id for x in playlist if isinstance(x, Track)]
id__in=recent_tracks_id + [x.id for x in playlist if isinstance(x, Track)]
).order_by('?').first()
if track is None:
# no track, reduce recent tracks exclusion
recent_tracks_id = recent_tracks_id[:len(recent_tracks_id)//2]
continue
playlist.append(track)
current_datetime = start_datetime + sum(
[x.duration for x in playlist], datetime.timedelta(seconds=0))
......@@ -72,7 +80,7 @@ class Command(BaseCommand):
duration__gte=remaining_time,
duration__lt=remaining_time + datetime.timedelta(seconds=1)
).exclude(
id__in=[x.id for x in playlist if isinstance(x, Track)]
id__in=recent_tracks_id + [x.id for x in playlist if isinstance(x, Track)]
).order_by('?').first()
if track:
# found a track
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment