public async Task <IHttpActionResult> Post(JobMatchForm form) { //var jobMatches = from jv in _dbContext.JobVacancies // join jvs in _dbContext.JobVacancySkills on jv.Id equals jvs.JobVancancyId // where jv.Isco == form.Isco // //group jvs by jvs.JobVancancyId into grouped // //select new { Id = grouped.Key, Skills = j.ToList(), Count = j. }; // select new {jv.Title, jv.Description, jv.Isco, jvs.SkillId, jv.Id }; //var result = await jobMatches.ToListAsync(); //result.GroupBy(x => new {x.Id, x.Title, x.Description}).Select(x => new JobMatch(){Id = x.Key.Id, Title = x.Key.Title, Description = x.Key.Description, Skills = x.}) var result = await _dbContext.JobVacancies.Include(x => x.JobVacancySkills).Where(x => x.Isco == form.Isco).ToListAsync(); var matches = new List <JobMatch>(); foreach (var job in result) { double percentage = (double)job.JobVacancySkills.Count(x => form.Skills.Contains(x.SkillId)) / (double)job.JobVacancySkills.Count; var match = new JobMatch() { Title = job.Title, Description = job.Description, Id = job.Id, MatchPercentage = (int)Math.Round(percentage * 100) }; matches.Add(match); } return(Ok(matches.OrderByDescending(x => x.MatchPercentage))); }
public static async Task AddJobMatchAsync(JobMatch jm) { var client = new HttpClient(); var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/AddJobMatch"; byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jm)); string msj = string.Empty; using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(uri, content); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); } else { msj = "Ocurrio un error al agregar la vacante"; } } }
/// <summary> /// Finding a most qualified candidate for a job /// </summary> /// <returns>Return a list of jobs with most qualified candidates </returns> public async Task <List <Job> > JobMatchAsync(List <Job> Jobs, List <Candidate> Candidates) { List <JobMatch> JobMatches = new List <JobMatch>(); List <Candidate> matchedCandidates = new List <Candidate>(); //STEP 1: GO THROUGH ALL JOBS AND CANDIDATES LIST foreach (var job in Jobs) { JobMatch jobMatch = new JobMatch(); foreach (var candidate in Candidates) { var CommonList = job.skills.Split(',').Select(s => s.Trim()).Intersect(candidate.SkillTags.Split(',').Select(s => s.Trim())); if (CommonList.Count() > 0) { candidate.NumberMatchedSkills = CommonList.Count(); matchedCandidates.Add(candidate); } } //STEP 2: TAKING ALL CANDIDATES WITH SKILLS WHICH MATCHED JOB SKILLS matchedCandidates = matchedCandidates.Where(c => c.NumberMatchedSkills == matchedCandidates.Max(m => m.NumberMatchedSkills)).ToList(); //STEP 3: FIDING THE STAFF WITH THE MOST RELEVANT SKILLS FOR THE JOB BY USING INDEX TO DETERMINE MOST RELEVANT SKILLS int SmallestTotalIndex = 0; int TotalIndex = 0; foreach (var candidate in matchedCandidates) { var jobSkillList = job.skills.Split(',').Select(s => s.Trim()).ToList <string>(); foreach (var skill in candidate.SkillTags.Split(',').Select(s => s.Trim()).ToList <string>()) { int indexSkill = jobSkillList.IndexOf(skill); if (indexSkill > 0) { TotalIndex = TotalIndex + indexSkill; } } if (TotalIndex < SmallestTotalIndex || SmallestTotalIndex == 0) { SmallestTotalIndex = TotalIndex; job.qualifiedCandidate = candidate; } TotalIndex = 0; } //RESET SmallestTotalIndex = 0; matchedCandidates.Clear(); } return(await Task.FromResult <List <Job> >(Jobs)); }