mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
This commit adds two new sections to the dashboard 1. A banner telling you about trial mode, including a count of how many messages you have left today, which is a restriction of trial mode 2. Panels with counts of how many emails and text messages have been sent in a day, plus the failure rates for each It does **not**: - link through to any further information about what trial mode is (coming later) - link through to pages for the failure rates (coming later) - change the ‘recent jobs’ section to ‘recent notifications’
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from flask import (
|
|
render_template,
|
|
session,
|
|
flash
|
|
)
|
|
|
|
from flask_login import login_required
|
|
from app.main import main
|
|
from app.main.dao.services_dao import get_service_by_id
|
|
from app.main.dao import templates_dao
|
|
from app import job_api_client, statistics_api_client
|
|
|
|
|
|
@main.route("/services/<service_id>/dashboard")
|
|
@login_required
|
|
def service_dashboard(service_id):
|
|
templates = templates_dao.get_service_templates(service_id)['data']
|
|
jobs = job_api_client.get_job(service_id)['data']
|
|
|
|
service = get_service_by_id(service_id)
|
|
session['service_name'] = service['data']['name']
|
|
session['service_id'] = service['data']['id']
|
|
|
|
if session.get('invited_user'):
|
|
session.pop('invited_user', None)
|
|
service_name = service['data']['name']
|
|
message = 'You have successfully accepted your invitation and been added to {}'.format(service_name)
|
|
flash(message, 'default_with_tick')
|
|
|
|
statistics = statistics_api_client.get_statistics_for_service(service_id)['data']
|
|
|
|
return render_template(
|
|
'views/dashboard/dashboard.html',
|
|
jobs=jobs[:5],
|
|
more_jobs_to_show=(len(jobs) > 5),
|
|
free_text_messages_remaining='250,000',
|
|
spent_this_month='0.00',
|
|
service=service['data'],
|
|
statistics=expand_statistics(statistics),
|
|
templates=templates,
|
|
service_id=str(service_id))
|
|
|
|
|
|
def expand_statistics(statistics, danger_zone=25):
|
|
|
|
if not statistics or not statistics[0]:
|
|
return {}
|
|
|
|
today = statistics[0]
|
|
|
|
today.update({
|
|
'emails_failure_rate': int(today['emails_error'] / today['emails_requested'] * 100),
|
|
'sms_failure_rate': int(today['sms_error'] / today['sms_requested'] * 100)
|
|
})
|
|
|
|
today.update({
|
|
'emails_percentage_of_danger_zone': min(today['emails_failure_rate'] / (danger_zone / 100), 100),
|
|
'sms_percentage_of_danger_zone': min(today['sms_failure_rate'] / (danger_zone / 100), 100)
|
|
})
|
|
|
|
return today
|