public bool CurrentCandidateIsBetterThanNextOne(ICandidate current, ICandidate next, IJobRelevantSkills jobRequiredSkill) { foreach (var skill in jobRequiredSkill.NormalizedSkillSet.OrderByDescending(s => s.Value).Select(s => s.Key).ToList()) { if (current.skillSet.ContainsKey(skill) && next.skillSet.ContainsKey(skill)) { // 1 is strongest n is weakest, current one may have stronger skil of what job required if (current.skillSet[skill] < next.skillSet[skill]) { return(true); } else { return(false); } } else if (current.skillSet.ContainsKey(skill) && !next.skillSet.ContainsKey(skill)) { return(true); // current one is better than next one , ready to re-order } else if (!current.skillSet.ContainsKey(skill) && next.skillSet.ContainsKey(skill)) { return(false); // next one is better . no need to re-order } } return(false); }
public List <ICandidate> DeepSortCandidates(List <ICandidate> deepSortedCandidates, IJobRelevantSkills jobRequiredSkill) { //var deepSortedCandidates = candidateWithSkillmatch.OrderBy(cs => cs.score).ToList(); var swapped = false; // start from most irrelevent candidate, if next is not as good as current, swap for (var i = 0; i < deepSortedCandidates.Count(); i++) { if (i < deepSortedCandidates.Count() - 1 && deepSortedCandidates[i].score == deepSortedCandidates[i + 1].score && CurrentCandidateIsBetterThanNextOne(deepSortedCandidates[i], deepSortedCandidates[i + 1], jobRequiredSkill)) { deepSortedCandidates.Swap(i, i + 1); swapped = true; } } if (swapped) { deepSortedCandidates = DeepSortCandidates(deepSortedCandidates, jobRequiredSkill); } return(deepSortedCandidates); }