예제 #1
0
def stats():
    if session.get('user') == 'admin':
        tweetvo = tweetVO()
        # logindao = loginDAO()
        tweetdao = tweetDAO()
        active_users = tweetdao.get_active_users()
        all_tweets = tweetdao.get_all_tweets()
        # tweet_ids = [row[1] for row in all_tweets]
        all_data, double_count = clean_data(all_tweets)
        same_annots, count_double = get_same_annots(all_data)
        data = read_json('data/annoted_tweets.json')
        len_same = len(same_annots)
        len_all = len(all_data)
        aggs = get_agg(all_tweets)

        for user in data:
            if user in active_users:
                data[user]['active'] = True
            else:
                data[user]['active'] = False

        statistics = {
            'same_annots': len_same,
            'total_annots': len_all,
            'double_annots': double_count
        }
        return render_template('view_statistics_admin.html',
                               data=data,
                               len=len,
                               statistics=statistics,
                               aggs=aggs)
    else:
        return redirect(url_for('home'))
예제 #2
0
def report_not_english():
    if session.get('user'):
        if request.method == 'POST':
            id_str = request.form.get('id_str')
            tweet = request.form.get('tweet')
            # print(tweet)
            tweetvo = tweetVO()
            tweetdao = tweetDAO()
            # user = session.get('user')
            tweetvo.username = session['user']
            tweetvo.tweet_id = id_str
            tweetvo.tweet = tweet
            resp = tweetdao.report_not_english(tweetvo)
            user_data = read_json('data/annoted_tweets.json')
            user_data[session['user']]['reported_tweets'].append(id_str)
            new_data = json.dumps(user_data, indent=4)
            json_file = open('data/annoted_tweets.json', 'w')
            json_file.write(new_data)
            json_file.close()

            if resp:
                resp = {'status': 'NOT_ENGLISH_OK'}
                return json.dumps(resp)
            else:
                return '<h1>Oooppss!! Internal Database Error</h1>'
        else:
            return '<h1>INVALID REQUEST</h1>'
    else:
        return redirect(url_for('login'))
예제 #3
0
def get_individual_annotator_log(user):
    if session.get('user') == 'admin':
        # print('inside admin indi')
        tweetvo = tweetVO()
        tweetdao = tweetDAO()
        # user = session.get('user')
        tweetvo.username = user
        resp, annotated_tweets = tweetdao.get_annots_admin()
        rows_tup = annotated_tweets[user]
        rows = []
        for i in range(len(rows_tup)):
            row = list(rows_tup[i])
            row[-1] = tuple(row[-1].split('\t'))
            rows.append(tuple(row))
        # print('--------- {} --------'.format(rows))
        if resp == True:
            # print('inside if true')
            # print(annotated_tweets[user])
            return render_template('view_annotated_tweets_admin_tables.html',
                                   rows=rows,
                                   error=None,
                                   user=user)
        else:
            return render_template('view_annotated_tweets_admin_tables.html',
                                   error=resp)
    else:
        return redirect(url_for('login'))
예제 #4
0
def annotated_tweets_admin():
    if session.get('user') == 'admin':
        # print('inside admin===============')
        tweetvo = tweetVO()
        tweetdao = tweetDAO()
        user = session.get('user')
        tweetvo.username = user
        data_json = read_json('data/annoted_tweets.json')
        active_users = tweetdao.get_active_users()
        # print(data_json)
        for user in data_json:
            if user in active_users:
                data_json[user]['active'] = True
            else:
                data_json[user]['active'] = False
        resp, annotated_tweets = tweetdao.get_annots_admin()
        if resp == True:
            # print('inside if true')
            for user in annotated_tweets:
                annots = annotated_tweets[user]
                labels = [annot[2] for annot in annots]
                task_1, task_2, task_3 = [
                    label.split('\t')[0] for label in labels
                ], [label.split('\t')[1] for label in labels
                    ], [label.split('\t')[2] for label in labels]
                # print('task 1',task_1)
                # print('task 2',task_2)
                # print('task 3',task_3)
                annotated_tweets[user].append({
                    'HOF_COUNT':
                    task_1.count('HOF'),
                    'NOT_COUNT':
                    task_1.count('NOT'),
                    'HATE_COUNT':
                    task_2.count('HATE'),
                    'OFFN_COUNT':
                    task_2.count('OFFN'),
                    'PRFN_COUNT':
                    task_2.count('PRFN'),
                    'UNT_COUNT':
                    task_3.count('UNT'),
                    'TIN_COUNT':
                    task_3.count('TIN'),
                    'NULL_COUNT':
                    task_3.count('NULL')
                })
            # print(annotated_tweets['german_1'][-1])
            return render_template('view_annotated_tweets_admin_graph.html',
                                   annotated_tweets_users=annotated_tweets,
                                   error=None,
                                   data_json=data_json)
        else:
            return render_template('view_annotated_tweets_admin_graph.html',
                                   error=resp)
    else:
        return redirect(url_for('login'))
예제 #5
0
def get_single_annots(data=None):
    tweetdao = tweetDAO()
    all_tweets = tweetdao.get_all_tweets()
    new_data = []
    data = []
    for row in all_tweets:
        temp = list(row)
        data.append(temp)
    for li in data:
        l = [item for item in li if item is not None]
        if len(l) == 5:
            new_data.append(l)
    # print(len(new_data))
    return new_data
예제 #6
0
def annotated_tweets():
    if session.get('user') == 'admin':
        return redirect(url_for('annotated_tweets_admin'))
    if session.get('user'):
        tweetvo = tweetVO()
        tweetdao = tweetDAO()
        user = session.get('user')
        tweetvo.username = user
        resp, rows_tup = tweetdao.get_annots(tweetvo)
        rows = []
        for i in range(len(rows_tup)):
            row = list(rows_tup[i])
            row[-1] = tuple(row[-1].split('\t'))
            rows.append(tuple(row))
        # print(rows)
        if resp == True:
            return render_template('view_annotated_tweets.html',
                                   rows=rows,
                                   error=None)
        else:
            return render_template('view_annotated_tweets.html', error=resp)
    else:
        return redirect(url_for('login'))
예제 #7
0
def annot():
    if session.get('user'):
        tweetvo = tweetVO()
        tweetdao = tweetDAO()
        cursor = conn.cursor()
        data_json = read_json('data/annoted_tweets.json')
        annoted_tweet_ids = data_json[session['user']]['annoted_tweets']
        if request.method == 'POST':
            # annot=request.form.get('annot')
            tweet = request.form.get('tweet')
            tweet = tweet.replace('"', "'")
            # tweet='"hello"'
            id_str = request.form.get('id_str')
            task_1 = request.form.get('task_1')
            task_2 = request.form.get('task_2')
            # task_b=request.form.get('task_b')
            task_3 = request.form.get('task_3')
            lang = request.form.get('lang')
            row_no = request.form.get('row_no')
            if task_3 == None:
                task_3 = 'NULL'
            # print('task3',task_3)
            # print(task_1)
            # print(request.form)
            resp = '{}\t{}\t{}'.format(task_1, task_2, task_3)
            # print(resp)
            tweetvo.resp = resp
            tweetvo.tweet_id = id_str
            tweetvo.tweet = tweet
            tweetvo.lang = lang
            tweetvo.username = session['user']
            rows, db_status = tweetdao.check_exists(tweetvo)
            if rows == 0:
                # print('inside if')
                db_status = tweetdao.insert_annot(tweetvo)
            elif rows == 1:
                # print('inside elif')
                db_status = tweetdao.update_records(tweetvo)

            if db_status == True:
                annoted_tweet_ids.append(id_str)
                data_json[session['user']]['annoted_count'] = len(
                    annoted_tweet_ids)
                # print(rows)
                utc_now = datetime.datetime.utcnow()
                date_list = str(utc_now.date()).split('-')
                date = '-'.join(date_list[-1::-1])
                time = str(utc_now.time()).split('.')[0]
                # print(date, time)
                data_json[session['user']]['annoted_tweets'] = list(
                    set(annoted_tweet_ids))
                data_json[session['user']]['last_updated'] = {
                    "date": date,
                    "time": time
                }
                new_data = json.dumps(data_json, indent=4)
                json_file = open('data/annoted_tweets.json', 'w')
                json_file.write(new_data)
                json_file.close()
                # cursor.execute(query)
                conn.commit()
                resp = {'status': 'OK'}
                return json.dumps(resp)
            else:
                return 'database Failure'

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