Added top uploads by user API endpoint.

This commit is contained in:
msinkec 2021-12-20 11:47:06 +01:00
parent 9e93d41bc3
commit 7c79891983
2 changed files with 21 additions and 1 deletions

8
app.py
View File

@ -455,10 +455,16 @@ def solar_resetpass_post(token):
@app.route('/topuploads') @app.route('/topuploads')
@login_required @login_required
def solar_topuploads_srednje(): def solar_topuploads():
return jsonify(portal.solar.get_top_uploading_institutions()) return jsonify(portal.solar.get_top_uploading_institutions())
@app.route('/topuploads-by-user')
@login_required
def solar_topuploads_by_user():
return jsonify(portal.solar.get_top_uploading_users())
@app.route('/deluser', methods=['POST']) @app.route('/deluser', methods=['POST'])
@login_required @login_required
def solar_del_user(): def solar_del_user():

View File

@ -458,6 +458,20 @@ def get_top_uploading_institutions():
return dict(sorted(res.items(), key=lambda x:x[1], reverse=True)) return dict(sorted(res.items(), key=lambda x:x[1], reverse=True))
def get_top_uploading_users():
res = dict()
users = get_all_active_users()
for user in users:
uploads = UploadSolar.query.filter_by(upload_user=user.id).all()
for upload in uploads:
if user.name not in res:
res[user.name] = 0
res[user.name] += len(upload.upload_file_hashes)
if len(res) >= 5:
return dict(sorted(res.items(), key=lambda x:x[1], reverse=True)[:5])
return dict(sorted(res.items(), key=lambda x:x[1], reverse=True))
def get_all_active_users(): def get_all_active_users():
# TODO: do filtering purely within an SQL query # TODO: do filtering purely within an SQL query
res = [] res = []