2021-03-10 10:35:58 +00:00
|
|
|
from datetime import datetime, timedelta
|
2021-03-11 12:34:22 +00:00
|
|
|
from itertools import groupby
|
|
|
|
|
from operator import itemgetter
|
|
|
|
|
from statistics import mean
|
2021-03-10 10:35:58 +00:00
|
|
|
|
2023-06-12 17:00:20 -04:00
|
|
|
import pytz
|
|
|
|
|
from flask import render_template
|
2021-03-10 10:35:58 +00:00
|
|
|
|
2021-03-11 13:29:46 +00:00
|
|
|
from app import performance_dashboard_api_client, status_api_client
|
2021-03-10 10:35:58 +00:00
|
|
|
from app.main import main
|
|
|
|
|
|
|
|
|
|
|
2021-03-11 10:40:44 +00:00
|
|
|
@main.route("/performance")
|
|
|
|
|
def performance():
|
2021-03-11 10:52:03 +00:00
|
|
|
stats = performance_dashboard_api_client.get_performance_dashboard_stats(
|
2023-06-12 17:00:20 -04:00
|
|
|
start_date=(datetime.now(pytz.utc) - timedelta(days=7)).date(),
|
|
|
|
|
end_date=datetime.now(pytz.utc).date(),
|
2021-03-11 10:52:03 +00:00
|
|
|
)
|
2023-07-12 12:09:44 -04:00
|
|
|
stats['organizations_using_notify'] = sorted(
|
2021-03-11 12:34:22 +00:00
|
|
|
[
|
|
|
|
|
{
|
2023-07-12 12:09:44 -04:00
|
|
|
'organization_name': organization_name or 'No organization',
|
2021-03-11 12:34:22 +00:00
|
|
|
'count_of_live_services': len(list(group)),
|
|
|
|
|
}
|
2023-07-12 12:09:44 -04:00
|
|
|
for organization_name, group in groupby(
|
2021-03-11 12:34:22 +00:00
|
|
|
stats['services_using_notify'],
|
2023-07-12 12:09:44 -04:00
|
|
|
itemgetter('organization_name'),
|
2021-03-11 12:34:22 +00:00
|
|
|
)
|
|
|
|
|
],
|
2023-07-12 12:09:44 -04:00
|
|
|
key=itemgetter('organization_name'),
|
2021-03-11 12:34:22 +00:00
|
|
|
)
|
|
|
|
|
stats['average_percentage_under_10_seconds'] = mean([
|
|
|
|
|
row['percentage_under_10_seconds']
|
|
|
|
|
for row in stats['processing_time']
|
|
|
|
|
] or [0])
|
2023-07-12 12:09:44 -04:00
|
|
|
stats['count_of_live_services_and_organizations'] = (
|
|
|
|
|
status_api_client.get_count_of_live_services_and_organizations()
|
2021-03-11 13:29:46 +00:00
|
|
|
)
|
2021-03-11 10:52:03 +00:00
|
|
|
return render_template(
|
|
|
|
|
'views/performance.html',
|
|
|
|
|
**stats
|
|
|
|
|
)
|