diff --git a/app/models/proxy_exercise.rb b/app/models/proxy_exercise.rb index 3d9197fb..c6da3870 100644 --- a/app/models/proxy_exercise.rb +++ b/app/models/proxy_exercise.rb @@ -36,15 +36,31 @@ class ProxyExercise < ActiveRecord::Base Rails.logger.debug("retrieved assigned exercise for user #{user.id}: Exercise #{assigned_user_proxy_exercise.exercise}" ) assigned_user_proxy_exercise.exercise else - Rails.logger.debug("find new matching exercise for user #{user.id}" ) matching_exercise = - begin - find_matching_exercise(user) - rescue => e #fallback - Rails.logger.error("finding matching exercise failed. Fall back to random exercise! Error: #{$!}" ) - @reason[:reason] = "fallback because of error" - @reason[:error] = "#{$!}:\n\t#{e.backtrace.join("\n\t")}" - exercises.where("expected_difficulty > 1").shuffle.first # difficulty should be > 1 to prevent dummy exercise from being chosen. + if (token.eql? "e85689d5") + Rails.logger.debug("Proxy exercise with token e85689d5, split user in groups..") + group = UserGroupSeparator.getGroupExerciseDescriptionTesting(user) + Rails.logger.debug("user assigned to group #{group}") + case group + when :group_a + exercises.where(id: 557).first + when :group_b + exercises.where(id: 558).first + when :group_c + exercises.where(id: 559).first + when :group_d + exercises.where(id: 560).first + end + else + Rails.logger.debug("find new matching exercise for user #{user.id}" ) + begin + find_matching_exercise(user) + rescue => e #fallback + Rails.logger.error("finding matching exercise failed. Fall back to random exercise! Error: #{$!}" ) + @reason[:reason] = "fallback because of error" + @reason[:error] = "#{$!}:\n\t#{e.backtrace.join("\n\t")}" + exercises.where("expected_difficulty > 1").shuffle.first # difficulty should be > 1 to prevent dummy exercise from being chosen. + end end user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user, exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json) matching_exercise diff --git a/lib/user_group_separator.rb b/lib/user_group_separator.rb index 4dcd00e1..2333b686 100644 --- a/lib/user_group_separator.rb +++ b/lib/user_group_separator.rb @@ -31,4 +31,18 @@ class UserGroupSeparator :recommended_assignment end end + + def self.getGroupExerciseDescriptionTesting(user) + groupById = user.id % 4 + if groupById == 0 + :group_a + elsif groupById == 1 + :group_b + elsif groupById == 2 + :group_c + else # 3 + :group_d + end + end + end \ No newline at end of file