mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Add new platform admin page
Added a new platform admin page, at '/plaform-admin-new' which shows
different data. This no longer offers the option to filter by test-key,
only by date, and also gives a more detailed break-down of the
notifications and failures sent with a normal / research key.
The existing platform admin stats page ('/platform-admin') has not been
deleted yet so that both pages can be compared.
This commit is contained in:
@@ -251,3 +251,9 @@ details .arrow {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.bordered-text-box {
|
||||
padding: 5px;
|
||||
outline: 2px solid $black;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,18 @@
|
||||
|
||||
}
|
||||
|
||||
.big-number-dark {
|
||||
@extend %big-number;
|
||||
padding: $gutter-half;
|
||||
position: relative;
|
||||
background: $black;
|
||||
color: $white;
|
||||
|
||||
.big-number-number {
|
||||
@include bold-36($tabular-numbers: true);
|
||||
}
|
||||
}
|
||||
|
||||
.big-number-smaller {
|
||||
|
||||
@extend %big-number;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import itertools
|
||||
from datetime import datetime
|
||||
|
||||
from flask import render_template, request
|
||||
from flask import render_template, request, url_for
|
||||
from flask_login import login_required
|
||||
|
||||
from app import complaint_api_client, service_api_client
|
||||
@@ -10,6 +10,10 @@ from app.main.forms import DateFilterForm
|
||||
from app.statistics_utils import get_formatted_percentage
|
||||
from app.utils import user_is_platform_admin
|
||||
|
||||
COMPLAINT_THRESHOLD = 0.02
|
||||
FAILURE_THRESHOLD = 3
|
||||
ZERO_FAILURE_THRESHOLD = 0
|
||||
|
||||
|
||||
@main.route("/platform-admin")
|
||||
@login_required
|
||||
@@ -38,6 +42,112 @@ def platform_admin():
|
||||
)
|
||||
|
||||
|
||||
@main.route("/platform-admin-new")
|
||||
@login_required
|
||||
@user_is_platform_admin
|
||||
def platform_admin_new():
|
||||
form = DateFilterForm(request.args)
|
||||
api_args = {}
|
||||
|
||||
if form.start_date.data:
|
||||
api_args['start_date'] = form.start_date.data
|
||||
api_args['end_date'] = form.end_date.data or datetime.utcnow().date()
|
||||
|
||||
platform_stats = service_api_client.get_new_aggregate_platform_stats(api_args)
|
||||
number_of_complaints = complaint_api_client.get_complaint_count(api_args)
|
||||
|
||||
return render_template(
|
||||
'views/platform-admin/index_new.html',
|
||||
form=form,
|
||||
global_stats=make_columns(platform_stats, number_of_complaints)
|
||||
)
|
||||
|
||||
|
||||
def is_over_threshold(number, total, threshold):
|
||||
percentage = number / total * 100 if total else 0
|
||||
return percentage > threshold
|
||||
|
||||
|
||||
def get_status_box_data(stats, key, label, threshold=FAILURE_THRESHOLD):
|
||||
return {
|
||||
'number': stats['failures'][key],
|
||||
'label': label,
|
||||
'failing': is_over_threshold(
|
||||
stats['failures'][key],
|
||||
stats['total'],
|
||||
threshold
|
||||
),
|
||||
'percentage': get_formatted_percentage(stats['failures'][key], stats['total'])
|
||||
}
|
||||
|
||||
|
||||
def get_tech_failure_status_box_data(stats):
|
||||
stats = get_status_box_data(stats, 'technical-failure', 'technical failures', ZERO_FAILURE_THRESHOLD)
|
||||
stats.pop('percentage')
|
||||
return stats
|
||||
|
||||
|
||||
def make_columns(global_stats, complaints_number):
|
||||
return [
|
||||
# email
|
||||
{
|
||||
'black_box': {
|
||||
'number': global_stats['email']['total'],
|
||||
'notification_type': 'email'
|
||||
},
|
||||
'other_data': [
|
||||
get_tech_failure_status_box_data(global_stats['email']),
|
||||
get_status_box_data(global_stats['email'], 'permanent-failure', 'permanent failures'),
|
||||
get_status_box_data(global_stats['email'], 'temporary-failure', 'temporary failures'),
|
||||
{
|
||||
'number': complaints_number,
|
||||
'label': 'complaints',
|
||||
'failing': is_over_threshold(complaints_number,
|
||||
global_stats['email']['total'], COMPLAINT_THRESHOLD),
|
||||
'percentage': get_formatted_percentage(complaints_number, global_stats['email']['total']),
|
||||
'url': url_for('main.platform_admin_list_complaints')
|
||||
}
|
||||
],
|
||||
'test_data': {
|
||||
'number': global_stats['email']['test-key'],
|
||||
'label': 'test emails'
|
||||
}
|
||||
},
|
||||
# sms
|
||||
{
|
||||
'black_box': {
|
||||
'number': global_stats['sms']['total'],
|
||||
'notification_type': 'sms'
|
||||
},
|
||||
'other_data': [
|
||||
get_tech_failure_status_box_data(global_stats['sms']),
|
||||
get_status_box_data(global_stats['sms'], 'permanent-failure', 'permanent failures'),
|
||||
get_status_box_data(global_stats['sms'], 'temporary-failure', 'temporary failures')
|
||||
],
|
||||
'test_data': {
|
||||
'number': global_stats['sms']['test-key'],
|
||||
'label': 'test text messages'
|
||||
}
|
||||
},
|
||||
# letter
|
||||
{
|
||||
'black_box': {
|
||||
'number': global_stats['letter']['total'],
|
||||
'notification_type': 'letter'
|
||||
},
|
||||
'other_data': [
|
||||
get_tech_failure_status_box_data(global_stats['letter']),
|
||||
get_status_box_data(global_stats['letter'],
|
||||
'virus-scan-failed', 'virus scan failures', ZERO_FAILURE_THRESHOLD)
|
||||
],
|
||||
'test_data': {
|
||||
'number': global_stats['letter']['test-key'],
|
||||
'label': 'test letters'
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@main.route("/platform-admin/live-services", endpoint='live_services')
|
||||
@main.route("/platform-admin/trial-services", endpoint='trial_services')
|
||||
@login_required
|
||||
|
||||
@@ -79,6 +79,7 @@ class HeaderNavigation(Navigation):
|
||||
'live_services',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'suspend_service',
|
||||
'trial_services',
|
||||
'update_email_branding',
|
||||
@@ -421,6 +422,7 @@ class MainNavigation(Navigation):
|
||||
'organisation_settings',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'platform_admin_list_complaints',
|
||||
'pricing',
|
||||
'privacy',
|
||||
@@ -590,6 +592,7 @@ class OrgNavigation(Navigation):
|
||||
'old_using_notify',
|
||||
'organisations',
|
||||
'platform_admin',
|
||||
'platform_admin_new',
|
||||
'platform_admin_list_complaints',
|
||||
'pricing',
|
||||
'privacy',
|
||||
|
||||
@@ -55,3 +55,19 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{% macro big_number_simple(number, label) %}
|
||||
<div class="big-number-dark bottom-gutter-2-3">
|
||||
<div class="big-number-number">
|
||||
{% if number is number %}
|
||||
{{ "{:,}".format(number) }}
|
||||
{% else %}
|
||||
{{ number }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if label %}
|
||||
<span class="big-number-label">{{ label }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
15
app/templates/components/status-box.html
Normal file
15
app/templates/components/status-box.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% macro status_box(number, label, failing=false, percentage=None, url=None) %}
|
||||
<div class="big-number-with-status">
|
||||
<div class="big-number-status{% if failing %}-failing{% endif %}">
|
||||
{% if url %}
|
||||
<a href="{{ url }}">{{ number }} {{ label }}</a>
|
||||
{% else %}
|
||||
{{ number }} {{ label }}
|
||||
{% endif %}
|
||||
|
||||
{% if percentage %}
|
||||
- {{ percentage }}%
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
59
app/templates/views/platform-admin/index_new.html
Normal file
59
app/templates/views/platform-admin/index_new.html
Normal file
@@ -0,0 +1,59 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/big-number.html" import big_number_simple %}
|
||||
{% from "components/message-count-label.html" import message_count_label %}
|
||||
{% from "components/status-box.html" import status_box %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Platform admin
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Summary
|
||||
</h1>
|
||||
|
||||
<details>
|
||||
<summary>Apply filters</summary>
|
||||
<form autocomplete="off" method="get">
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
</br>
|
||||
<button type="submit" class="button">Filter</button>
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
{{ big_number_simple(
|
||||
noti_type.black_box.number,
|
||||
message_count_label(noti_type.black_box.number, noti_type.black_box.notification_type)
|
||||
) }}
|
||||
|
||||
{% for item in noti_type.other_data %}
|
||||
{{ status_box(
|
||||
number=item.number,
|
||||
label=item.label,
|
||||
failing=item.failing,
|
||||
percentage=item.percentage,
|
||||
url=item.url)
|
||||
}}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
{% for noti_type in global_stats %}
|
||||
<div class="column-third">
|
||||
<div class="bordered-text-box">
|
||||
<span class="big-number-number">{{ "{:,}".format(noti_type.test_data.number) }}</span>
|
||||
{{ noti_type.test_data.label }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user