Skip to content

Commit

Permalink
Swap order of episodes 13 and 14
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 6, 2024
1 parent 06baafa commit f39f113
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 6 deletions.
4 changes: 2 additions & 2 deletions game/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
136 changes: 136 additions & 0 deletions game/migrations/0102_reoder_episodes_13_14.py
Original file line number Diff line number Diff line change
@@ -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
)
]
2 changes: 1 addition & 1 deletion game/tests/test_scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions game/views/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f39f113

Please sign in to comment.