-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make algorithm score setting consistent with presence of model s…
…olutions (#1585) * fix: Set Python scores to 10 * Lockfile * Make algo scores consistent with model solutions * Remove prints * Feedback again * Small fixes * Iterator
- Loading branch information
1 parent
d3c688e
commit bc244c3
Showing
7 changed files
with
452 additions
and
263 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 +1,54 @@ | ||
from django.contrib import admin | ||
|
||
from game.models import Level, Block, Episode, Workspace, LevelDecor | ||
from game.models import Level, Block, Episode, Workspace, LevelDecor, Attempt | ||
|
||
|
||
class LevelAdmin(admin.ModelAdmin): | ||
search_fields = ["name", "id", "owner__user__username", "owner__user__first_name"] | ||
search_fields = [ | ||
"name", | ||
"id", | ||
"owner__user__username", | ||
"owner__user__first_name", | ||
] | ||
raw_id_fields = ["next_level", "locked_for_class"] | ||
readonly_fields = ["owner"] | ||
list_display = ["name", "id", "episode", "owner"] | ||
|
||
|
||
class EpisodeAdmin(admin.ModelAdmin): | ||
list_display = ["id", "name"] | ||
|
||
|
||
class WorkspaceAdmin(admin.ModelAdmin): | ||
raw_id_fields = ["owner"] | ||
|
||
|
||
class AttemptAdmin(admin.ModelAdmin): | ||
search_fields = [ | ||
"level", | ||
"student", | ||
"start_time", | ||
"finish_time", | ||
"is_best_attempt", | ||
] | ||
raw_id_fields = ["student"] | ||
list_display = [ | ||
"level", | ||
"student", | ||
"start_time", | ||
"finish_time", | ||
"is_best_attempt", | ||
] | ||
|
||
|
||
class LevelDecorAdmin(admin.ModelAdmin): | ||
search_fields = ["level__name"] | ||
list_display = ["id", "level", "x", "y", "decorName"] | ||
|
||
|
||
admin.site.register(Level, LevelAdmin) | ||
admin.site.register(Episode, EpisodeAdmin) | ||
admin.site.register(Workspace, WorkspaceAdmin) | ||
admin.site.register(Episode) | ||
admin.site.register(Block) | ||
admin.site.register(Attempt, AttemptAdmin) | ||
admin.site.register(LevelDecor, LevelDecorAdmin) |
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
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import re | ||
|
||
from django.apps.registry import Apps | ||
from django.db import migrations | ||
|
||
|
||
def add_missing_model_solutions(apps: Apps, *args): | ||
Level = apps.get_model("game", "Level") | ||
|
||
model_solutions = { | ||
"80": "[5]", | ||
"81": "[10]", | ||
"82": "[11]", | ||
"83": "[5]", | ||
"84": "[5]", | ||
"85": "[3]", | ||
"86": "[8]", | ||
"87": "[8]", | ||
"88": "[11]", | ||
"89": "[11]", | ||
"90": "[15]", | ||
"91": "[15]", | ||
} | ||
|
||
for level_name, model_solution in model_solutions.items(): | ||
count = Level.objects.filter(name=level_name).update( | ||
model_solution=model_solution, disable_algorithm_score=False | ||
) | ||
assert count == 1 | ||
|
||
Attempt = apps.get_model("game", "Attempt") | ||
|
||
attempts = Attempt.objects.filter( | ||
level__name__in=[ | ||
"80", | ||
"81", | ||
"82", | ||
"83", | ||
"84", | ||
"85", | ||
"86", | ||
"87", | ||
"88", | ||
"89", | ||
"90", | ||
"91", | ||
], | ||
score=10, | ||
).prefetch_related("level") | ||
|
||
for attempt in attempts.iterator(chunk_size=500): | ||
workspace = attempt.workspace | ||
|
||
# Get number of blocks from solution - 1 to discount Start block | ||
number_of_blocks = len(re.findall("<block", workspace)) - 1 | ||
|
||
model_solution = model_solutions[attempt.level.name] | ||
|
||
ideal_number_of_blocks = int( | ||
model_solution.replace("[", "").replace("]", "") | ||
) | ||
|
||
if number_of_blocks == ideal_number_of_blocks: | ||
attempt.score = 20 | ||
else: | ||
difference = abs(number_of_blocks - ideal_number_of_blocks) | ||
|
||
if difference < 10: | ||
attempt.score += 10 - difference | ||
|
||
attempt.save() | ||
|
||
|
||
def remove_new_model_solutions(apps: Apps, *args): | ||
Level = apps.get_model("game", "Level") | ||
|
||
Level.objects.filter( | ||
name__in=[ | ||
"80", | ||
"81", | ||
"82", | ||
"83", | ||
"84", | ||
"85", | ||
"86", | ||
"87", | ||
"88", | ||
"89", | ||
"90", | ||
"91", | ||
] | ||
).update(model_solution="[]", disable_algorithm_score=True) | ||
|
||
Attempt = apps.get_model("game", "Attempt") | ||
|
||
Attempt.objects.filter( | ||
level__name__in=[ | ||
"80", | ||
"81", | ||
"82", | ||
"83", | ||
"84", | ||
"85", | ||
"86", | ||
"87", | ||
"88", | ||
"89", | ||
"90", | ||
"91", | ||
], | ||
score__gt=10, | ||
).update(score=10) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [("game", "0089_episodes_in_development")] | ||
operations = [ | ||
migrations.RunPython( | ||
add_missing_model_solutions, | ||
reverse_code=remove_new_model_solutions, | ||
) | ||
] |
40 changes: 40 additions & 0 deletions
40
game/migrations/0091_disable_algo_score_if_no_model_solution.py
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.apps.registry import Apps | ||
from django.db import migrations | ||
|
||
|
||
def disable_algo_score_for_levels_without_model_solution(apps: Apps, *args): | ||
Level = apps.get_model("game", "Level") | ||
|
||
Level.objects.filter(default=True, model_solution="[]").update( | ||
disable_algorithm_score=True | ||
) | ||
|
||
Attempt = apps.get_model("game", "Attempt") | ||
|
||
Attempt.objects.filter( | ||
level__default=True, level__model_solution="[]", score=20 | ||
).update(score=10) | ||
|
||
|
||
def enable_algo_score_for_levels_without_model_solution(apps: Apps, *args): | ||
Level = apps.get_model("game", "Level") | ||
|
||
Level.objects.filter(default=True, model_solution="[]").update( | ||
disable_algorithm_score=False | ||
) | ||
|
||
Attempt = apps.get_model("game", "Attempt") | ||
|
||
Attempt.objects.filter( | ||
level__default=True, level__model_solution="[]", score=10 | ||
).update(score=20) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [("game", "0090_add_missing_model_solutions")] | ||
operations = [ | ||
migrations.RunPython( | ||
disable_algo_score_for_levels_without_model_solution, | ||
reverse_code=enable_algo_score_for_levels_without_model_solution, | ||
) | ||
] |
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
Oops, something went wrong.