re-introduce exercise description exercise split
This commit is contained in:
@ -36,15 +36,31 @@ class ProxyExercise < ActiveRecord::Base
|
|||||||
Rails.logger.debug("retrieved assigned exercise for user #{user.id}: Exercise #{assigned_user_proxy_exercise.exercise}" )
|
Rails.logger.debug("retrieved assigned exercise for user #{user.id}: Exercise #{assigned_user_proxy_exercise.exercise}" )
|
||||||
assigned_user_proxy_exercise.exercise
|
assigned_user_proxy_exercise.exercise
|
||||||
else
|
else
|
||||||
Rails.logger.debug("find new matching exercise for user #{user.id}" )
|
|
||||||
matching_exercise =
|
matching_exercise =
|
||||||
begin
|
if (token.eql? "e85689d5")
|
||||||
find_matching_exercise(user)
|
Rails.logger.debug("Proxy exercise with token e85689d5, split user in groups..")
|
||||||
rescue => e #fallback
|
group = UserGroupSeparator.getGroupExerciseDescriptionTesting(user)
|
||||||
Rails.logger.error("finding matching exercise failed. Fall back to random exercise! Error: #{$!}" )
|
Rails.logger.debug("user assigned to group #{group}")
|
||||||
@reason[:reason] = "fallback because of error"
|
case group
|
||||||
@reason[:error] = "#{$!}:\n\t#{e.backtrace.join("\n\t")}"
|
when :group_a
|
||||||
exercises.where("expected_difficulty > 1").shuffle.first # difficulty should be > 1 to prevent dummy exercise from being chosen.
|
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
|
end
|
||||||
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user, exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json)
|
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user, exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json)
|
||||||
matching_exercise
|
matching_exercise
|
||||||
|
@ -31,4 +31,18 @@ class UserGroupSeparator
|
|||||||
:recommended_assignment
|
:recommended_assignment
|
||||||
end
|
end
|
||||||
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
|
end
|
Reference in New Issue
Block a user