Example #1
0
def matches(new_user):
    #find mentor
    if new_user['is_mentee']:
        mentor_ranking = []
        all_mentors = session.query(Users).filter(Users.is_mentor == True).all()
        #print(all_mentors)

        for mentor in all_mentors:
            cur_mentor = session.query(MentorSurvey).filter(
                MentorSurvey.user_id == mentor.employee_id).first()

            score = 0
            if new_user['location'] == cur_mentor.location:
                score += 1
            if new_user['cpa'] == cur_mentor.cpa:
                score += 1
            if new_user['leadership_skills'] == cur_mentor.leadership_skills:
                score += 1
            if new_user['life_at_nike'] == cur_mentor.life_at_nike:
                score += 1
            if new_user['education_advice'] == cur_mentor.education_advice:
                score += 1
            if new_user['finance'] == cur_mentor.finance:
                score += 1

            mentor_ranking.append((mentor.employee_id, score))

            mentor_ranking.sort(key=lambda tup:tup[1])
        return mentor_ranking

    #find mentee
    if new_user['is_mentor']:
        mentee_ranking = []
        all_mentees = session.query(Users).filter(Users.is_mentee == True).all()

        for mentees in all_mentees:
            cur_mentee = session.query(MenteeSurvey).filter(
                MenteeSurvey.user_id == mentee.employee_id).first()

            score = 0
            if new_user['location'] == cur_mentee.location:
                score += 1
            if new_user['cpa'] == cur_mentee.cpa:
                score += 1
            if new_user['leadership_skills'] == cur_mentee.leadership_skills:
                score += 1
            if new_user['life_at_nike'] == cur_mentee.life_at_nike:
                score += 1
            if new_user['education_advice'] == cur_mentee.education_advice:
                score += 1
            if new_user['finance'] == cur_mentee.finance:
                score += 1

            mentee_ranking.append((mentee.employee_id, score))
            mentee__ranking.sort(key=lambda tup:tup[1])

        return mentee__ranking
Example #2
0
def get_user(employee_id):
    """Return user with the same id"""

    temp = session.query(Users).filter(Users.employee_id == employee_id).first()

    if temp is None:
        return "No employee with that id found", 400

    results = {
        'Email': temp.email,
        'Password': temp.password,
        'First Name': temp.fname,
        'Last Name': temp.lname,
        'Job Title': temp.job_title,
        'Department': temp.department,
        'Employee Networks': temp.employee_network,
        'url': temp.profile_pic
    }
    if temp.is_mentee and not temp.is_mentor:
        results['Role'] = 'Mentee'
    elif not temp.is_mentee and temp.is_mentor:
        results['Role'] = 'Mentor'
    else:
        results['Role'] = 'Both'

    return jsonify(results)
Example #3
0
def get_all_mentees():
    """Return all users who are mentees"""

    mentee_objects = session.query(Users).filter(Users.is_mentee == True).all()
    schema = UserSchema(many=True)
    mentees = schema.dump(mentee_objects)

    return jsonify(mentees.data)
Example #4
0
def create_test_db():
    """Populate empty database with entries"""
    for entry in users_list:
        #Populate users table
        new_user = Users(
            entry['fname'], entry['lname'], entry['employee_id'], entry['is_mentor'],
            entry['is_mentee'], entry['password'], entry['email'],
            entry['job_title'], entry['department'], entry['bio'],
            entry['employee_network'], entry['num_to_mentor'], entry['url']
        )

        session.add(new_user)

        #populate mentor survey table
        if entry['is_mentor'] == True:
            mentor_survey = MentorSurvey(
                entry['employee_id'], entry['location'], entry['cpa'],
                entry['leadership_skills'], entry['life_at_nike'],
                entry['education_advice'], entry['finance']
            )

            session.add(mentor_survey)

        #populate mentee survey table
        if entry['is_mentee'] == True:
            mentee_survey = MenteeSurvey(
                entry['employee_id'], entry['location'], entry['cpa'],
                entry['leadership_skills'], entry['life_at_nike'],
                entry['education_advice'], entry['finance']
            )

            session.add(mentee_survey)

    results = session.query(Users).all()
    if len(results) == 8:
        print("Successfully added dummy values to data")
    else:
        print(f"Error only had {len(results)} entries in database")

    #TODO Populate Relationship Table

    session.commit()
Example #5
0
def add_user():
    """Given user info, add to database"""
    entry = json.loads(request.data)

    new_user = Users(
            entry['fname'], entry['lname'], entry['employee_id'],
            entry['is_mentor'], entry['is_mentee'], entry['password'],
            entry['email'], entry['job_title'], entry['department'],
            entry['bio'], entry['employee_network'], entry['num_to_mentor'],
            entry['url']
    )
    session.add(new_user)

    #populate mentor survey table
    if entry['is_mentor'] == True:
        mentor_survey = MentorSurvey(
            entry['employee_id'], entry['location'], entry['cpa'],
            entry['leadership_skills'], entry['life_at_nike'],
            entry['education_advice'], entry['finance']
        )

        session.add(mentor_survey)

    #populate mentee survey table
    if entry['is_mentee'] == True:
        mentee_survey = MenteeSurvey(
            entry['employee_id'], entry['location'], entry['cpa'],
            entry['leadership_skills'], entry['life_at_nike'],
            entry['education_advice'], entry['finance']
        )

        session.add(mentee_survey)

    ranked = matches(entry)

    session.commit()

    profile_list = []
    for prof in ranked:
        temp = session.query(Users).filter(Users.employee_id == prof[0]).first()
        schema = UserSchema(many=False)
        results = {
            'Email': temp.email,
            'Password': temp.password,
            'First Name': temp.fname,
            'Last Name': temp.lname,
            'Job Title': temp.job_title,
            'Department': temp.department,
            'Employee Networks': temp.employee_network,
            'url': temp.profile_pic
        }
        if temp.is_mentee and not temp.is_mentor:
            results['Role'] = 'Mentee'
        elif not temp.is_mentee and temp.is_mentor:
            results['Role'] = 'Mentor'
        else:
            results['Role'] = 'Both'
        profile_list.append(schema.dump(temp))

    print(profile_list)

    return jsonify(profile_list)
Example #6
0
# coding=utf-8

from app import app
from flask import request, jsonify
from models import Users, UserSchema, MenteeSurvey, MentorSurvey
from entity import session
from app.utilities import create_test_db, matches

import json

#Check if database exist and is populated, else populate
testing = session.query(Users).all()
if len(testing) == 0:
    create_test_db()

@app.route('/')
def index():
    return "Hello World!"

@app.route('/user/<int:employee_id>')
def get_user(employee_id):
    """Return user with the same id"""

    temp = session.query(Users).filter(Users.employee_id == employee_id).first()

    if temp is None:
        return "No employee with that id found", 400

    results = {
        'Email': temp.email,
        'Password': temp.password,