Exemplo n.º 1
0
def table_cluster():

    if request.data:
        username = json.loads(request.data).get('username')

        try:
            if session['username'] == username:
                modelcluster = Model()
                result = modelcluster.select_cluster()
                data = {}
                data.setdefault('data', result)

                modelcluster.close_connection()

                return jsonify(data)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 2
0
def delete_keyword():

    if request.data:
        username = json.loads(request.data).get('username')
        keyword = json.loads(request.data).get('keyword')

        try:
            if session['username'] == username:
                modeltwitter = Model()
                result = modeltwitter.delete_keyword_twitter(keyword)
                data = {}
                data.setdefault('succes', True)

                modeltwitter.close_connection()

                return jsonify(data)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 3
0
def edit_kbba():
    if request.data:
        username = json.loads(request.data).get('username')
        alay_before = json.loads(request.data).get('alay_before')
        alay_after = json.loads(request.data).get('alay_after')
        baku_before = json.loads(request.data).get('baku_before')
        baku_after = json.loads(request.data).get('baku_after')

        try:
            if session['username'] == username:
                modelkbba = Model()
                result = modelkbba.edit_kbba(alay_after, baku_after,
                                             alay_before, baku_before)
                modelkbba.close_connection()

                return jsonify(result)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 4
0
def visualitation():

    if 'username' not in session:
        return redirect(url_for('login'))
    modeltraining = Model()
    list_keyword = modeltraining.select_model_keyword()
    modeltraining.close_connection()
    return render_template('admin/pages/visualitation.html',
                           keyword=list_keyword,
                           username=session['username'])
Exemplo n.º 5
0
def training():

    if 'username' not in session:
        return redirect(url_for('login'))

    if chache[session['username']]['statustraining'] == 0 and session[
            'process_training']:
        session['process_training'].remove(1)
        session.modified = True

    modellabel = Model()
    emoticon = modellabel.select_label()
    modellabel.close_connection()

    return render_template('admin/pages/training.html',
                           username=session['username'],
                           training=session['process_training'],
                           emoticon=emoticon)
Exemplo n.º 6
0
def check_min_max_tweet():

    if request.data:
        username = json.loads(request.data).get('username')
        keyword = json.loads(request.data).get('keyword')

        try:
            if session['username'] == username:
                modeltwitter = Model()
                dict_result = modeltwitter.select_min_max_tweet(keyword)
                modeltwitter.close_connection()
                return jsonify(dict_result)

            else:
                return redirect(url_for('login'))
        except Exception as error:
            print(error)
            return redirect(url_for('login'))
    else:
        return redirect(url_for('login'))
Exemplo n.º 7
0
def table_preprocessing_keyword():

    if request.data:
        username = json.loads(request.data).get('username')
        keyword = json.loads(request.data).get('keyword')

        try:
            if session['username'] == username:
                modeltwitter = Model()
                data_preprocessing = modeltwitter.select_keyword_not_preprocessing(
                    keyword)
                modeltwitter.close_connection()
                # backgroundprocess_preprocessing(keyword, data_preprocessing, username)
                worker = threading.Thread(
                    target=backgroundprocess_preprocessing,
                    args=(
                        keyword,
                        data_preprocessing,
                        username,
                    ))
                worker.daemon = True
                worker.start()

                chache[session['username']]['statuspreprocessing'] = 1
                data = {}
                data['statuspreprocessing'] = chache[
                    session['username']]['statuspreprocessing']
                session['process_preprocessing'].append(1)
                session.modified = True

                return jsonify(data)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 8
0
def delete_label():
    if request.data:
        username = json.loads(request.data).get('username')
        id_label = json.loads(request.data).get('id_label')

        try:
            if session['username'] == username:
                modellabel = Model()
                result = modellabel.delete_label(id_label)
                modellabel.close_connection()

                return jsonify(result)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 9
0
def delete_stopword():
    if request.data:
        username = json.loads(request.data).get('username')
        word = json.loads(request.data).get('word')

        try:
            if session['username'] == username:
                modelstopword = Model()
                result = modelstopword.delete_stopword(word)
                modelstopword.close_connection()

                return jsonify(result)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 10
0
def backgroundprocess_preprocessing(keyword, data_preprocessing, username):
    model = Model()
    tfidf = TfIdf(model)
    preprocessing = Preprocessing(model)
    list_id_tweet = []
    list_tweet_stemming = []
    list_tfidf = []

    try:

        model.delete_clustered(keyword)

        for data_tweet in data_preprocessing:
            id_tweet, tweet_stemming = background_preprocessing(
                data_tweet, keyword, preprocessing, model)
            list_id_tweet.append(id_tweet)
            list_tweet_stemming.append(tweet_stemming)

        tfidf.word_idf(list_tweet_stemming, keyword)
        list_idf = model.select_idf(keyword)

        for index, tweet_steming in enumerate(list_tweet_stemming):
            id_tweet = list_id_tweet[index]
            tweet_tfidf = tfidf.tf_idf(
                preprocessing.tokennizing(tweet_steming), keyword, list_idf)
            model.update_tfidf(id_tweet, keyword, tweet_tfidf)
            list_tfidf.append({'id': id_tweet, 'tfidf': tweet_tfidf})

        data = sorted(list_tfidf, key=lambda k: k['id'])

        model.update_vocab_config(data, keyword)

    except Exception as error:
        print(error)

    finally:
        chache[username]['statuspreprocessing'] = 0
        model.close_connection()
Exemplo n.º 11
0
def delete_kbba():
    if request.data:
        username = json.loads(request.data).get('username')
        alay = json.loads(request.data).get('alay')
        baku = json.loads(request.data).get('baku')

        try:
            if session['username'] == username:
                modelkbba = Model()
                result = modelkbba.delete_kbba(alay, baku)
                modelkbba.close_connection()

                return jsonify(result)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 12
0
def visualitation_show():

    if request.data:
        username = json.loads(request.data).get('username')
        keyword = json.loads(request.data).get('keyword')

        try:
            if session['username'] == username:
                modelcluster = Model()
                data = modelcluster.select_cluster_plot(keyword)
                modelcluster.close_connection()

                return jsonify(data)

            else:
                return redirect(url_for('login'))

        except Exception as error:
            print(error)
            return redirect(url_for('login'))

    else:
        return redirect(url_for('login'))
Exemplo n.º 13
0
def index():
    modeltraining = Model()
    list_keyword = modeltraining.select_model_keyword()
    modeltraining.close_connection()

    return render_template('index.html', keyword=list_keyword)