recommendation also now returns easiest exercise as recommendation if no tag matched could be found

findMatchingExercises only searched for assessed submissions to get processed exercises, fixed this to look at all submissions
This commit is contained in:
Thomas Hille
2017-02-23 13:38:42 +01:00
parent 9935cb3048
commit 0f67297e2c

View File

@ -41,7 +41,8 @@ class ProxyExercise < ActiveRecord::Base
def findMatchingExercise(user) def findMatchingExercise(user)
#exercises.shuffle.first #exercises.shuffle.first
exercisesUserHasAccessed = user.submissions.where(cause: :assess).map{|s| s.exercise}.uniq # hier vielleicht nur betrachten wenn der user die aufgabe assessed oder submitted hat
exercisesUserHasAccessed = user.submissions.map{|s| s.exercise}.uniq
tagsUserHasSeen = exercisesUserHasAccessed.map{|ex| ex.tags}.uniq.flatten tagsUserHasSeen = exercisesUserHasAccessed.map{|ex| ex.tags}.uniq.flatten
puts "exercisesUserHasAccessed #{exercisesUserHasAccessed}" puts "exercisesUserHasAccessed #{exercisesUserHasAccessed}"
@ -54,15 +55,19 @@ class ProxyExercise < ActiveRecord::Base
potentialRecommendedExercises << ex potentialRecommendedExercises << ex
end end
end end
if potentialRecommendedExercises.empty?
getEasiestExercise(exercises)
else
puts "potentialRecommendedExercises: #{potentialRecommendedExercises}" puts "potentialRecommendedExercises: #{potentialRecommendedExercises}"
recommendedExercise = selectBestMatchingExercise(user, exercisesUserHasAccessed, potentialRecommendedExercises) recommendedExercise = selectBestMatchingExercise(user, exercisesUserHasAccessed, potentialRecommendedExercises)
recommendedExercise recommendedExercise
end end
end
def selectBestMatchingExercise(user, exercisesUserHasAccessed, potentialRecommendedExercises) def selectBestMatchingExercise(user, exercisesUserHasAccessed, potentialRecommendedExercises)
topic_knowledge_user_and_max = getUserKnowledgeAndMaxKnowledge(user, exercisesUserHasAccessed) topic_knowledge_user_and_max = getUserKnowledgeAndMaxKnowledge(user, exercisesUserHasAccessed)
puts "topic_knowledge_user_and_max: #{topic_knowledge_user_and_max}" puts "topic_knowledge_user_and_max: #{topic_knowledge_user_and_max}"
puts "potentialRecommendedExercises: #{potentialRecommendedExercises.size}" puts "potentialRecommendedExercises: #{potentialRecommendedExercises.size}: #{potentialRecommendedExercises.map{|p| p.title}}"
topic_knowledge_user = topic_knowledge_user_and_max[:user_topic_knowledge] topic_knowledge_user = topic_knowledge_user_and_max[:user_topic_knowledge]
topic_knowledge_max = topic_knowledge_user_and_max[:max_topic_knowledge] topic_knowledge_max = topic_knowledge_user_and_max[:max_topic_knowledge]
relative_knowledge_improvement = {} relative_knowledge_improvement = {}
@ -80,8 +85,8 @@ class ProxyExercise < ActiveRecord::Base
end end
end end
puts "relative improvements #{relative_knowledge_improvement}" puts "relative improvements #{relative_knowledge_improvement}"
exercise_with_greatest_improvements = relative_knowledge_improvement.max_by{|k,v| v} exercise_with_greatest_improvements = relative_knowledge_improvement.max_by{|k,v| v}.first
exercise_with_greatest_improvements.first exercise_with_greatest_improvements
end end
# [score][quantile] # [score][quantile]
@ -166,4 +171,8 @@ class ProxyExercise < ActiveRecord::Base
{user_topic_knowledge: topic_knowledge_loss_user, max_topic_knowledge: topic_knowledge_max} {user_topic_knowledge: topic_knowledge_loss_user, max_topic_knowledge: topic_knowledge_max}
end end
def getEasiestExercise(exercises)
exercises.order(:expected_difficulty).first
end
end end