Beispiel #1
0
def _test_table(request, traina, trainb, testa, testb):
    con = sqlite3.connect(settings['USERS_DB'].format(session['username'])).cursor()
    traininga = con.execute("SELECT plain_text FROM {}".format(testa)).fetchall()
    trainingb = con.execute("SELECT plain_text FROM {}".format(testb)).fetchall()
    a, b = [], []
    for item in traininga:
        a.append(item[0])
    for item in trainingb:
        b.append(item[0])
    my_list = [(item, 0) for item in a]
    my_list2 = [(item, 1) for item in b]
    my_list.extend(my_list2)
    random.shuffle(my_list)
    train1 = []
    train2 = []
    for item in my_list:
        train1.append(item[0])
        train2.append(item[1])
    x = FileController()
    file = x.fetch_path(session['username'])
    f = open(file + "/{}_{}.pickle".format(traina, trainb), 'rb')
    model = pickle.load(f)
    f.close()
    testcase = TestModel(model, train1, train2)
    print(testcase['plain_text'])
    print(testcase['guess'])
    print(testcase['answer'])
    print(testcase['percent'])
    return render_template('User/results.html', training=testcase)
Beispiel #2
0
def _delete_model(request, model):
    items = model.replace(' VS. ', '_')
    User(session['username']).delete_model(model)
    session['models'] = User(session['username']).fetch_models()
    x = FileController()
    file = x.fetch_path(session['username'])
    os.remove(file+"/{}.pickle".format(items))
    return redirect("/training")
Beispiel #3
0
def _train_table(request, traina, trainb):
    con = sqlite3.connect(settings['USERS_DB'].format(session['username'])).cursor()
    traininga = con.execute("SELECT plain_text FROM {}".format(traina)).fetchall()
    trainingb = con.execute("SELECT plain_text FROM {}".format(trainb)).fetchall()
    a, b = [], []
    for item in traininga:
        a.append(item[0])
    for item in trainingb:
        b.append(item[0])
    my_list = [(item, 0) for item in a]
    my_list2 = [(item, 1) for item in b]
    my_list.extend(my_list2)
    random.shuffle(my_list)
    train1 = []
    train2 = []
    for item in my_list:
        train1.append(item[0])
        train2.append(item[1])
    print(traina, trainb)
    print(train1, train2)
    model = MakeModel(train1, train2, [traina, trainb])
    x = FileController()
    file = x.fetch_path(session['username'])
    f = open(file+"/{}_{}.pickle".format(traina, trainb), 'wb')
    pickle.dump(model, f)
    f.close()
    User(session['username']).create_model("{} VS. {}".format(traina, trainb))
    session['models'] = User(session['username']).fetch_models()
    # f.write('hi')
    # f.close()


    # print(traina, trainb, testa, testb)
    # print("{}/{}v{}".format(x.fetch_path(session['username']), traina, trainb))
    # testlist = [(item, 0) for item in c]
    # testlist2 = [(item, 1) for item in d]
    # testlist.extend(testlist2)
    # print(my_list, testlist)
    return redirect("/training")