-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update backfilljsonmods command for score filters
- Loading branch information
Showing
1 changed file
with
11 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.paginator import Paginator | ||
from tqdm import tqdm | ||
|
||
from common.osu.utils import get_json_mods | ||
from profiles.models import Score | ||
from profiles.models import ScoreFilter | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Generates json mods for stable scores from legacy attributes" | ||
help = "Generates json mods for all ScoreFilters" | ||
|
||
def handle(self, *args, **options): | ||
scores = Score.objects.filter(is_stable=True).order_by("id") | ||
paginator = Paginator(scores, per_page=2000) | ||
|
||
with tqdm(total=scores.count(), smoothing=0) as pbar: | ||
for page in paginator: | ||
for score in page: | ||
score.mods_json = get_json_mods(score.mods, score.is_stable) | ||
pbar.update() | ||
|
||
Score.objects.bulk_update(page, ["mods_json"]) | ||
score_filters = ScoreFilter.objects.all() | ||
for score_filter in tqdm(score_filters): | ||
score_filter.required_mods_json = get_json_mods( | ||
score_filter.required_mods, False | ||
) | ||
score_filter.disqualified_mods_json = get_json_mods( | ||
score_filter.disqualified_mods, False | ||
) | ||
score_filter.save() |