Created
February 25, 2014 19:16
-
-
Save deependersingla/9215590 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContentBased | |
Todo_course_weight = 1 | |
Active_course_weight = 2 | |
Completed_course_weight = 3 | |
def self.course_suggestion(user) | |
user_total_projects = user.projects | |
completed_project = user.completed_projects | |
active_project = user_total_projects - completed_project | |
todo_project = user.todos | |
project_hash = { "completed_project" => [completed_project, Completed_course_weight], | |
"active_project" => [active_project, Active_course_weight], | |
"todo_project" => [todo_project, Todo_course_weight] | |
} | |
total_price = 0 | |
total_course = 0 | |
self_paced_course_count = 0 | |
total_length = 0 | |
language = {} | |
difficulty_level = {} | |
course_provider ={} | |
course_subject = {} | |
project_hash.each_value do |h| | |
total_price, total_course, self_paced_course_count,total_length, difficulty_level, course_provider, course_subject, language = calculate_weight(h[0], h[1],total_price, total_course, self_paced_course_count,total_length, difficulty_level, course_provider, course_subject, language) | |
end | |
if self_paced_course_count > total_course - self_paced_course_count | |
length = nil | |
else | |
right_side = total_length / (total_course - self_paced_course_count) | |
length = (0..right_side) | |
end | |
price = (0..(total_price / total_course)) | |
language = language.sort_by{|k,v| v}.reverse.first[0] | |
course_subject = course_subject.sort_by{|k,v| v}.reverse.first[0] | |
course_provider = course_provider.sort_by{|k,v| v}.reverse.first[0] | |
difficulty_level = difficulty_level.sort_by{|k,v| v}.reverse.first[0] | |
d = Array.new | |
Course.where(length_in_weeks: length,price: price,difficulty_level: difficulty_level,course_provider_id: course_provider,language: language).each do |x| | |
x.course_provider_subjects.each do |y| | |
y.course_subjects.each do |z| | |
if z.name == course_subject | |
d.push(x) | |
end | |
end | |
end | |
end | |
d | |
#puts d[0].name | |
#puts total_price, total_course, self_paced_course_count, total_length, difficulty_level,course_provider, course_subject,language | |
end | |
def self.calculate_weight(projects,weight,total_price,total_course,self_paced_course_count,total_length,difficulty_level,course_provider,course_subject,language) | |
projects.each do |p| | |
price = p.course.price | |
total_price = total_price + price * weight | |
total_course = total_course + 1 * weight | |
length = p.course.length_in_weeks | |
if length == nil | |
self_paced_course_count = self_paced_course_count + 1 * weight | |
else | |
total_length = total_length + length * weight | |
end | |
level = p.course.difficulty_level | |
difficulty_level = enter_value_hash(difficulty_level, level, 1*weight) | |
provider = p.course.course_provider_id | |
course_provider = enter_value_hash(course_provider, provider, 1*weight) | |
p.course.course_provider_subjects.each do |cps| | |
cps.course_subjects.each do |cs| | |
subject = cs.name | |
course_subject = enter_value_hash(course_subject, subject, 1*weight) | |
end | |
end | |
lang = p.course.language | |
language = enter_value_hash(language, lang, 1*weight) | |
end | |
return total_price,total_course,self_paced_course_count,total_length,difficulty_level,course_provider,course_subject,language | |
end | |
def self.enter_value_hash(hash,value,key) | |
if hash.has_key?(value) | |
hash[value] = hash[value] + key | |
else | |
hash[value] = key | |
end | |
hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment