mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
Add usage to the dashboard
Takes the number of emails and SMS fragments sent from: https://github.com/alphagov/notifications-api/pull/273 Using these numbers it’s possible to show: - how much of your allowance is left - or how much you have spent For now the allowance and rates are hard coded. Only for users that have manage service.
This commit is contained in:
@@ -80,6 +80,16 @@ def template_history(service_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/usage")
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def usage(service_id):
|
||||
return render_template(
|
||||
'views/usage.html',
|
||||
**get_dashboard_statistics_for_service(service_id)
|
||||
)
|
||||
|
||||
|
||||
def add_rates_to(delivery_statistics):
|
||||
|
||||
keys = [
|
||||
@@ -148,11 +158,25 @@ def aggregate_usage(template_statistics):
|
||||
|
||||
|
||||
def get_dashboard_statistics_for_service(service_id):
|
||||
|
||||
usage = service_api_client.get_service_usage(service_id)
|
||||
sms_free_allowance = 250000
|
||||
sms_rate = 0.018
|
||||
|
||||
sms_sent = usage['data'].get('sms_count', 0)
|
||||
emails_sent = usage['data'].get('email_count', 0)
|
||||
|
||||
return {
|
||||
'statistics': add_rates_to(
|
||||
statistics_api_client.get_statistics_for_service(service_id, limit_days=7)['data']
|
||||
),
|
||||
'template_statistics': aggregate_usage(
|
||||
template_statistics_client.get_template_statistics_for_service(service_id, limit_days=7)
|
||||
)
|
||||
),
|
||||
'emails_sent': emails_sent,
|
||||
'sms_free_allowance': sms_free_allowance,
|
||||
'sms_sent': sms_sent,
|
||||
'sms_allowance_remaining': max(0, (sms_free_allowance - sms_sent)),
|
||||
'sms_chargeable': max(0, sms_sent - sms_free_allowance),
|
||||
'sms_rate': sms_rate,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user