def description(): user_id = current_user.id details = Test6.query.join(User6).filter(User6.id == user_id).all() if details: skills = details[0].mentorskills preference = details[0].preference if preference == "In Person": location = details[0].location else: location = '' else: skills = '' location = None skills_list = clean_user_input.main(skills) loc_list = clean_user_input.main(location) # TODO: Note that details[0] will only select the first entry from db corresponding to that user # TODO: Handle it such that test database has only 1 entry per user page, per_page, offset = get_page_args(page_parameter='page', per_page_parameter='per_page') # all_matched_mentors = match_mentors.main(skills_list, loc_list) # final_top_mentors = match_mentors.main(skills_list, loc_list) if loc_list and len(loc_list) > 0: loc_list, not_loc_list = match_mentors.main(skills_list, loc_list) final_top_mentors = prioritize_women_mentors(loc_list=loc_list, no_loc_list=not_loc_list) else: all_matched_mentors = match_mentors.main(skills_list, loc_list) final_top_mentors = prioritize_women_mentors(loc_list=all_matched_mentors, no_loc_list=None) if len(final_top_mentors) == 0: # no matches found # all_matched_mentors flash('No mentors found, try searching another skill', 'danger') return redirect(url_for('settings')) pagination_users = final_top_mentors[offset: offset + per_page] pagination = Pagination(page=page, per_page=per_page, total=len(final_top_mentors), record_name='final_top_mentors', css_framework='bootstrap4') return render_template("result.html", pagination_users=pagination_users, page=page, per_page=per_page, pagination=pagination)
def test_if_query_not_present_in_file(self): """ To test how the algorithm works when the query is not found in the file :return: True/False """ q = "java" q_list = clean_user_input.main(q) results = match_mentors.main(skills_query=q_list, filename="unittest.json") self.assertEqual(len(results), 0)
def test_if_query_empty(self): """ To test how the algorithm works when the empty query is passed :return: True/False """ q = "" q_list = clean_user_input.main(q) results = match_mentors.main(skills_query=q_list, filename="unittest.json") self.assertEqual(len(results), 3)
def test_recommendation(self): """ To test how the algorithm works when the query match is found :return: True/False """ q = "polyglot software developer" q_list = clean_user_input.main(q) results = match_mentors.main(skills_query=q_list, filename="unittest.json") print(results) self.assertEqual(len(results), 2) self.assertEqual(results[0]['id'], 2240) self.assertEqual(results[1]['id'], 15667722)
def test_wild_characters(self): """ To test how the algorithm works when the query has various wild characters :return: True/False """ q = "polyglot$software,.*developer" q_list = clean_user_input.main(q) print('q_list', q_list) results = match_mentors.main(skills_query=q_list, filename="unittest.json") print(results) self.assertEqual(len(results), 2) self.assertEqual(results[0]['id'], 2240) self.assertEqual(results[1]['id'], 15667722)
def search(): query = request.args.get('query') query = clean_user_input.main(query) # Clean up query here. Remove punctuations. return render_template('search_mentors.html', title='Search Mentors', query=query)