Skip to content

Commit

Permalink
fix: Only target recent attempts (#1587)
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 authored Feb 29, 2024
1 parent 7faa398 commit 4d398b1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion game/migrations/0090_add_missing_model_solutions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import datetime
import logging
import re

import pytz
from django.apps.registry import Apps
from django.db import migrations

LOGGER = logging.getLogger(__name__)


def add_missing_model_solutions(apps: Apps, *args):
Level = apps.get_model("game", "Level")
Expand Down Expand Up @@ -48,9 +53,14 @@ def add_missing_model_solutions(apps: Apps, *args):
"91",
],
score=10,
finish_time__gte=datetime.datetime(2023, 3, 1, 00, 00, tzinfo=pytz.UTC),
).prefetch_related("level")

for attempt in attempts.iterator(chunk_size=500):
LOGGER.info(f"Retrieved {attempts.count()} attempts.")

processed_count = 0

for attempt in attempts.iterator(chunk_size=1000):
workspace = attempt.workspace

# Get number of blocks from solution - 1 to discount Start block
Expand All @@ -72,6 +82,11 @@ def add_missing_model_solutions(apps: Apps, *args):

attempt.save()

processed_count += 1

if processed_count % 1000 == 0:
LOGGER.info(f"Processed {processed_count} attempts.")


def remove_new_model_solutions(apps: Apps, *args):
Level = apps.get_model("game", "Level")
Expand Down Expand Up @@ -115,6 +130,7 @@ def remove_new_model_solutions(apps: Apps, *args):
"91",
],
score__gt=10,
finish_time__gte=datetime.datetime(2023, 3, 1, 00, 00, tzinfo=pytz.UTC),
).update(score=10)


Expand Down

0 comments on commit 4d398b1

Please sign in to comment.