def match_candidate(jobseekerID): try: jobseeker = JobSeeker.objects.get(id=jobseekerID) skills = list(itertools.chain(*jobseeker.jobseekerskill_set.all().values_list('skill__name'))) candidate = {'name': jobseeker.user.get_full_name(), 'skills': skills, 'years': int(jobseeker.years_of_experience)} # For new candidates, do a match for jobs added in the last 30 days only date = timezone.now() - timedelta(days=30) jobs = Job.objects.filter(category=jobseeker.category, created_at__gte=date) for job in jobs: required_skills = list(itertools.chain( *job.requiredjobskill_set.values_list('skill__name'))) optional_skills = list(itertools.chain( *job.optionaljobskill_set.values_list('skill__name'))) requirements = {'years': int(job.years_of_experience), 'skills': required_skills, 'optional': optional_skills} matched, score, weight = matcher(requirements, candidate) if matched: try: jobmatch = JobMatch(job=job, seeker=jobseeker, score=score, weight=weight) jobmatch.save() except IntegrityError, e: # Match already exists logging.exception(e) pass except Exception, e: logging.exception(e) return False
def match_job(jobID): try: job = Job.objects.get(id=jobID) required_skills = list(itertools.chain(*job.requiredjobskill_set.values_list('skill__name'))) optional_skills = list(itertools.chain(*job.optionaljobskill_set.values_list('skill__name'))) requirements = {'years': int(job.years_of_experience), 'skills': required_skills, 'optional': optional_skills} candidates = JobSeeker.objects.filter(category=job.category) for jobseeker in candidates: skills = list(itertools.chain(*JobSeekerSkill.objects.filter( seeker=jobseeker).values_list('skill__name'))) candidate = {'name': jobseeker.user.get_full_name(), 'skills': skills, 'years': int(jobseeker.years_of_experience)} matched, score, weight = matcher(requirements, candidate) if matched: try: jobmatch = JobMatch(job=job, seeker=jobseeker, score=score, weight=weight) jobmatch.save() except IntegrityError, e: # Match already exists logging.exception(e) pass except Exception, e: logging.exception(e) return False
def run_matches(): print("Calculating optimal matches...") open_jobs = JobOpening.objects(closed=False) for job in open_jobs: if not JobMatch.objects(job_id=job.job_id): print(f'Calculating match for {job.job_id}') create_match_object(job.job_id) else: print(f'Skipping {job.job_id} already exists')
def create_match_object(job_id): print('create match object') match = JobMatch(job_id=job_id, status='processing') match.save() match_scores = get_match_scores(job_id) scores_list = json.loads(match_scores.T.to_json()).values() try: connect_db() match = JobMatch.objects.get(job_id=job_id) match.update(scores=list(scores_list), status='complete') print('match updated') except Exception as e: print("error: ", e) finally: disconnect_db()