def get(self, id: int): applicant = Applicants.query.options( orm.joinedload('job'), orm.joinedload('educations'), orm.joinedload('experiences')).filter_by( id=id).first_or_404("Upps applicant not found") if applicant.job.user.id != get_jwt_identity(): return {"message": "You can't access this applicant!"}, 400 schema_applicant = ApplicantSchema() return schema_applicant.dump(applicant), 200
def get(self, id: int): schema_job = JobSchema(exclude=("user", )) job = Jobs.query.options( orm.joinedload('applicants.educations'), orm.joinedload('applicants.experiences'), orm.joinedload('applicants.detail_score')).filter_by( id=id).first_or_404('Upps job not found') if job.user_id != get_jwt_identity(): return {"message": "You can't access this job!"}, 400 return schema_job.dump(job), 200
def get(self): data = request.args schema_search = SearchApplicantSchema() schema_search.load(data) result = Applicants.query.options( orm.joinedload('educations'), orm.joinedload('experiences'), orm.joinedload('detail_score')).join(Jobs).filter( Applicants.name.like("%" + data.get('s') + "%"), Applicants.job_id == data.get('job_id'), Jobs.user_id == get_jwt_identity()).all() schema_applicant = ApplicantSchema(many=True) return schema_applicant.dump(result), 200
def get(self): per_page = 5 page_args = request.args.get('page', default=None, type=int) q_args = request.args.get('q', default=None, type=str) if page_args: page = page_args else: page = 1 if q_args: jobs = Jobs.query.options(orm.joinedload('applicants')).filter( Jobs.title_job.like('%' + q_args + '%'), Jobs.user_id == get_jwt_identity()).order_by( Jobs.id.desc()).paginate(page, per_page, error_out=False) else: jobs = Jobs.query.options(orm.joinedload('applicants')).filter_by( user_id=get_jwt_identity()).order_by(Jobs.id.desc()).paginate( page, per_page, error_out=False) job_id = [x.id for x in jobs.items] title_jobs = [x.title_job for x in jobs.items] created_at = [ x.created_at.strftime("%-d %B %Y ~ %H.%M") for x in jobs.items ] total_candidate = [len(x.applicants) for x in jobs.items] qualify_applicant = list() for job in jobs.items: qualify = 0 for applicant in job.applicants: if applicant and applicant.qualify: qualify += 1 qualify_applicant.append(qualify) data = list() for job_id, title, date, total, qualify in zip(job_id, title_jobs, created_at, total_candidate, qualify_applicant): raw = { 'id': job_id, 'title_jobs': title, 'created_at': date, 'total_candidate': total, 'qualify_applicant': qualify } data.append(raw) result = dict(data=data, next_num=jobs.next_num, prev_num=jobs.prev_num, page=jobs.page, iter_pages=[x for x in jobs.iter_pages()]) return result, 200
def generate_join(root_model: object, includes: [str]): """Tries to implement "load"(orm.joinedload or orm.subqueryload) Tries to implement "load" from chain of relations gotten from function `parse_includes`. "Loads" can be used for queryset.options(*loads). :param root_model: instance of flask_sqlalchemy.SQLAlchemy.Model :param includes: sequence of strings :return: None or "load" """ loads = None current_model = root_model for include in includes: if not hasattr(current_model, include): break relation = getattr(current_model, include) current_model = relation.property.mapper.class_manager.class_ if loads is None: loads = orm.joinedload(relation) else: loads = loads.subqueryload(relation) return loads
def delete(self, id: int): applicant = Applicants.query.options(orm.joinedload('job')).filter_by( id=id).first_or_404("Upps applicant not found") if applicant.job.user.id != get_jwt_identity(): return {"message": "You can't access this applicant!"}, 400 applicant.delete_from_db() return {"message": "Applicant success deleted."}, 200
def post(self, job_id: int): job = Jobs.query.options(orm.joinedload('user')).filter_by( id=job_id).first_or_404('Upps job not found') if job.user_id != get_jwt_identity(): return {"message": "You can't access this job!"}, 400 data = request.get_json() args = _scrape_schema.load(data) max_url_profile = job.user.url_profile if (len(job.applicants) + len(args['url_applicants'])) > max_url_profile: return { "message": f"Upss you can't scrape applicant greater than {max_url_profile}, please upgrade your account." }, 400 applicants = ProfileLinkedin(args['url_applicants']) if not applicants.valid_url: return { "message": "Upss only profile LinkedIn you can provide." }, 400 if not applicants.valid_scrape_url: return {"message": "Upps invalid url profile LinkedIn."}, 400 data = applicants.get_content() # save to db for raw in data: raw_applicants = dict() raw_experiences = dict() raw_educations = dict() for key, value in raw.items(): if key != "experiences" and key != "educations": raw_applicants[key] = value if key == "experiences": raw_experiences = value.values() if key == "educations": raw_educations = value.values() raw_applicants['languages'] = ','.join(raw_applicants['languages']) raw_applicants['licenses'] = ','.join(raw_applicants['licenses']) raw_applicants['skills'] = ','.join(raw_applicants['skills']) raw_applicants['honors'] = ','.join(raw_applicants['honors']) # save applicants applicant = Applicants(**raw_applicants, job_id=job.id) applicant.save_to_db() for exp in raw_experiences: # save experiences experience = Experiences(**exp, applicant_id=applicant.id) experience.save_to_db() for edu in raw_educations: # save educations education = Educations(**edu, applicant_id=applicant.id) education.save_to_db() return {"message": "Applicants successfully added."}, 201
def put(self, id: int): applicant = Applicants.query.options(orm.joinedload('job')).filter_by( id=id).first_or_404("Upps applicant not found") if applicant.job.user.id != get_jwt_identity(): return {"message": "You can't access this applicant!"}, 400 if not applicant.qualify: applicant.qualify = True message = "Applicant updated to qualify" else: applicant.qualify = False message = "Applicant updated to not qualify" applicant.save_to_db() return {"message": message}, 200
def put(self, job_id: int): score = OverallScore.query.options(orm.joinedload('job')).filter_by( job_id=job_id).first_or_404("Upps score not found") if score.job.user_id != get_jwt_identity(): return {"message": "You can't access this score!"}, 400 schema_score = OverallScoreSchema() data = request.get_json() args = schema_score.load(data) count = sum([x for x in args.values() if type(x) != str]) if count != 100: return {"message": "The calculation results must all be 100%"}, 400 score.update_score(**args) score.save_to_db() return {"message": "Overall score has been update."}, 200
def post(self): data = request.get_json() args = _scrape_schema.load(data) job = ScrapingJobs(args['url_job']) if not job.valid_url: return {"message": "Upss job portal not registerd yet."}, 400 if not job.valid_scrape_url: return {"message": "Upps invalid url job portal."}, 400 user = Users.query.options(orm.joinedload('jobs')).get( get_jwt_identity()) if len(user.jobs) >= user.url_job: return { "message": f"Upss you can't scrape job greater than {user.url_job}, please upgrade your account." }, 400 data = job.get_content() jobs = Jobs(**data, user_id=user.id, url=args['url_job']) jobs.save_to_db() score = OverallScore(job_id=jobs.id) score.save_to_db() return {"message": "Job successfully added."}, 201
def get(self, job_id: int): job = Jobs.query.filter_by( id=job_id).first_or_404("Upps job not found!") if job.user_id != get_jwt_identity(): return {"message": "You can't access this job!"}, 400 if not job.keywords and not job.concepts: return {"message": "Job doesn't have keywords and concepts!"}, 400 applicants = Applicants.query.options( orm.joinedload('educations'), orm.joinedload('experiences')).filter_by(job_id=job.id).all() if len(applicants) == 0: return {"message": "Upss this job does not have an applicant"}, 400 overall_score = job.overall_score for applicant in applicants: # check if applicant not have score yet. if not applicant.score: current_job = applicant.current_job license = applicant.licenses skill = applicant.skills honor = applicant.honors educations = [] experiences = [] for education in applicant.educations: if education.study: educations.append(education.study) for experience in applicant.experiences: if experience.job: experiences.append(experience.job) # calculation current position if current_job: raw_current_job = MatchCalculation.calculation( current_job, job.title_job) calc_current_job = ( raw_current_job * overall_score.score_current_position) / 100 else: calc_current_job = 0 # calculation experience if experiences: experiences = ','.join(experiences) raw_experience = MatchCalculation.calculation(experiences, job.concepts, num_100=True) calc_experience = (raw_experience * overall_score.score_experience) / 100 else: calc_experience = 0 # calculation skill if skill: raw_skill = MatchCalculation.calculation(skill, job.keywords, num_100=True) calc_skill = (raw_skill * overall_score.score_skill) / 100 else: calc_skill = 0 # calculation education if educations: educations = ','.join(educations) raw_education = MatchCalculation.calculation(educations, job.concepts, num_100=True) calc_education = (raw_education * overall_score.score_education) / 100 else: calc_education = 0 # calculation license if license: raw_license = MatchCalculation.calculation(license, job.concepts, num_100=True) calc_license = (raw_license * overall_score.score_license) / 100 else: calc_license = 0 # calculation honor if honor: score_honor = overall_score.score_honor length = len(honor.split(',')) if length >= 13: calc_honor = score_honor / 1 elif length >= 8: calc_honor = score_honor / 2 elif length >= 3: calc_honor = score_honor / 3 else: calc_honor = 0 hasil = calc_current_job + calc_experience + calc_skill + calc_education + calc_license + calc_honor applicant.score = round(hasil, 2) applicant.save_to_db() detail_score = DetailScore(calc_experience, calc_current_job, calc_skill, calc_education, calc_license, calc_honor, applicant.id) detail_score.save_to_db() return {"message": "All applicant has been scored"}, 200
def get(self): jobs = Jobs.query.options( orm.joinedload('applicants'), orm.joinedload('applicants.experiences')).filter_by( user_id=get_jwt_identity()).all() # for header dashboard total_applicant = 0 published_job = len(jobs) qualify_applicant = 0 disqualify_applicant = 0 for job in jobs: total_applicant += len(job.applicants) for applicant in job.applicants: if applicant.qualify: qualify_applicant += 1 else: disqualify_applicant += 1 # for chart dashboard 1 month jobs_one_month = Jobs.query.filter( Jobs.user_id == get_jwt_identity(), extract('month', Jobs.created_at) == datetime.now().month).all() job_summary = list() applicant_summary = list() applicant_work = list() for job in jobs_one_month: # chart dashboard job_summary.append(job.title_job) applicant_summary.append(len(job.applicants)) for applicant in job.applicants: # get applicant experience length_work = list() for exp in applicant.experiences: length_work.append(exp.date_employed) # calculate length work try: start_work = int(length_work[-1].split(' ')[0]) except Exception: start_work = int(length_work[-1].split(' ')[1]) total_work = int(datetime.now().strftime('%Y')) - start_work applicant_work.append(total_work) result = dict(total_applicant=total_applicant, published_job=published_job, qualify_applicant=qualify_applicant, disqualify_applicant=disqualify_applicant, job_summary=dict(zip(job_summary, applicant_summary)), length_of_work={ '< 1 years': len([x for x in applicant_work if x == 0]), '1 - 3 years': len([x for x in applicant_work if x >= 1 and x <= 3]), '3 - 5 years': len([x for x in applicant_work if x >= 3 and x <= 5]), '> 5 years': len([x for x in applicant_work if x > 5]) }) return result, 200
def get(self): _user_schema = UserSchema(exclude=("password", )) user = Users.query.options(orm.joinedload('jobs')).get( get_jwt_identity()) return _user_schema.dump(user), 200