@ionaai/rtnapi
Version:
common api collection for RTN
186 lines (156 loc) • 5.61 kB
JavaScript
;
var _ = require("underscore");
var mongoose = require("mongoose");
var DBModel = require('@ionaai/rtndbmodel');
var User = DBModel.user;
var Job = DBModel.job;
var AppliedJobData = DBModel.appliedJobData;
//Micro-functions
//1. Filters
var genderCheck = function(master, job){
var genderFound = _.filter(job.gender, function (jobGender) {
return (jobGender === master.gender) ;
});
return genderFound.length;
};
var filters = [
{name: 'gender', filterFunc: genderCheck}
];
//2. Match makers
var salaryMatch = function(master, job){
if(master.jobPreferences && master.jobPreferences.abbyAnswer){
var salPref = _.find(master.jobPreferences.abbyAnswer, function(i){
return i.parameter === "Salary"
});
console.log("salPref.answer.text " + salPref.answer.text);
if(salPref && salPref.answer){
var prefSalaryRange = {
min : 0,
max : 0
}
var answer = salPref.answer;
if(salPref.answer.text === "10,000 - 12,000 per month"){
prefSalaryRange = {
min : 10000,
max : 12000
};
} else if(salPref.answer.text === "8,000 - 10,000 per month"){
prefSalaryRange = {
min : 8000,
max : 10000
};
} else if(salPref.answer.text === "12,000 - 14,000 per month"){
prefSalaryRange = {
min : 12000,
max : 14000
};
} else if(salPref.answer.text === ">14,000 per month"){
prefSalaryRange = {
min : 14000,
max : 1000000
};
} else {
//Happy to accept salary as per my skills and qualifications
prefSalaryRange = {
min : 0,
max : 1000000
};
}
console.log("Salary data points: Job ", job.minSalary, job.maxSalary);
console.log("Salary data points: User " , prefSalaryRange.min, prefSalaryRange.max);
if((job.minSalary >= prefSalaryRange.min) && (job.maxSalary <= prefSalaryRange.max)){
return 50;
} else {
return 0;
}
} else {
return 0;
}
} else {
return 0;
}
};
var matchmakers = [
{name: 'salary Preference', filterFunc: salaryMatch},
{name: 'location', filterFunc: salaryMatch},
];
//3. Amplifiers
var behaviorCheck = function(master, job){
var genderFound = _.filter(job.gender, function (jobGender) {
return (jobGender === master.gender) ;
});
return genderFound.length;
}
var amplifiers = [
{name: 'gender', filterFunc: behaviorCheck}
];
////Unit function
//score = F1*F2*F3.....FN*Amp1*Amp2.....AmpN*(M1 + M2 + .....MN)
var GetMatchScore = function (masterAJD, job) {
console.log("=================================");
var matchScore = 0;
//Let's start with Filters
_.each(filters, function(f){
console.log("Running Filter : ", f.name);
var filterResult = f.filterFunc(masterAJD, job);
console.log("Filter Result (is it pass?): " + filterResult);
if(!filterResult){
console.log("Filter blocked : ", f.name);
matchScore = 0;
return matchScore;
}
});
//Match Makers
_.each(matchmakers, function(mm){
console.log("Running match maker : ", mm.name + " with initial Score: " + matchScore);
matchScore += mm.filterFunc(masterAJD, job);
console.log("Updated Matching Score : ", matchScore);
});
//Amplifier
_.each(amplifiers, function(amp){
console.log("Running amplifier : ", amp.name + " with initial Score: " + matchScore);
matchScore = matchScore * (amp.filterFunc(masterAJD, job));
console.log("Updated Matching Score : ", matchScore);
});
return matchScore;
};
//Library exports
var getUserJobMatchingScore = function(masterAJD, job, next){
console.log("User: " , masterAJD.userId, "Job: " , job.urlSlug);
var matchScore = GetMatchScore(masterAJD, job);
next({
urlSlug : job.jobUrlSlug,
name : job.name,
orgDisplayName : job.orgDisplayName,
matchScore : matchScore,
logoUrl : job.logoUrl,
workLocation : job.workLocation,
salaryRange : job.salaryRange
});
};
var getUserJobsMatchingScore = function(masterAJD, jobs, next){
console.log("User: " , masterAJD.userId, "Jobs count: ", jobs.length);
var jobsPayload = [];
_.each(jobs, function(item){
var matchScore = GetMatchScore(masterAJD, item);
jobsPayload.push({
urlSlug : item.jobUrlSlug,
name : item.name,
orgDisplayName : item.orgDisplayName,
matchScore : matchScore,
logoUrl : item.logoUrl,
workLocation : item.workLocation,
salaryRange : item.salaryRange
})
});
next(null, jobsPayload);
}
var getUsersJobMatchingScore = function(masterAJDs, Job, next){
console.log("Users count: ", masterAJDs.length, "Job: " , Job.urlSlug);
next();
}
module.exports = {
getUserJobMatchingScore : getUserJobMatchingScore,
getUserJobsMatchingScore : getUserJobsMatchingScore,
getUsersJobMatchingScore : getUsersJobMatchingScore
}