Esempio n. 1
0
def deleteentry():
    '''
    Delete an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num = request.form['num']
        # PDelete the record from mongo database
        try:
            Database.objects(num=num).delete()
        except:
            eorror = "ERR-004 Failed to delete log entry"
            return render_template('sidekick/dberror.html', error=error)

        #send delete success
        return render_template('sidekick/crud-deleteentry.html')

    # Build list of projects in database and send to selector form

    # Get user
    user = Sidekick.objects.first()
    user = user.user.encode('utf-8')

    entries = []
    for e in Database.objects():
        if e.user == user:
            entries.append(e.num)
    return render_template('sidekick/crud-deleteselect.html', entries=entries)
Esempio n. 2
0
def editentry():
    '''
    Edit an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num = request.form['num']
        # PDelete the record from mongo database
        entry = Database.objects(num=num)

        # create list from database entry
        stamp = {
            "num": entry[0].num,
            "now": entry[0].now,
            "user": entry[0].user,
            "message": entry[0].message,
            "concern": entry[0].concern
        }

        #send form with info list
        return render_template('sidekick/crud-editentry.html', stamp=stamp)

    # Get user
    user = Sidekick.objects.first()
    user = user.user.encode('utf-8')

    entries = []
    for e in Database.objects():
        if e.user == user:
            entries.append(e.num)
    return render_template('sidekick/crud-editselect.html', entries=entries)
Esempio n. 3
0
def deleteentry():
    '''
    Delete an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num = request.form['num']
        # PDelete the record from mongo database
        try:
            Database.objects(num=num).delete()
        except:

            return render_template('engineers/dberror4.html')

        #send delete success
        return render_template('engineers/deleteentry.html')

    # Build list of projects in database and send to selector form

    # Get sa
    sa_list= []
    for sa in Temp.objects():
        sa_list.append(sa.sa)
    sa = sa_list[0]
    sa = sa.encode('utf-8')
    sa=sa.replace(" ", "-")

    entries = []
    for e in Database.objects():
        if e.sa == sa:
            entries.append(e.num)
    return render_template('engineers/entryeditdelete.html', entries=entries)
Esempio n. 4
0
def upentry():
    '''
    Saves the edited record

    '''
    # Get desired project
    num = request.form['num']
    now = request.form['now']
    sa = request.form['sa']
    message = request.form['message']
    concern = request.form['concern']

    now = now.encode('utf-8')
    sa = sa.encode('utf-8')
    message = message.encode('utf-8')
    concern = concern.encode('utf-8')
    num = int(num)

    # Save the number record for the next use

    try:
        Database.objects(num=num).update(message=message,concern=concern)
    except:
        return render_template('engineers/dberror2.html')

    #send delete success
    return render_template('engineers/goodeditentry.html')
Esempio n. 5
0
def editentry():
    '''
    Edit an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num = request.form['num']
        # PDelete the record from mongo database
        entry = Database.objects(num=num)

        # create list from database entry
        more = {
                "num" : entry[0].num,
                "now" : entry[0].now,
                "sa" : entry[0].sa,
                "message" : entry[0].message,
                "concern" : entry[0].concern
                }
        # rick.append('fail')
        #send form with info list
        return render_template('engineers/editentry.html', more=more)
    # Get sa
    sa_list= []
    for sa in Temp.objects():
        sa_list.append(sa.sa)
    sa = sa_list[0]
    sa = sa.encode('utf-8')
    sa=sa.replace(" ", "-")

    entries = []
    for e in Database.objects():
        if e.sa == sa:
            entries.append(e.num)
    return render_template('engineers/entryeditselect.html', entries=entries)
Esempio n. 6
0
def upentry():
    '''
    Saves the edited record

    '''
    # Get desired project
    num = request.form['num']
    now = request.form['now']
    user = request.form['user']
    message = request.form['message']
    concern = request.form['concern']

    now = now.encode('utf-8')
    user = user.encode('utf-8')
    message = message.encode('utf-8')
    concern = concern.encode('utf-8')
    num = int(num)

    # Save the number record for the next use

    try:
        Database.objects(num=num).update(message=message, concern=concern)
    except:
        error = "ERR005 - Failed to update edited log entry"
        return render_template('sidekick/dberror.html')

    #send delete success
    return render_template('sidekick/crud-goodeditentry.html')
Esempio n. 7
0
def test_predict_mood():
    # load the saved model (after training)
    model = pickle.load(open("audio/result/mlp_classifier.model", "rb"))
    # extract features and reshape it (change actor to test different moods)
    filename = \
        "C:/Users/Ian/Documents/GitHub/EmotionDetection/EmotionDetection/Dataset/Actor_24/03-01-01-01-02-02-24.wav"
    features = extract_feature(filename, mfcc=True, chroma=True,
                               mel=True).reshape(1, -1)
    # predict
    result = model.predict(features)[0]
    # show the result !
    print("result:", result)
    Database.createMood(result)
    return result
Esempio n. 8
0
def upclone():
    '''
    Saves the cloned record

    '''
    # Get desired project
    num = request.form['num']
    now = request.form['now']
    user = request.form['user']
    message = request.form['message']
    concern = request.form['concern']

    now = now.encode('utf-8')
    user = user.encode('utf-8')
    message = message.encode('utf-8')
    concern = concern.encode('utf-8')
    num = int(num)
    #
    # Build record to write to mongo database

    entry = Database(user=user,
                     message=message,
                     concern=concern,
                     now=now,
                     num=num)

    # Save the record
    try:
        entry.save()
    except:
        error = "Clone save issues"
        return render_template('sidekick/dberror.html', error=error)

    # Increment number for next use
    num = num + 1

    # Clear temp database for a new session
    Number.objects().delete()

    # write the new number
    update = Number(num=num)

    # Save the number record for the next use
    try:
        update.save()
    except:
        error = "ERR007 Proble saving updated page index from clone"
        return render_template('sidekick/dberror.html', error=error)

    return render_template('sidekick/crud-goodcloneentry.html')
Esempio n. 9
0
def logs():
    table = []  # save table as empty tuple
    if request.method == 'POST':
        return render_template('logs.html', title="Logs")
    else:
        table = Database.retrieveMoods()  # puts moods inside table tuple
        return render_template('logs.html', title="Logs", table=table)
Esempio n. 10
0
 def post(self,request,*args,**kwargs):
     schema_name = request.POST.get('schema_name')
     schema_url = request.POST.get('schema_url')
     schema_username = request.POST.get('schema_username')
     schema_password = request.POST.get('schema_password')
     schema_env = request.POST.get('schema_env')
     database = Database(
         schema_name=schema_name,
         schema_url=schema_url,
         schema_username=schema_username,
         schema_password=encrypt(AES_ENCRYPT_KEY,schema_password),
         schema_env=schema_env
     )
     database_init.delay(schema_name,schema_url,schema_username,schema_password)
     database.save()
     return HttpResponseRedirect(reverse('database_list'))
Esempio n. 11
0
def predict_mood():
    # load the saved model (after training)
    model = pickle.load(open("audio/result/mlp_classifier.model", "rb"))
    print("Please talk")
    filename = "audio/test.wav"
    # record the file (start talking)
    record_to_file(filename)
    # extract features and reshape it
    features = extract_feature(filename, mfcc=True, chroma=True,
                               mel=True).reshape(1, -1)
    # predict
    result = model.predict(features)[0]
    # show the result !
    print("result:", result)
    Database.createMood(result)
    return result
Esempio n. 12
0
def cloneentry():
    '''
    Clone an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num = request.form['num']
        # PDelete the record from mongo database
        entry = Database.objects(num=num)

        # Get next record number and add 1
        num_list= []
        for n in Number.objects():
            num_list.append(n.num)
        num = num_list[0]

        # Get time date stamp
        now = datetime.datetime.now()
        now = now.isoformat()


        # create list from database entry
        more = {
                "num" : num,
                "now" : now,
                "sa" : entry[0].sa,
                "message" : entry[0].message,
                "concern" : entry[0].concern
                }


        #send form with info list
        return render_template('engineers/cloneentry.html', more=more)
    # Get sa
    sa_list= []
    for sa in Temp.objects():
        sa_list.append(sa.sa)
    sa = sa_list[0]
    sa = sa.encode('utf-8')
    sa=sa.replace(" ", "-")

    entries = []
    for e in Database.objects():
        if e.sa == sa:
            entries.append(e.num)
    return render_template('engineers/entrycloneselect.html', entries=entries)
Esempio n. 13
0
def start_record():
    # result = test_predict_mood()
    result = predict_mood()
    output = Database.feelBetter(result)
    return render_template('result.html',
                           title="Result",
                           output=output,
                           result=result)
Esempio n. 14
0
def upclone():
    '''
    Saves the cloned record

    '''
    # Get desired project
    num = request.form['num']
    now = request.form['now']
    sa = request.form['sa']
    message = request.form['message']
    concern = request.form['concern']

    now = now.encode('utf-8')
    sa = sa.encode('utf-8')
    message = message.encode('utf-8')
    concern = concern.encode('utf-8')
    num = int(num)

    # Build record to write to mongo database

    entry = Database(sa=sa,message=message,concern=concern,now=now,num=num)
    #rick.append('faiul')

    # Save the record
    try:
        entry.save()
    except:
        error = "Clone save issues"
        return render_template('engineers/dberror2.html',error=error)

    # Increment number for next use
    num = num + 1

    # Clear temp database for a new session
    Number.objects().delete()

    # write the new number
    update = Number(num=num)

    # Save the number record for the next use
    try:
        update.save()
    except:
        return render_template('engineers/dberror3.html')
    return render_template('engineers/goodeditentry.html')
Esempio n. 15
0
def listentryx():
    '''
    List all entries from the database by SA

    '''
    entries = []
    for e in Database.objects():
        entries.append(e)

    return render_template('managers/listentryx.html', entries=entries)
Esempio n. 16
0
def cloneentry():
    '''
    Clone an existing entry from the database

    '''
    if request.method == 'POST':
        # Get desired project
        num=request.form['num']
        # PDelete the record from mongo database
        entry=Database.objects(num=num)

        # Get next record number
        num=Number.objects.first()
        num=num.num

        # Get time date stamp
        now=datetime.datetime.now()
        now=now.isoformat()

        # create list from database entry
        stamp = {
                "num" : num,
                "now" : now,
                "user" : entry[0].user,
                "message" : entry[0].message,
                "concern" : entry[0].concern
                }

        #send form with info list
        return render_template('companion/crud-cloneentry.html',stamp=stamp)
    # Get user
    user=Companion.objects.first()
    user=user.user.encode('utf-8')

    entries=[]
    for e in Database.objects():
        if e.user == user:
            entries.append(e.num)
    return render_template('companion/crud-cloneselect.html', entries=entries)
Esempio n. 17
0
def listentry():
    '''
    List all entries from the database by SA

    '''
    # Get user
    user = Sidekick.objects.first()
    user = user.user.encode('utf-8')

    entries = []
    for e in Database.objects():
        if e.user == user:
            entries.append(e)
    return render_template('sidekick/crud-list.html', entries=entries)
Esempio n. 18
0
def listentry():
    '''
    List all entries from the database by SA

    '''
    # Get sa
    sa_list= []
    for sa in Temp.objects():
        sa_list.append(sa.sa)
    sa = sa_list[0]
    sa = sa.encode('utf-8')
    sa=sa.replace(" ", "-")

    entries = []
    for e in Database.objects():
        if e.sa == sa:
            entries.append(e)
    return render_template('engineers/listentry.html', entries=entries)
Esempio n. 19
0
def download():
    '''
    List all entries from the database by SA

    '''
    counter = 0
    cr = '\n'

    if request.method == 'POST':
        # Get desired project
        start = request.form['start']
        start = start.encode('utf-8')
        start = int(start)
        # Set the start back a month to get any weeks that cross month bounry
        if start == 1:
            start = 0
        else:
            start = start - 1

        # Open file for writing
        f = open('/opt/argus/static/sa_activities.csv', 'w')

        entries = []
        for e in Database.objects():
            e.now = e.now.encode('utf-8')

            check = e.now[5:7]
            check = int(check)

            # Look for matching Entries
            print "check %i, start %i" % (check, start)
            if check > start:
                line = str(e.num) + ',' + str(e.now) + ',' + str(
                    e.sa) + ',' + str(e.message) + ',' + str(e.concern)
                f.write(line)
                f.write(cr)

        f.close()
        return render_template('managers/download.html', entries=entries)

    return render_template('managers/dateselect.html')
Esempio n. 20
0
def name():
    '''
    List all entries from the database by SA

    '''

    if request.method == 'POST':
        # Get desired project
        sa = request.form['sa']
        entries = []
        for e in Database.objects():
            if e.sa == sa:
                entries.append(e)
        return render_template('managers/listsaentryx.html',
                               entries=entries,
                               sa=sa)
    # Get engineers
    eng_list = []
    for eng in Engineers.objects():
        eng.name = eng.name.encode('utf-8')
        eng_list.append(eng.name)

    return render_template('managers/salistselect.html', eng_list=eng_list)
Esempio n. 21
0
def newentry():
    '''
    Adds a new entry to the database
    Reads form variables, creates an entry and
    saves it to the mongo database..

    '''
    # Get sa
    sa_list= []
    for sa in Temp.objects():
        sa_list.append(sa.sa)
    sa = sa_list[0]
    sa = sa.encode('utf-8')
    sa=sa.replace(" ", "-")

    # Get time date stamp
    now = datetime.datetime.now()
    now = now.isoformat()


    # Get next record number and add 1
    num_list= []
    for n in Number.objects():
        num_list.append(n.num)
    num = num_list[0]
    more = [sa,now,num]

    # rick.append('fail')
    error='none'
    form = DatabaseForm()
    if form.validate_on_submit():
        message=form.message.data
        concern=form.concern.data

        message = message.encode('utf-8')
        concern = concern.encode('utf-8')

        # Build record to write to mongo database

        entry = Database(sa=sa,message=message,concern=concern,now=now,num=num)
        #rick.append('faiul')

        # Save the record
        try:
            entry.save()
        except:
            return render_template('engineers/dberror2.html',error=error)

        # Increment number for next use
        num = num + 1

        # Clear temp database for a new session
        Number.objects().delete()

        # write the new number
        update = Number(num=num)

        # Save the number record for the next use
        try:
            update.save()
        except:
            return render_template('engineers/dberror3.html')


        return render_template('engineers/savedentry.html')
    return render_template('engineers/newentry.html', form=form, more=more)
Esempio n. 22
0
def newentry():
    '''
    Adds a new entry to the database
    Reads form variables, creates an entry and
    saves it to the mongo database..

    '''
    # Get user
    user = Sidekick.objects.first()
    user = user.user.encode('utf-8')

    # Get time date stamp
    now = datetime.datetime.now()
    now = now.isoformat()

    # Get next record number
    num = Number.objects.first()
    num = num.num
    stamp = [user, now, num]

    # rick.append('fail')
    error = 'none'
    form = DatabaseForm()
    if form.validate_on_submit():
        message = form.message.data
        concern = form.concern.data

        message = message.encode('utf-8')
        concern = concern.encode('utf-8')

        # Build record to write to mongo database

        entry = Database(user=user,
                         message=message,
                         concern=concern,
                         now=now,
                         num=num)
        #rick.append('faiul')

        # Save the record
        try:
            entry.save()
        except:
            error = "ERR002 - saving new event form to database"
            return render_template('sidekick/dberror.html', error=error)

        # Increment number for next use
        num = num + 1

        # Clear temp database for a new session
        Number.objects().delete()

        # write the new record number
        update = Number(num=num)

        # Save the number record for the next use
        try:
            update.save()
        except:
            error = "ERR-003 - event number not increased"
            return render_template('sidekick/dberror.html', error=error)

        return render_template('sidekick/crud-goodsavedentry.html')
    return render_template('sidekick/crud-new.html', form=form, stamp=stamp)
Esempio n. 23
0
def delete_account():
    Database.remove_user()
    print("User deleted")
    return redirect(url_for("home"))