Example #1
0
def images(employeeid):
    employee = employees.find_one({"id": int(employeeid)})
    if employee is None:
        abort(404, "Not found.")
    employee = employee["photo"]
    photoid = os.path.splitext(os.path.basename(employee))[0]
    return send_from_directory(app.config['UPLOAD_FOLDER'], photoid + '.jpg')
Example #2
0
try:
    counter = 0
    while True:
        if counter == 30:
            print('dropping previous messages')
            counter = 0
            messages.drop()

        # message = saved_messages[counter % len(saved_messages)]
        # if '_id' in message:
        # del message['_id']
#
# message['id'] = counter
        message = generate_message(counter, random.randint(0, 24999))
        messages.insert_one(message)

        # print('updated employee: ', message['from'])

        emp1 = employees.find_one({'id': message['from']})
        print('after update:', emp1)

        # socketio.emit('new_chat', message)
        print('inserted message: ', counter)

        print('---------------------------------------------------')

        counter += 1
        time.sleep(2)
except KeyboardInterrupt:
    sys.exit()
Example #3
0
def get_employee(emp_id):
    employee = employees.find_one({'id': int(emp_id)})
    if employee:
        return Response(dumps(employee), mimetype='application/json')
    else:
        abort(400, 'Employee not found')
Example #4
0
def add_message(from_employee, to_employee, text, emotion):
    sentiment = emotion['sentiment']['document']['score'],
    employee = employees.find_one({'id': from_employee})
    # anger = employee['anger']
    # disgust = employee['disgust']
    # fear = employee['fear']
    # joy = employee['joy']
    # sadness = employee['sadness']
    print('before update:', employee)

    # employees.update_one(
    # {'id': from_employee},
    # {
    # '$set': {
    # 'sentiment': emotion['sentiment']['document']['score'],
    # 'anger': 0.5 * (anger + emotion['emotion']['document']['emotion']['anger']),
    # 'disgust': 0.5 * (disgust + emotion['emotion']['document']['emotion']['disgust']),
    # 'fear': 0.5 * (fear + emotion['emotion']['document']['emotion']['fear']),
    # 'joy': 0.5 * (joy + emotion['emotion']['document']['emotion']['joy']),
    # 'sadness': 0.5 * (sadness + emotion['emotion']['document']['emotion']['sadness'])
    # }
    # }, upsert=True
    # )

    employees.update_one({'id': from_employee}, {
        '$set': {
            'sentiment': emotion['sentiment']['document']['score'],
            'anger': emotion['emotion']['document']['emotion']['anger'],
            'disgust': emotion['emotion']['document']['emotion']['disgust'],
            'fear': emotion['emotion']['document']['emotion']['fear'],
            'joy': emotion['emotion']['document']['emotion']['joy'],
            'sadness': emotion['emotion']['document']['emotion']['sadness']
        }
    },
                         upsert=True)

    employee2 = employees.find_one({'id': from_employee})
    anger = employee2['anger']
    disgust = employee2['disgust']
    fear = employee2['fear']
    sadness = employee['sadness']
    burnout_risk = 0.25 * (anger + disgust + fear + sadness)

    turnover_risk = calculate_turnover_risk(
        employees.find_one({'id': from_employee}))

    if sentiment[0] > 0 and turnover_risk > 0.5:
        turnover_risk = np.random.uniform(0, 0.2)

    employees.update_one({'id': from_employee}, {
        '$set': {
            'turnover_risk': turnover_risk,
            'burnout_risk': burnout_risk
        }
    },
                         upsert=True)
    return {
        # 'id': message_id,
        'from': from_employee,
        'to': to_employee,
        'body': text,
        'emotion': emotion,
        'created_at': datetime.now()
    }
Example #5
0
def dump_employee(employee_id):
    employee = employees.find_one({"id": employee_id})
    employee = {k: v for k, v in employee.items() if k != '_id'}

    return employee