mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Merge branch '1513-provide-notification-stats-data-within-7-days-month-and-year' into socketIO
This commit is contained in:
@@ -20,11 +20,13 @@ from app import (
|
|||||||
)
|
)
|
||||||
from app.formatters import format_date_numeric, format_datetime_numeric, get_time_left
|
from app.formatters import format_date_numeric, format_datetime_numeric, get_time_left
|
||||||
from app.main import main
|
from app.main import main
|
||||||
|
from app.models.user import User
|
||||||
from app.statistics_utils import get_formatted_percentage
|
from app.statistics_utils import get_formatted_percentage
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
DELIVERED_STATUSES,
|
DELIVERED_STATUSES,
|
||||||
FAILURE_STATUSES,
|
FAILURE_STATUSES,
|
||||||
REQUESTED_STATUSES,
|
REQUESTED_STATUSES,
|
||||||
|
SENDING_STATUSES,
|
||||||
service_has_permission,
|
service_has_permission,
|
||||||
)
|
)
|
||||||
from app.utils.csv import Spreadsheet
|
from app.utils.csv import Spreadsheet
|
||||||
@@ -340,6 +342,11 @@ def aggregate_notifications_stats(template_statistics):
|
|||||||
|
|
||||||
|
|
||||||
def get_dashboard_partials(service_id):
|
def get_dashboard_partials(service_id):
|
||||||
|
current_financial_year = get_current_financial_year()
|
||||||
|
current_month = get_current_month_for_financial_year(current_financial_year)
|
||||||
|
start_date = datetime.now().strftime('%Y-%m-%d')
|
||||||
|
days=7
|
||||||
|
|
||||||
all_statistics = template_statistics_client.get_template_statistics_for_service(
|
all_statistics = template_statistics_client.get_template_statistics_for_service(
|
||||||
service_id, limit_days=7
|
service_id, limit_days=7
|
||||||
)
|
)
|
||||||
@@ -352,16 +359,30 @@ def get_dashboard_partials(service_id):
|
|||||||
)
|
)
|
||||||
# These 2 calls will update the dashboard sms allowance count while in trial mode.
|
# These 2 calls will update the dashboard sms allowance count while in trial mode.
|
||||||
billing_api_client.get_monthly_usage_for_service(
|
billing_api_client.get_monthly_usage_for_service(
|
||||||
service_id, get_current_financial_year()
|
service_id, current_financial_year
|
||||||
)
|
)
|
||||||
billing_api_client.create_or_update_free_sms_fragment_limit(
|
billing_api_client.create_or_update_free_sms_fragment_limit(
|
||||||
service_id, free_sms_fragment_limit=free_sms_allowance
|
service_id, free_sms_fragment_limit=free_sms_allowance
|
||||||
)
|
)
|
||||||
|
|
||||||
yearly_usage = billing_api_client.get_annual_usage_for_service(
|
yearly_usage = billing_api_client.get_annual_usage_for_service(
|
||||||
service_id,
|
service_id,
|
||||||
get_current_financial_year(),
|
current_financial_year,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#Previous 7 day stats
|
||||||
|
daily_stats = service_api_client.get_service_notification_statistics_by_day(service_id, start_date=start_date, days=days)
|
||||||
|
|
||||||
|
#Single month stats
|
||||||
|
single_month_notification_stats = service_api_client.get_single_month_notification_stats(service_id, year=current_financial_year, month=current_month)
|
||||||
|
|
||||||
|
#monthly stats by year
|
||||||
|
monthly_stats = format_monthly_stats_to_list(
|
||||||
|
service_api_client.get_monthly_notification_stats(service_id, current_financial_year)["data"]
|
||||||
|
)
|
||||||
|
|
||||||
|
# user=User.from_id(user_id),
|
||||||
|
# single_month_notification_stats = service_api_client.get_single_month_notification_stats_by_user(service_id, user, year=current_financial_year, month=current_month)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"upcoming": render_template(
|
"upcoming": render_template(
|
||||||
"views/dashboard/_upcoming.html",
|
"views/dashboard/_upcoming.html",
|
||||||
@@ -383,6 +404,7 @@ def get_dashboard_partials(service_id):
|
|||||||
),
|
),
|
||||||
"usage": render_template(
|
"usage": render_template(
|
||||||
"views/dashboard/_usage.html",
|
"views/dashboard/_usage.html",
|
||||||
|
monthly_stats=monthly_stats,
|
||||||
**get_annual_usage_breakdown(yearly_usage, free_sms_allowance),
|
**get_annual_usage_breakdown(yearly_usage, free_sms_allowance),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@@ -441,6 +463,8 @@ def aggregate_status_types(counts_dict):
|
|||||||
"{}_counts".format(message_type): {
|
"{}_counts".format(message_type): {
|
||||||
"failed": sum(stats.get(status, 0) for status in FAILURE_STATUSES),
|
"failed": sum(stats.get(status, 0) for status in FAILURE_STATUSES),
|
||||||
"requested": sum(stats.get(status, 0) for status in REQUESTED_STATUSES),
|
"requested": sum(stats.get(status, 0) for status in REQUESTED_STATUSES),
|
||||||
|
"delivered": sum(stats.get(status, 0) for status in DELIVERED_STATUSES),
|
||||||
|
"pending": sum(stats.get(status, 0) for status in SENDING_STATUSES),
|
||||||
}
|
}
|
||||||
for message_type, stats in counts_dict.items()
|
for message_type, stats in counts_dict.items()
|
||||||
}
|
}
|
||||||
@@ -451,6 +475,11 @@ def get_months_for_financial_year(year, time_format="%B"):
|
|||||||
return [month.strftime(time_format) for month in (get_months_for_year(1, 13, year))]
|
return [month.strftime(time_format) for month in (get_months_for_year(1, 13, year))]
|
||||||
|
|
||||||
|
|
||||||
|
def get_current_month_for_financial_year(year):
|
||||||
|
current_month = datetime.now().month
|
||||||
|
return current_month
|
||||||
|
|
||||||
|
|
||||||
def get_months_for_year(start, end, year):
|
def get_months_for_year(start, end, year):
|
||||||
return [datetime(year, month, 1) for month in range(start, end)]
|
return [datetime(year, month, 1) for month in range(start, end)]
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,24 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
|||||||
params={"limit_days": limit_days},
|
params={"limit_days": limit_days},
|
||||||
)["data"]
|
)["data"]
|
||||||
|
|
||||||
|
def get_service_notification_statistics_by_day(self, service_id, start_date=None, days=None):
|
||||||
|
if start_date is None:
|
||||||
|
start_date = datetime.now().strftime('%Y-%m-%d')
|
||||||
|
|
||||||
|
return self.get(
|
||||||
|
"/service/{0}/statistics/{1}/{2}".format(service_id, start_date, days),
|
||||||
|
)["data"]
|
||||||
|
|
||||||
|
def get_single_month_notification_stats(self, service_id, year, month):
|
||||||
|
return self.get(
|
||||||
|
"/service/{0}/notifications/month?year={1}&month={2}".format(service_id, year, month),
|
||||||
|
)
|
||||||
|
|
||||||
|
# def get_single_month_notification_stats(self, service_id, user_id, year, month):
|
||||||
|
# return self.get(
|
||||||
|
# "/service/{0}/notifications/<uuid:user_id>/month?year={1}&month={2}".format(service_id, user_id, year, month),
|
||||||
|
# )
|
||||||
|
|
||||||
def get_services(self, params_dict=None):
|
def get_services(self, params_dict=None):
|
||||||
"""
|
"""
|
||||||
Retrieve a list of services.
|
Retrieve a list of services.
|
||||||
|
|||||||
Reference in New Issue
Block a user