diff --git a/game/messages.py b/game/messages.py index 98286da40..2048e87df 100644 --- a/game/messages.py +++ b/game/messages.py @@ -3329,8 +3329,8 @@ def get_episode_title(episode_id): 10: "Introduction to Python", 11: "Python", 12: "Counted Loops Using While", - 13: "Indeterminate Loops", - 14: "Selection in a Loop", + 13: "Selection in a Loop", + 14: "Indeterminate Loops", 15: "For Loops", 16: "Output, Operators, and Data", 17: "Variables, Input, and Casting", diff --git a/game/migrations/0102_reoder_episodes_13_14.py b/game/migrations/0102_reoder_episodes_13_14.py new file mode 100644 index 000000000..be414fe9b --- /dev/null +++ b/game/migrations/0102_reoder_episodes_13_14.py @@ -0,0 +1,136 @@ +from django.apps.registry import Apps +from django.db import migrations + + +def swap_episodes_13_14(apps: Apps, *args): + Episode = apps.get_model("game", "Episode") + Level = apps.get_model("game", "Level") + + episode12 = Episode.objects.get(pk=12) + episode13 = Episode.objects.get(pk=13) + episode14 = Episode.objects.get(pk=14) + episode15 = Episode.objects.get(pk=15) + + episode13_levels = Level.objects.filter( + default=True, name__in=range(1026, 1041) + ) + episode14_levels = Level.objects.filter( + default=True, name__in=range(1014, 1026) + ) + + episode13_levels.update(episode=episode14) + episode14_levels.update(episode=episode13) + + old_episode13_name = episode13.name + old_episode13_lesson_plan_link = episode13.lesson_plan_link + old_episode13_slides_link = episode13.slides_link + old_episode13_worksheet_link = episode13.worksheet_link + old_episode13_video_link = episode13.video_link + old_episode14_name = episode14.name + old_episode14_lesson_plan_link = episode14.lesson_plan_link + old_episode14_slides_link = episode14.slides_link + old_episode14_worksheet_link = episode14.worksheet_link + old_episode14_video_link = episode14.video_link + + episode13.name = old_episode14_name + episode13.lesson_plan_link = old_episode14_lesson_plan_link + episode13.slides_link = old_episode14_slides_link + episode13.worksheet_link = old_episode14_worksheet_link + episode13.video_link = old_episode14_video_link + episode14.name = old_episode13_name + episode14.lesson_plan_link = old_episode13_lesson_plan_link + episode14.slides_link = old_episode13_slides_link + episode14.worksheet_link = old_episode13_worksheet_link + episode14.video_link = old_episode13_video_link + + episode12.next_episode = episode13 + episode13.next_episode = episode14 + episode14.next_episode = episode15 + + episode12.save() + episode13.save() + episode14.save() + + episode12_last_level = episode12.level_set.last() + episode13_last_level = episode13.level_set.last() + episode14_last_level = episode14.level_set.last() + + episode12_last_level.next_level = episode13.level_set.all()[0] + episode13_last_level.next_level = episode14.level_set.all()[0] + episode14_last_level.next_level = episode15.level_set.all()[0] + + episode12_last_level.save() + episode13_last_level.save() + episode14_last_level.save() + + +def unswap_episodes_13_14(apps: Apps, *args): + Episode = apps.get_model("game", "Episode") + Level = apps.get_model("game", "Level") + + episode12 = Episode.objects.get(pk=12) + episode13 = Episode.objects.get(pk=13) + episode14 = Episode.objects.get(pk=14) + episode15 = Episode.objects.get(pk=15) + + episode13_levels = Level.objects.filter( + default=True, name__in=range(1014, 1026) + ) + episode14_levels = Level.objects.filter( + default=True, name__in=range(1026, 1041) + ) + + episode13_levels.update(episode=episode14) + episode14_levels.update(episode=episode13) + + old_episode13_name = episode13.name + old_episode13_lesson_plan_link = episode13.lesson_plan_link + old_episode13_slides_link = episode13.slides_link + old_episode13_worksheet_link = episode13.worksheet_link + old_episode13_video_link = episode13.video_link + old_episode14_name = episode14.name + old_episode14_lesson_plan_link = episode14.lesson_plan_link + old_episode14_slides_link = episode14.slides_link + old_episode14_worksheet_link = episode14.worksheet_link + old_episode14_video_link = episode14.video_link + + episode13.name = old_episode14_name + episode13.lesson_plan_link = old_episode14_lesson_plan_link + episode13.slides_link = old_episode14_slides_link + episode13.worksheet_link = old_episode14_worksheet_link + episode13.video_link = old_episode14_video_link + episode14.name = old_episode13_name + episode14.lesson_plan_link = old_episode13_lesson_plan_link + episode14.slides_link = old_episode13_slides_link + episode14.worksheet_link = old_episode13_worksheet_link + episode14.video_link = old_episode13_video_link + + episode12.next_episode = episode14 + episode14.next_episode = episode13 + episode13.next_episode = episode15 + + episode12.save() + episode13.save() + episode14.save() + + episode12_last_level = episode12.level_set.last() + episode13_last_level = episode13.level_set.last() + episode14_last_level = episode14.level_set.last() + + episode12_last_level.next_level = episode14.level_set.all()[0] + episode14_last_level.next_level = episode13.level_set.all()[0] + episode13_last_level.next_level = episode14.level_set.all()[0] + + episode12_last_level.save() + episode13_last_level.save() + episode14_last_level.save() + + +class Migration(migrations.Migration): + dependencies = [("game", "0101_rename_episodes")] + + operations = [ + migrations.RunPython( + code=swap_episodes_13_14, reverse_code=unswap_episodes_13_14 + ) + ] diff --git a/game/tests/test_scoreboard.py b/game/tests/test_scoreboard.py index 8ec6af4da..d36f2733f 100644 --- a/game/tests/test_scoreboard.py +++ b/game/tests/test_scoreboard.py @@ -80,7 +80,7 @@ def test_teacher_multiple_students_multiple_levels(self): # Generate results student_data, headers, level_headers, levels_sorted = scoreboard_data( - episode_ids, attempts_per_student + episode_ids, attempts_per_student, "blockly" ) ( shared_headers, diff --git a/game/views/scoreboard.py b/game/views/scoreboard.py index 6a1db162d..6492d0f11 100644 --- a/game/views/scoreboard.py +++ b/game/views/scoreboard.py @@ -134,6 +134,10 @@ def to_name(level): return f"L{level.name}" +def to_python_name(level): + return f"L{int(level.name) - 1000}" + + def shared_level_to_name(level, user): return ( f"{level.name} (you)" @@ -142,14 +146,16 @@ def shared_level_to_name(level, user): ) -def scoreboard_data(episode_ids, attempts_per_students): +def scoreboard_data(episode_ids, attempts_per_students, language): # Show the total score, total time and score of each level levels_sorted = [] for episode_id in episode_ids: episode = Episode.objects.get(id=episode_id) levels_sorted += episode.levels - level_headers = list(map(to_name, levels_sorted)) + to_name_function = to_name if language == "blockly" else to_python_name + + level_headers = list(map(to_name_function, levels_sorted)) student_data = [ student_row(levels_sorted, student, best_attempts) for student, best_attempts in attempts_per_students.items() @@ -341,7 +347,7 @@ def scoreboard(request, language): attempts_per_student[student] = best_attempts (student_data, headers, level_headers, levels_sorted) = scoreboard_data( - episode_ids, attempts_per_student + episode_ids, attempts_per_student, language ) improvement_data = get_improvement_data(attempts_per_student)