diff --git a/app.py b/app.py index efa583c..66c6de9 100644 --- a/app.py +++ b/app.py @@ -455,10 +455,16 @@ def solar_resetpass_post(token): @app.route('/topuploads') @login_required -def solar_topuploads_srednje(): +def solar_topuploads(): 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']) @login_required def solar_del_user(): diff --git a/portal/solar.py b/portal/solar.py index 5151e50..b5a6d26 100644 --- a/portal/solar.py +++ b/portal/solar.py @@ -458,6 +458,20 @@ def get_top_uploading_institutions(): 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(): # TODO: do filtering purely within an SQL query res = []