Пример #1
0
def topic_submit():
    if 'logged_in' in session and session['logged_in']:        
        if session['user'] == 'admin':
            keyword = request.args.get('keyword', None)
            during = request.args.get('during', None)
            time = request.args.get('time', None)
            timestamp = request.args.get('timestamp', None)
            timestamp = int(timestamp)
            time = _utf_encode(time)
            start_ts, end_ts = _time_zone(time)
            if not during or during == '':
                during = MinInterval
            else:
                during = str2ts(during)
            status , item = _add_history(-1, keyword, start_ts, end_ts, timestamp, during) #添加提交topic的历史
            return render_template('moodlens/topic_emotion.html', active='moodlens', temp_keyword=keyword, temp_during=during)
        else:
            pas = db.session.query(UserList).filter(UserList.username==session['user']).all()
            if pas != []:
                for pa in pas:
                    identy = pa.moodlens
                    if identy == 1:
                        return render_template('moodlens/topic_emotion.html', active='moodlens')
                    else:
                        return redirect('/')

            return redirect('/')
    else:
        return redirect('/')
Пример #2
0
def topic_submit():
    if "logged_in" in session and session["logged_in"]:
        if session["user"] == "admin":
            keyword = request.args.get("keyword", None)
            time = request.args.get("time", None)
            timestamp = request.args.get("timestamp", None)
            timestamp = int(timestamp)
            time = _utf_encode(time)
            start_ts, end_ts = _time_zone(time)
            status, item = _add_history(-1, keyword, start_ts, end_ts, timestamp)
            return status, item
            # return render_template('identify/topic.html', topic=keyword, topic_id=1, window_size=1)
    else:
        return redirect("/")
Пример #3
0
def search_history():
    if request.method == "GET":
        keyword = request.args.get("keyword", None)
        now1 = request.args.get("now1", None)
        now2 = request.args.get("now2", None)
        now = request.args.get("now", None)
        timestamp_end = request.args.get("timestamp", None)
        if timestamp_end:
            timestamp_end = int(timestamp_end)
        if now1:
            now1 = int(now1)
        if now2:
            now2 = int(now2)
        if now:
            now = int(now)
        histories1 = None
        histories2 = None
        histories = None
        if keyword != None:
            status, histories = _search_history(keyword)
        else:
            if now:
                status, histories = _all_history(now)
            if now1:
                status, histories1 = _all_history(now1)
            if now2 == 0:
                status, histories2 = _all_history(now2)
        histories_names = []
        if histories1:
            for history in histories1:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end - 24 * 3600))
                datestr = str(start) + " - " + str(end)
                if timestamp_end:
                    timestamp_start = int(history.db_date)
                    time_pass = timestamp_end - timestamp_start
                    time_pass_hour = int(time_pass) / 3600
                    time_pass_day = int(time_pass) / (24 * 3600)
                    time_pass = time.strftime("%M分钟 %S秒 ", time.localtime(time_pass))
                    time_pass = str(time_pass_day) + "天" + str(time_pass_hour) + "小时" + time_pass
                    time_pass = "******" + str(time_pass)
                    db_date = time.strftime("%m月 %d日, %Y %H:%M:%S", time.localtime(history.db_date))
                    db_date = "     提交时间: " + str(db_date)
                    histories_names.append([history.topic, datestr, db_date, time_pass])
                else:
                    histories_names.append([history.topic, datestr])
        if histories2:
            for history in histories2:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end - 24 * 3600))
                datestr = str(start) + " - " + str(end)
                if timestamp_end:
                    timestamp_start = int(history.db_date)
                    time_pass = timestamp_end - timestamp_start
                    time_pass_hour = int(time_pass) / 3600
                    time_pass_day = int(time_pass) / (24 * 3600)
                    time_pass = time.strftime("%M分钟 %S秒 ", time.localtime(time_pass))
                    time_pass = str(time_pass_day) + "天" + str(time_pass_hour) + "小时" + time_pass
                    time_pass = "******" + str(time_pass)
                    db_date = time.strftime("%m月 %d日, %Y %H:%M:%S", time.localtime(history.db_date))
                    db_date = "     提交时间: " + str(db_date)
                    histories_names.append([history.topic, datestr, db_date, time_pass])
                else:
                    histories_names.append([history.topic, datestr])
        if histories:
            for history in histories:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end - 24 * 3600))
                datestr = str(start) + " - " + str(end)
                histories_names.append([history.topic, datestr])
        return json.dumps(histories_names)
    else:
        operator = request.form.get("operator", "add")
        keyword = request.form.get("keyword", "")
        start = request.form.get("start", "")
        end = request.form.get("end", "")
        sentiment = request.form.get("sentiment", "")
        if keyword != "" and start != "" and end != "" and sentiment != "":
            if operator == "add":
                status, item = _add_history(-1, keyword, start_ts, end_ts, timestamp)
                item = item.topic + "\t" + item.start + "\t" + item.end + "\t" + item.range + "\t" + item.status
            else:
                status, item = "failed", "Null"
        else:
            status, item = "failed", "Null"
        return json.dumps({"status": status, "item": item})
Пример #4
0
def search_history():
    if request.method == 'GET':  #显示查询历史
        keyword = request.args.get('keyword',None)
        now1 = request.args.get('now1', None)
        now2 = request.args.get('now2', None)
        now = request.args.get('now', None) 
        timestamp_end = request.args.get('timestamp', None)
        if timestamp_end:
            timestamp_end = int(timestamp_end)
        if now1:
            now1 = int(now1)
        if now2:
            now2 = int(now2)
        if now:
            now = int(now)   #三个变量的含义??
        histories1 = None
        histories2 = None
        histories = None
        if keyword != None:
            status, histories = _search_history(keyword)
        else:
            if now:
                status, histories = _all_history(now)
            if now1:
                status, histories1 = _all_history(now1)
            if now2 == 0:
                status, histories2 = _all_history(now2)
        histories_names = []
        if histories1:
            for history in histories1:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end-24*3600))
                datestr  = str(start) + ' - ' + str(end)
                if(timestamp_end):
                    timestamp_start = int(history.db_date)
                    time_pass = timestamp_end - timestamp_start
                    time_pass_hour = int(time_pass) / 3600
                    time_pass_day = int(time_pass) / ( 24 * 3600 )
                    time_pass = time.strftime("%M分钟 %S秒 ", time.localtime(time_pass))
                    time_pass = str(time_pass_day) + '天' + str(time_pass_hour) + '小时' + time_pass
                    time_pass = '******' + str(time_pass)
                    db_date = time.strftime("%m月 %d日, %Y %H:%M:%S", time.localtime(history.db_date))
                    db_date = '     提交时间: ' + str(db_date)
                    histories_names.append([history.topic, datestr, db_date, time_pass ])
                else:
                    histories_names.append([history.topic, datestr])
        if histories2:
            for history in histories2:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end-24*3600))
                datestr  = str(start) + ' - ' + str(end)
                if(timestamp_end):
                    timestamp_start = int(history.db_date)
                    time_pass = timestamp_end - timestamp_start
                    time_pass_hour = int(time_pass) / 3600
                    time_pass_day = int(time_pass) / ( 24 * 3600 )
                    time_pass = time.strftime("%M分钟 %S秒 ", time.localtime(time_pass))
                    time_pass = str(time_pass_day) + '天' + str(time_pass_hour) + '小时' + time_pass
                    time_pass = '******' + str(time_pass)
                    db_date = time.strftime("%m月 %d日, %Y %H:%M:%S", time.localtime(history.db_date))
                    db_date = '     提交时间: ' + str(db_date)
                    histories_names.append([history.topic, datestr, db_date, time_pass ])
                else:
                    histories_names.append([history.topic, datestr])                
        if histories:
            for history in histories:
                start = time.strftime("%m月 %d日, %Y", time.localtime(history.start))
                end = time.strftime("%m月 %d日, %Y", time.localtime(history.end-24*3600))
                datestr  = str(start) + ' - ' + str(end)
                histories_names.append([history.topic, datestr])
        return json.dumps(histories_names)
    else:   #添加历史?!
        operator = request.form.get('operator', 'add')
        keyword = request.form.get('keyword', '')
        start = request.form.get('start', '')
        end = request.form.get('end', '')
        range = request.form.get('during', '')
        sentiment = request.form.get('sentiment', '')
        if keyword != '' and start != '' and end != '' and range != '' and sentiment != '':
            if operator == 'add':
                status, item = _add_history(-1, keyword, start, end, range)
                item = item.topic + '\t' + item.start + '\t' + item.end + '\t' + item.range + '\t' + item.status
            else:
                status, item = 'failed', 'Null'
        else:
            status, item = 'failed', 'Null'
        return json.dumps({'status': status, 'item': item})