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 import typing
from time import time from time import time
import sqlalchemy
import sqlalchemy.exc import sqlalchemy.exc
import werkzeug.debug.tbtools import werkzeug.debug.tbtools
from flask import Flask, jsonify, redirect, render_template, request, url_for from flask import Flask, jsonify, redirect, render_template, request, url_for
from sqlalchemy import func
from sqlalchemy.orm.query import Query from sqlalchemy.orm.query import Query
from werkzeug.wrappers import Response from werkzeug.wrappers import Response
@ -332,12 +332,15 @@ def reports() -> str:
"""Reports page with various statistics.""" """Reports page with various statistics."""
log_count = model.LookupLog.query.count() log_count = model.LookupLog.query.count()
log_start_time = database.session.query( log_start_time, average_response_time = database.session.query(
sqlalchemy.func.min(model.LookupLog.dt) func.min(model.LookupLog.dt), func.avg(model.LookupLog.response_time_ms)
).scalar() ).one()
return render_template( 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>Total lookups processed: {{ "{:,d}".format(log_count) }}</p>
<p>Average response time: {{ average_response_time | int }} milliseconds</p>
</div> </div>
{% endblock %} {% endblock %}