def burst_monitor(): request_method = request.method if request_method == "POST": form = request.form current_time = time.time() current_date = ts2datetime(current_time) data = burst_caculate(current_date, 1, "active", 5) return json.dumps(data) else: abort(404)
def burst(): default_burst_time = get_default_burst_time() if "logged_in" in session and session["logged_in"]: if session["user"] == "admin": request_method = request.method if request_method == "GET": return render_template("identify/burst.html", from_external=True, time=default_burst_time) elif request_method == "POST": form = request.form action = form.get("action", "run") top_n = int(form.get("top_n", 500)) if top_n > 500: top_n = 500 page_num = int(form.get("page_num", 20)) rank_method = form.get("rank_method", "important") burst_time = form.get("burst_time", default_burst_time) burst_time = _utf_encode(burst_time) time_ts = burst2ts(burst_time) if action == "rank": current_date = ts2datetime(time_ts) data = burst_caculate(current_date, 1, rank_method, top_n) previous_date = ts2datetime(time_ts - 24 * 3600) previous_data = burst_caculate(previous_date, 1, rank_method, top_n) index = dict() for i in range(0, len(data)): # 比较上期结果 flag = 0 for j in range(0, len(previous_data)): if previous_data[j][1] == data[i][1]: flag = 1 compare = previous_data[j][0] - data[i][0] index[previous_data[j][1]] = j break if flag == 0: compare = 0 data[i].append(compare) pre_data = [] for i in range(0, len(previous_data)): if index.has_key(previous_data[i][1]): pass else: pre_data.append(previous_data[i]) return json.dumps( { "status": "current finished", "data": data, "pre_data": pre_data, "method": rank_method, "time": time_ts, } ) elif action == "run": burst_time = _utf_decode(burst_time.strip()) return render_template( "identify/burst.html", rank_method=rank_method, burst_time=burst_time, top_n=top_n, page_num=page_num, time=default_burst_time, ) else: abort(404) else: abort(404) else: pas = db.session.query(UserList).filter(UserList.username == session["user"]).all() if pas != []: for pa in pas: identy = pa.identify if identy == 1: request_method = request.method if request_method == "GET": return render_template("identify/burst.html", from_external=True, time=default_burst_time) elif request_method == "POST": form = request.form action = form.get("action", "run") top_n = int(form.get("top_n", 500)) if top_n > 500: top_n = 500 page_num = int(form.get("page_num", 20)) rank_method = form.get("rank_method", "important") burst_time = form.get("burst_time", default_burst_time) burst_time = _utf_encode(burst_time) time_ts = burst2ts(burst_time) if action == "rank": current_date = ts2datetime(time_ts) data = burst_caculate(current_date, 1, rank_method, top_n) previous_date = ts2datetime(time_ts - 24 * 3600) previous_data = burst_caculate(previous_date, 1, rank_method, top_n) index = dict() for i in range(0, len(data)): # 比较上期结果 flag = 0 for j in range(0, len(previous_data)): if previous_data[j][1] == data[i][1]: flag = 1 compare = previous_data[j][0] - data[i][0] index[previous_data[j][1]] = j break if flag == 0: compare = 0 data[i].append(compare) pre_data = [] for i in range(0, len(previous_data)): if index.has_key(previous_data[i][1]): pass else: pre_data.append(previous_data[i]) return json.dumps( { "status": "current finished", "data": data, "pre_data": pre_data, "method": rank_method, "time": time_ts, } ) elif action == "run": burst_time = _utf_decode(burst_time) return render_template( "identify/burst.html", rank_method=rank_method, burst_time=burst_time, top_n=top_n, page_num=page_num, time=default_burst_time, ) else: return redirect("/") return redirect("/") else: return redirect("/")