Last active
November 10, 2015 03:23
-
-
Save AlexVKO/5ec2834bdbf13324e63c to your computer and use it in GitHub Desktop.
Code for matching between Trainees And Jobs
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
module Matching | |
extend ActiveSupport::Concern | |
def run_matching trainee | |
self.trainee = trainee | |
self.matching = {rate: 0} | |
self.weight_of_exact = { city: 19.3, course: 13.9, semester: 19.3, languages: 17.4, other_courses: 21.3 } | |
self.run | |
end | |
def run | |
self.check :cities | |
self.check :courses | |
self.check :semester | |
self.check :languages | |
self.check :other_course | |
self.round_rate | |
self.matching | |
end | |
def check type | |
case type | |
when :cities then check_cities | |
when :courses then check_courses | |
when :semester then check_semester | |
when :languages then check_languages | |
when :other_course then check_other_course | |
end | |
end | |
def check_cities | |
current_check = self.addresses.select(:id).where(id: self.trainee[:city_ids]).size | |
self.matching[:city] = current_check > 0 | |
self.matching[:rate] += self.weight_of_exact[:city] if current_check > 0 | |
end | |
def check_courses | |
included = self.courses_id.include?(self.trainee[:course_id]) | |
self.matching[:course] = included | |
matching[:rate] += weight_of_exact[:course] if included | |
end | |
def check_semester | |
more_then = self.semester >= self.trainee[:semester] | |
self.matching[:semester] = more_then | |
self.matching[:rate] += self.weight_of_exact[:semester] if more_then | |
end | |
def check_languages | |
current_check = job.languages.select(:title).where(title: self.trainee[:languages]).size | |
self.matching[:languages] = current_check > 0 | |
self.matching[:rate] += self.weight_of_exact[:city] if current_check > 0 | |
end | |
def check_other_course | |
current_presence = self.requiriments.present? and trainee[:other_courses] | |
self.matching[:other_course] = current_presence | |
self.matching[:rate] += self.weight_of_exact[:other_courses] if current_presence | |
end | |
def round_rate | |
self.matching[:rate] = self.matching[:rate].round(2) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment