From c27bac1cf5001c24aee8c5bc573d527b90569427 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 6 Sep 2021 19:06:34 +0000 Subject: [PATCH] Skip scheduled work for games when music DB for that game was not imported. --- bemani/backend/iidx/cannonballers.py | 41 ++++----- bemani/backend/iidx/copula.py | 41 ++++----- bemani/backend/iidx/pendual.py | 41 ++++----- bemani/backend/iidx/rootage.py | 41 ++++----- bemani/backend/iidx/sinobuz.py | 41 ++++----- bemani/backend/iidx/spada.py | 41 ++++----- bemani/backend/iidx/tricoro.py | 41 ++++----- bemani/backend/jubeat/clan.py | 45 +++++----- bemani/backend/jubeat/prop.py | 114 +++++++++++++------------ bemani/backend/jubeat/qubell.py | 45 +++++----- bemani/backend/jubeat/saucer.py | 41 ++++----- bemani/backend/jubeat/saucerfulfill.py | 45 +++++----- bemani/backend/popn/usaneko.py | 41 ++++----- 13 files changed, 316 insertions(+), 302 deletions(-) diff --git a/bemani/backend/iidx/cannonballers.py b/bemani/backend/iidx/cannonballers.py index f31f2ba..82f778f 100644 --- a/bemani/backend/iidx/cannonballers.py +++ b/bemani/backend/iidx/cannonballers.py @@ -99,27 +99,28 @@ class IIDXCannonBallers(IIDXCourse, IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/copula.py b/bemani/backend/iidx/copula.py index 3dfa3b8..e7e0dee 100644 --- a/bemani/backend/iidx/copula.py +++ b/bemani/backend/iidx/copula.py @@ -99,27 +99,28 @@ class IIDXCopula(IIDXCourse, IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/pendual.py b/bemani/backend/iidx/pendual.py index 1f4172f..a489386 100644 --- a/bemani/backend/iidx/pendual.py +++ b/bemani/backend/iidx/pendual.py @@ -96,27 +96,28 @@ class IIDXPendual(IIDXCourse, IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/rootage.py b/bemani/backend/iidx/rootage.py index 21f9ee1..ca2a8b7 100644 --- a/bemani/backend/iidx/rootage.py +++ b/bemani/backend/iidx/rootage.py @@ -99,27 +99,28 @@ class IIDXRootage(IIDXCourse, IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/sinobuz.py b/bemani/backend/iidx/sinobuz.py index 81f6972..6ab93e4 100644 --- a/bemani/backend/iidx/sinobuz.py +++ b/bemani/backend/iidx/sinobuz.py @@ -99,27 +99,28 @@ class IIDXSinobuz(IIDXCourse, IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/spada.py b/bemani/backend/iidx/spada.py index e68676f..d7d4031 100644 --- a/bemani/backend/iidx/spada.py +++ b/bemani/backend/iidx/spada.py @@ -95,27 +95,28 @@ class IIDXSpada(IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/iidx/tricoro.py b/bemani/backend/iidx/tricoro.py index d9c3c8f..d48453f 100644 --- a/bemani/backend/iidx/tricoro.py +++ b/bemani/backend/iidx/tricoro.py @@ -94,27 +94,28 @@ class IIDXTricoro(IIDXBase): # Generate a new list of three dailies. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = list(set([song.id for song in data.local.music.get_all_songs(cls.game, cls.version)])) - daily_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'dailies', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': daily_songs, - }, - ) - events.append(( - 'iidx_daily_charts', - { - 'version': cls.version, - 'music': daily_songs, - }, - )) + if len(all_songs) >= 3: + daily_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'dailies', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': daily_songs, + }, + ) + events.append(( + 'iidx_daily_charts', + { + 'version': cls.version, + 'music': daily_songs, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'daily_charts', 'daily') return events @classmethod diff --git a/bemani/backend/jubeat/clan.py b/bemani/backend/jubeat/clan.py index 6601fb6..39a287b 100644 --- a/bemani/backend/jubeat/clan.py +++ b/bemani/backend/jubeat/clan.py @@ -97,29 +97,30 @@ class JubeatClan( # these song IDs, so we explicitly exclude them. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version) if song.id not in cls.FIVE_PLAYS_UNLOCK_EVENT_SONG_IDS) - daily_songs = random.sample(all_songs, 2) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'fc_challenge', - { - 'start_time': start_time, - 'end_time': end_time, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - ) - events.append(( - 'jubeat_fc_challenge_charts', - { - 'version': cls.version, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - )) + if len(all_songs) >= 2: + daily_songs = random.sample(all_songs, 2) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'fc_challenge', + { + 'start_time': start_time, + 'end_time': end_time, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + ) + events.append(( + 'jubeat_fc_challenge_charts', + { + 'version': cls.version, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') return events def __get_course_list(self) -> List[Dict[str, Any]]: diff --git a/bemani/backend/jubeat/prop.py b/bemani/backend/jubeat/prop.py index 799c431..a9cbf8f 100644 --- a/bemani/backend/jubeat/prop.py +++ b/bemani/backend/jubeat/prop.py @@ -319,73 +319,75 @@ class JubeatProp( # Generate a new league course list, save it to the DB. start_time, end_time = data.local.network.get_schedule_duration('weekly') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version)) - league_songs = random.sample(all_songs, 3) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'league', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': league_songs, - }, - ) - events.append(( - 'jubeat_league_course', - { - 'version': cls.version, - 'songs': league_songs, - }, - )) + if len(all_songs) >= 3: + league_songs = random.sample(all_songs, 3) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'league', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': league_songs, + }, + ) + events.append(( + 'jubeat_league_course', + { + 'version': cls.version, + 'songs': league_songs, + }, + )) - # League ID for the current league we just added. - leagueid = int(start_time / 604800) + # League ID for the current league we just added. + leagueid = int(start_time / 604800) - # Evaluate player scores on previous courses and find players - # that didn't play last week. - all_profiles = data.local.user.get_all_profiles(cls.game, cls.version) - scores, absentees = cls._get_league_scores(data, leagueid, all_profiles) + # Evaluate player scores on previous courses and find players + # that didn't play last week. + all_profiles = data.local.user.get_all_profiles(cls.game, cls.version) + scores, absentees = cls._get_league_scores(data, leagueid, all_profiles) - # Get user IDs to promote, demote and ignore based on scores. - promote, ignore, demote = cls._get_league_buckets(scores) - demote.extend(cls._get_league_absentees(data, leagueid, absentees)) + # Get user IDs to promote, demote and ignore based on scores. + promote, ignore, demote = cls._get_league_buckets(scores) + demote.extend(cls._get_league_absentees(data, leagueid, absentees)) - # Actually modify the profiles so the game knows to tell the user. - for userid in promote: - cls._modify_profile(data, userid, 'promote') - for userid in demote: - cls._modify_profile(data, userid, 'demote') + # Actually modify the profiles so the game knows to tell the user. + for userid in promote: + cls._modify_profile(data, userid, 'promote') + for userid in demote: + cls._modify_profile(data, userid, 'demote') - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'league_course', 'weekly') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'league_course', 'weekly') if data.local.network.should_schedule(cls.game, cls.version, 'fc_challenge', 'daily'): # Generate a new list of two FC challenge songs. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version)) - daily_songs = random.sample(all_songs, 2) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'fc_challenge', - { - 'start_time': start_time, - 'end_time': end_time, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - ) - events.append(( - 'jubeat_fc_challenge_charts', - { - 'version': cls.version, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - )) + if len(all_songs) >= 2: + daily_songs = random.sample(all_songs, 2) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'fc_challenge', + { + 'start_time': start_time, + 'end_time': end_time, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + ) + events.append(( + 'jubeat_fc_challenge_charts', + { + 'version': cls.version, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') return events diff --git a/bemani/backend/jubeat/qubell.py b/bemani/backend/jubeat/qubell.py index 27a6a77..eab0f4f 100644 --- a/bemani/backend/jubeat/qubell.py +++ b/bemani/backend/jubeat/qubell.py @@ -66,29 +66,30 @@ class JubeatQubell( # Generate a new list of two FC challenge songs. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version)) - daily_songs = random.sample(all_songs, 2) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'fc_challenge', - { - 'start_time': start_time, - 'end_time': end_time, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - ) - events.append(( - 'jubeat_fc_challenge_charts', - { - 'version': cls.version, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - )) + if len(all_songs) >= 2: + daily_songs = random.sample(all_songs, 2) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'fc_challenge', + { + 'start_time': start_time, + 'end_time': end_time, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + ) + events.append(( + 'jubeat_fc_challenge_charts', + { + 'version': cls.version, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') return events def __get_global_info(self) -> Node: diff --git a/bemani/backend/jubeat/saucer.py b/bemani/backend/jubeat/saucer.py index a0eb797..90285a6 100644 --- a/bemani/backend/jubeat/saucer.py +++ b/bemani/backend/jubeat/saucer.py @@ -45,27 +45,28 @@ class JubeatSaucer( # Generate a new list of two FC challenge songs. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version)) - today_song = random.sample(all_songs, 1)[0] - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'fc_challenge', - { - 'start_time': start_time, - 'end_time': end_time, - 'today': today_song, - }, - ) - events.append(( - 'jubeat_fc_challenge_charts', - { - 'version': cls.version, - 'today': today_song, - }, - )) + if all_songs: + today_song = random.sample(all_songs, 1)[0] + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'fc_challenge', + { + 'start_time': start_time, + 'end_time': end_time, + 'today': today_song, + }, + ) + events.append(( + 'jubeat_fc_challenge_charts', + { + 'version': cls.version, + 'today': today_song, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') return events def handle_shopinfo_regist_request(self, request: Node) -> Node: diff --git a/bemani/backend/jubeat/saucerfulfill.py b/bemani/backend/jubeat/saucerfulfill.py index 3060aaa..bdc58b3 100644 --- a/bemani/backend/jubeat/saucerfulfill.py +++ b/bemani/backend/jubeat/saucerfulfill.py @@ -56,29 +56,30 @@ class JubeatSaucerFulfill( # Generate a new list of two FC challenge songs. start_time, end_time = data.local.network.get_schedule_duration('daily') all_songs = set(song.id for song in data.local.music.get_all_songs(cls.game, cls.version)) - daily_songs = random.sample(all_songs, 2) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'fc_challenge', - { - 'start_time': start_time, - 'end_time': end_time, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - ) - events.append(( - 'jubeat_fc_challenge_charts', - { - 'version': cls.version, - 'today': daily_songs[0], - 'whim': daily_songs[1], - }, - )) + if len(all_songs) >= 2: + daily_songs = random.sample(all_songs, 2) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'fc_challenge', + { + 'start_time': start_time, + 'end_time': end_time, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + ) + events.append(( + 'jubeat_fc_challenge_charts', + { + 'version': cls.version, + 'today': daily_songs[0], + 'whim': daily_songs[1], + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'fc_challenge', 'daily') return events def handle_shopinfo_regist_request(self, request: Node) -> Node: diff --git a/bemani/backend/popn/usaneko.py b/bemani/backend/popn/usaneko.py index 731c9f2..828e456 100644 --- a/bemani/backend/popn/usaneko.py +++ b/bemani/backend/popn/usaneko.py @@ -71,27 +71,28 @@ class PopnMusicUsaNeko(PopnMusicBase): # Generate a new course list, save it to the DB. start_time, end_time = data.local.network.get_schedule_duration('weekly') all_songs = [song.id for song in data.local.music.get_all_songs(cls.game, cls.version)] - course_song = random.choice(all_songs) - data.local.game.put_time_sensitive_settings( - cls.game, - cls.version, - 'course', - { - 'start_time': start_time, - 'end_time': end_time, - 'music': course_song, - }, - ) - events.append(( - 'pnm_course', - { - 'version': cls.version, - 'song': course_song, - }, - )) + if all_songs: + course_song = random.choice(all_songs) + data.local.game.put_time_sensitive_settings( + cls.game, + cls.version, + 'course', + { + 'start_time': start_time, + 'end_time': end_time, + 'music': course_song, + }, + ) + events.append(( + 'pnm_course', + { + 'version': cls.version, + 'song': course_song, + }, + )) - # Mark that we did some actual work here. - data.local.network.mark_scheduled(cls.game, cls.version, 'course', 'weekly') + # Mark that we did some actual work here. + data.local.network.mark_scheduled(cls.game, cls.version, 'course', 'weekly') return events def __score_to_rank(self, score: int) -> int: