diff --git a/app/controllers/concerns/submission_scoring.rb b/app/controllers/concerns/submission_scoring.rb index 4fc8d737..9c6c5971 100644 --- a/app/controllers/concerns/submission_scoring.rb +++ b/app/controllers/concerns/submission_scoring.rb @@ -86,6 +86,13 @@ module SubmissionScoring output.except!(:error_messages, :count, :failed, :filename, :message, :passed, :stderr, :stdout) end end - outputs + + # Return all test results except for those of a linter if not allowed + show_linter = Python20CourseWeek.show_linter? submission.exercise, submission.user_id + outputs&.reject do |output| + next if show_linter + + output[:file_role] == 'teacher_defined_linter' + end end end diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index ec9f8985..0ba4f483 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -309,6 +309,11 @@ class ExercisesController < ApplicationController else current_user.id end + + # Tips are collected and set with set_available_tips. + # Delete tips for those users who should not see them. + # Doing this here is beneficial because all other (admin) routes still work. + @tips = nil unless Python20CourseWeek.show_tips? @exercise, @user_id end def set_course_token diff --git a/lib/python20_course_week.rb b/lib/python20_course_week.rb new file mode 100644 index 00000000..420c40b9 --- /dev/null +++ b/lib/python20_course_week.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class Python20CourseWeek + + def self.get_for(exercise) + case exercise.title + when /Python20 Aufgabe 1/ + 1 + when /Python20 Aufgabe 2/ + 2 + when /Python20 Aufgabe 3/ + 3 + when /Python20 Aufgabe 4/ + 4 + when /Python20 Snake/ + 4 + else + # Not part of the Python20 course + nil + end + end + + def self.show_tips?(exercise, user_id) + week = get_for(exercise) + return true if week.nil? # Exercise is not part of the experiment + + user_group = UserGroupSeparator.get_tips_group(user_id) + [1, 2].include?(week) && user_group == :show_tips + end + + def self.show_linter?(exercise, user_id) + week = get_for(exercise) + return true if week.nil? # Exercise is not part of the experiment + + user_group = UserGroupSeparator.get_linter_group(user_id) + [3].include?(week) && user_group == :show_linter + end +end diff --git a/lib/user_group_separator.rb b/lib/user_group_separator.rb new file mode 100644 index 00000000..f1fef355 --- /dev/null +++ b/lib/user_group_separator.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class UserGroupSeparator + + # Different user groups for Python20 course based on last digit of the user_id + # 0: show_tips && no_linter + # 1: no_tips && show_linter + # 2: show_tips && show_linter + # 3: no_tips && no_linter + + # separates user into 50% no tips, 50% with tips + def self.get_tips_group(user_id) + user_group = user_id % 4 # => 0, 1, 2, 3 + if [0, 2].include?(user_group) + :show_tips + else # [1, 3].include?(user_group) + :no_tips + end + end + + # separates user into 50% with linter, 50% without linter + def self.get_linter_group(user_id) + user_group = user_id % 4 # => 0, 1, 2, 3 + if [1, 2].include?(user_group) + :show_linter + else # [0, 3].include?(user_group) + :no_linter + end + end +end