Add A/B/n test for interventions
This commit is contained in:
@ -296,10 +296,24 @@ raise: false
|
||||
|
||||
if @embed_options[:disable_interventions]
|
||||
@show_rfc_interventions = false
|
||||
@show_break_interventions = false
|
||||
@show_tips_interventions = false
|
||||
else
|
||||
@show_rfc_interventions = (!user_solved_exercise && !user_got_enough_interventions).to_s
|
||||
show_intervention = (!user_solved_exercise && !user_got_enough_interventions).to_s
|
||||
if @tips.present? && Java21Study.show_tips_intervention?(current_user, @exercise)
|
||||
@show_tips_interventions = show_intervention
|
||||
@show_break_interventions = false
|
||||
@show_rfc_interventions = false
|
||||
elsif Java21Study.show_break_intervention?(current_user, @exercise)
|
||||
@show_tips_interventions = false
|
||||
@show_break_interventions = show_intervention
|
||||
@show_rfc_interventions = false
|
||||
else
|
||||
@show_tips_interventions = false
|
||||
@show_break_interventions = false
|
||||
@show_rfc_interventions = show_intervention
|
||||
end
|
||||
end
|
||||
@show_break_interventions = false
|
||||
|
||||
@hide_rfc_button = @embed_options[:disable_rfc]
|
||||
|
||||
|
33
lib/java21_study.rb
Normal file
33
lib/java21_study.rb
Normal file
@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Java21Study
|
||||
def self.get_for(exercise)
|
||||
java21_collection = ExerciseCollection.find_by(name: 'java2021', id: 13)
|
||||
|
||||
exercise.exercise_collections.include? java21_collection
|
||||
end
|
||||
|
||||
def self.show_tips_intervention?(user, exercise)
|
||||
java21_exercise = get_for(exercise)
|
||||
return false unless java21_exercise # Exercise is not part of the experiment
|
||||
|
||||
user_group = UserGroupSeparator.get_intervention_group(user.id)
|
||||
user_group == :show_tips_intervention
|
||||
end
|
||||
|
||||
def self.show_break_intervention?(user, exercise)
|
||||
java21_exercise = get_for(exercise)
|
||||
return false unless java21_exercise # Exercise is not part of the experiment
|
||||
|
||||
user_group = UserGroupSeparator.get_intervention_group(user.id)
|
||||
user_group == :show_break_intervention
|
||||
end
|
||||
|
||||
def self.allow_redirect_to_community_solution?(user, exercise)
|
||||
java21_exercise = get_for(exercise)
|
||||
return false unless java21_exercise # Exercise is not part of the experiment
|
||||
|
||||
user_group = UserGroupSeparator.get_community_solution_group(user.id)
|
||||
user_group == :show_community_solution
|
||||
end
|
||||
end
|
35
lib/user_group_separator.rb
Normal file
35
lib/user_group_separator.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UserGroupSeparator
|
||||
# Different user groups for the Java21 course based on the user_id
|
||||
# 0: show_tips_intervention && no_b
|
||||
# 1: show_break_intervention && no_b
|
||||
# 2: show_rfc_intervention && no_b
|
||||
# 3: show_tips_intervention && show_b
|
||||
# 4: show_break_intervention && show_b
|
||||
# 5: show_rfc_intervention && show_b
|
||||
|
||||
# separates user into 33% tips interventions, 33% break intervention, 33% rfc intervention
|
||||
def self.get_intervention_group(user_id)
|
||||
user_group = user_id % 6 # => 0, 1, 2, 3, 4, 5
|
||||
case user_group
|
||||
when 0, 3
|
||||
:show_tips_intervention
|
||||
when 1, 4
|
||||
:show_break_intervention
|
||||
else # 2, 5
|
||||
:show_rfc_intervention
|
||||
end
|
||||
end
|
||||
|
||||
# separates user into 50% with Community Solution, 50% without Community Solution
|
||||
def self.get_community_solution_group(user_id)
|
||||
user_group = user_id % 6 # => 0, 1, 2, 3, 4, 5
|
||||
case user_group
|
||||
when 0, 1, 2
|
||||
:show_community_solution
|
||||
else # 3, 4, 5
|
||||
:no_community_solution
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user