Esempio n. 1
0
def company_average_salary(request, responder):
    create_feedback_file('company_name',request)
    company_name = request.frame.get('company_name')
    year = request.frame.get('year')

    for i in request.entities:
        if i['type'] == 'company_name':
            company_name = i['value'][0]['cname']
        elif i['type'] == 'sys_time':
            year = i['value'][0]['value'][0:4]

    responder.frame['desired_action'] = "average_salary"

    if company_name and year:
        handle_salary(company_name, year, "average", responder)
    elif company_name:
        responder.frame['company_name'] = company_name

        responder.reply("Which year's average salary would you like to know?")
        responder.listen()
    else:
        responder.frame['year'] = year

        responder.reply(
            "Sure, which company's average salary would you like to know?")
        responder.listen()
Esempio n. 2
0
def list_companies(request, responder):
    create_feedback_file('placement_info',request)
    asked_year = None

    for i in request.entities:
        if i['type'] == 'sys_time':
            asked_year = i['value'][0]['value'][0:4]
            break
    companies = qa.get(index='companies')
    if asked_year == None:
        company_names = [i['name'] for i in companies]
    else:
        responder.frame['year'] = asked_year
        company_names = [i['name']
                         for i in companies if asked_year in i['data']]

    if len(company_names) == 0:
        reply = "No companies came for placements"
        if asked_year != None:
            reply += " in " + asked_year
    else:
        reply = "The companies which came for placements"
        if asked_year != None:
            reply += " in " + asked_year
        reply += " are\n" + "\n".join(company_names)

    responder.reply(reply)
Esempio n. 3
0
def lower_salary_companies(request, responder):
    create_feedback_file('placement_info', request)
    year, *_ = extract_entities(request)

    salary = next((i['value'][0]['value']
                   for i in request.entities if i['type'] == 'sys_number'),
                  None)

    responder.frame.pop('year', None)

    companies = qa.get(index='companies', size=100)
    count = 0

    if year:
        for i in companies:
            if year in i['data']:
                if salary > i['data'][year]['salary']:
                    count += 1
    else:
        for i in companies:
            for k in i['data']:
                if salary > i['data'][k]['salary']:
                    count += 1
                    break

    reply = "A total of %s " % (count)
    if count == 1:
        reply += "company"
    else:
        reply += "companies"
    reply += " gave a salary lower than %s lpa" % (salary)
    if year:
        reply += " in the year %s" % (year)
    responder.reply(reply)
Esempio n. 4
0
def company_last_year(request, responder):
    create_feedback_file('company_info', request)
    _, company_name, dept_name = extract_entities(request)

    responder.frame['desired_action'] = "last_recruitment"

    if company_name:
        handle_last_recruitment(company_name, dept_name, responder)
    else:
        responder.reply(
            "Sure, which company's last recruitment would you like to know?")
        responder.listen()
Esempio n. 5
0
def welcome(request, responder):
    create_feedback_file('greeting', request)
    try:
        # Get user's name from session information in a request to personalize the greeting.
        responder.slots['name'] = request.context['name']
        prefix = "Hello {name}, "
    except KeyError:
        prefix = 'Hello, '

    welcome_msg = ("I am your placement info assistant. You can ask questions "
                   "related to campus placements.")

    responder.reply(prefix + welcome_msg)
Esempio n. 6
0
def company_last_year(request, responder):
    create_feedback_file('company_info',request)
    company_name = request.frame.get('company_name')

    company_name = next((e['value'][0]['cname']
                         for e in request.entities if e['type'] == 'company_name'), company_name)

    responder.frame['desired_action'] = "last_recruitment"

    if company_name:
        handle_last_recruitment(company_name, responder)
    else:
        responder.reply(
            "Sure, which company's last recruitment would you like to know?")
        responder.listen()
Esempio n. 7
0
def company_salary(request, responder):
    create_feedback_file('company_info', request)
    year, company_name, _ = extract_entities(request)

    responder.frame['desired_action'] = 'salary'

    if company_name and year:
        handle_salary(company_name, year, responder)
    elif company_name:
        responder.frame['company_name'] = company_name

        responder.reply("Which year's salary would you like to know?")
        responder.listen()
    else:
        responder.frame['year'] = year

        responder.reply("Sure, which company's salary would you like to know?")
        responder.listen()
Esempio n. 8
0
def specify_year(request, responder):
    create_feedback_file('helpers',request)
    company_name = request.frame.get('company_name')
    year = next((e['value'][0]['value'][0:4]
                 for e in request.entities if e['type'] == 'sys_time'), None)

    if company_name:
        try:
            if request.frame['desired_action'] == "highest_salary":
                handle_salary(company_name, year, "highest", responder)
            elif request.frame['desired_action'] == "lowest_salary":
                handle_salary(company_name, year, "lowest", responder)
            elif request.frame['desired_action'] == "average_salary":
                handle_salary(company_name, year, "average", responder)
        except KeyError:
            print("Please specify some action")
    else:
        responder.reply(
            "Not sure which company you meant there. Can you please try again?")
Esempio n. 9
0
def count_companies(request, responder):
    create_feedback_file('placement_info', request)
    year, *_ = extract_entities(request)

    responder.frame.pop('year', None)

    companies = qa.get(index='companies', size=100)
    count = 0

    for i in companies:
        if year in i['data']:
            count += 1

    reply = "A total of "
    if year != None:
        reply += "%s companies visited in %s." % (count, year)
    else:
        reply += "%s companies have visited till now." % (len(companies))

    responder.reply(reply)
Esempio n. 10
0
def specify_entity(request, responder):
    create_feedback_file('helpers', request)
    year, company_name, dept_name = extract_entities(request)

    if company_name:
        try:
            if request.frame['desired_action'] == "last_recruitment":
                handle_last_recruitment(company_name, dept_name, responder)
            elif request.frame['desired_action'] == "salary":
                handle_salary(company_name, year, responder)
            elif request.frame['desired_action'] == 'total_recruits':
                if dept_name:
                    handle_total_recruits(company_name, year, dept_name,
                                          responder)
                else:
                    handle_total_recruits(company_name, year, 'all', responder)

        except KeyError:
            responder.reply("Please specify some action")
    else:
        responder.reply(
            "Not sure which company you meant there. Can you please try again?"
        )
Esempio n. 11
0
def company_total_recruits(request, responder):
    create_feedback_file('company_info', request)
    year, company_name, dept_name = extract_entities(request)

    responder.frame['desired_action'] = 'total_recruits'

    if dept_name:
        category = dept_name
    else:
        category = 'all'

    if company_name and year:
        handle_total_recruits(company_name, year, category, responder)
    elif company_name:
        responder.frame['company_name'] = company_name

        responder.reply("Which year's total recruits would you like to know?")
        responder.listen()
    else:
        responder.frame['year'] = year

        responder.reply(
            "Sure, which company's total recruits would you like to know?")
        responder.listen()
Esempio n. 12
0
def unknown(request, responder):
    create_feedback_file('unsupported', request)
    responder.reply('Not sure what you meant there...')
Esempio n. 13
0
def list_companies(request, responder):
    create_feedback_file('placement_info', request)
    year, *_ = extract_entities(request)
    handle_companies_list("some", year, responder)