Show average response time on reports page

Closes: #13
This commit is contained in:
Edward Betts 2023-12-10 17:31:31 +00:00
parent e65f85becb
commit 96e3bac55c
2 changed files with 10 additions and 5 deletions

View file

@ -9,10 +9,10 @@ import traceback
import typing
from time import time
import sqlalchemy
import sqlalchemy.exc
import werkzeug.debug.tbtools
from flask import Flask, jsonify, redirect, render_template, request, url_for
from sqlalchemy import func
from sqlalchemy.orm.query import Query
from werkzeug.wrappers import Response
@ -332,12 +332,15 @@ def reports() -> str:
"""Reports page with various statistics."""
log_count = model.LookupLog.query.count()
log_start_time = database.session.query(
sqlalchemy.func.min(model.LookupLog.dt)
).scalar()
log_start_time, average_response_time = database.session.query(
func.min(model.LookupLog.dt), func.avg(model.LookupLog.response_time_ms)
).one()
return render_template(
"reports.html", log_count=log_count, log_start_time=log_start_time
"reports.html",
log_count=log_count,
log_start_time=log_start_time,
average_response_time=average_response_time,
)

View file

@ -12,6 +12,8 @@
<p>Total lookups processed: {{ "{:,d}".format(log_count) }}</p>
<p>Average response time: {{ average_response_time | int }} milliseconds</p>
</div>
{% endblock %}