Added stats page

This commit is contained in:
Simon
2018-06-18 19:56:25 -04:00
parent 7923647ea3
commit 8768e39f08
10 changed files with 289 additions and 38 deletions

View File

@@ -50,7 +50,7 @@ def task_put():
@auth.login_required
def get_completed_tasks():
json_str = json.dumps([result.to_json() for result in tm.get_non_indexed_results()])
return json_str
return Response(json_str, mimetype="application/json")
@app.route("/task/current", methods=["GET"])
@@ -77,7 +77,14 @@ def get_file_list(website_id):
def get_task_logs():
json_str = json.dumps([result.to_json() for result in tm.get_all_results()])
return json_str
return Response(json_str, mimetype="application/json")
@app.route("/stats/")
@auth.login_required
def get_stats():
json_str = json.dumps(tm.get_stats())
return Response(json_str, mimetype="application/json")
if __name__ == "__main__":

View File

@@ -103,5 +103,20 @@ class TaskManager:
if task.website_id == task_result.website_id:
del current_tasks[i]
def get_stats(self):
task_results = self.get_all_results()
stats = dict()
if len(task_results) > 0:
stats["task_count"] = len(task_results)
stats["task_time"] = sum((task.end_time - task.start_time) for task in task_results)
stats["task_time_avg"] = stats["task_time"] / len(task_results)
stats["task_file_count"] = sum(task.file_count for task in task_results)
stats["task_file_count_avg"] = stats["task_file_count"] / len(task_results)
return stats