Add top_users
This commit is contained in:
parent
ae38540076
commit
d918b9a25d
|
@ -6,6 +6,37 @@ from datetime import datetime
|
||||||
|
|
||||||
group_stat_api = Blueprint('group_stat_api', __name__)
|
group_stat_api = Blueprint('group_stat_api', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@group_stat_api.route("/top_users", methods=["GET"])
|
||||||
|
def top_users():
|
||||||
|
number = request.args.get("number")
|
||||||
|
|
||||||
|
if not number: number = 3
|
||||||
|
|
||||||
|
number = int(number)
|
||||||
|
|
||||||
|
members = []
|
||||||
|
counts = []
|
||||||
|
|
||||||
|
query = (Member
|
||||||
|
.select(fn.count(Message.id).alias("count"), Member)
|
||||||
|
.join(Message)
|
||||||
|
.group_by(Member)
|
||||||
|
.order_by(SQL("count").desc())
|
||||||
|
)
|
||||||
|
|
||||||
|
for group in query:
|
||||||
|
members.append(group.first_name)
|
||||||
|
counts.append(group.count)
|
||||||
|
|
||||||
|
members.insert(0, "Others")
|
||||||
|
counts.insert(0, sum(counts[number:]))
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
"members": members[:number + 1],
|
||||||
|
"counts": counts[:number + 1]
|
||||||
|
})
|
||||||
|
|
||||||
@group_stat_api.route("/chat_activity", methods=["GET"])
|
@group_stat_api.route("/chat_activity", methods=["GET"])
|
||||||
def chat_activity():
|
def chat_activity():
|
||||||
from_date = request.args.get("from_date")
|
from_date = request.args.get("from_date")
|
||||||
|
|
Loading…
Reference in New Issue