mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
first round
This commit is contained in:
@@ -48,16 +48,8 @@ def service_dashboard(service_id):
|
||||
if not current_user.has_permissions("view_activity"):
|
||||
return redirect(url_for("main.choose_template", service_id=service_id))
|
||||
|
||||
yearly_usage = billing_api_client.get_annual_usage_for_service(
|
||||
service_id,
|
||||
get_current_financial_year(),
|
||||
)
|
||||
free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
|
||||
current_service.id,
|
||||
)
|
||||
usage_data = get_annual_usage_breakdown(yearly_usage, free_sms_allowance)
|
||||
sms_sent = usage_data["sms_sent"]
|
||||
sms_allowance_remaining = usage_data["sms_allowance_remaining"]
|
||||
|
||||
|
||||
|
||||
job_response = job_api_client.get_jobs(service_id)["data"]
|
||||
service_data_retention_days = 7
|
||||
@@ -89,24 +81,11 @@ def service_dashboard(service_id):
|
||||
partials=get_dashboard_partials(service_id),
|
||||
jobs=jobs,
|
||||
service_data_retention_days=service_data_retention_days,
|
||||
sms_sent=sms_sent,
|
||||
sms_allowance_remaining=sms_allowance_remaining,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/daily_stats.json")
|
||||
def get_daily_stats():
|
||||
service_id = session.get("service_id")
|
||||
date_range = get_stats_date_range()
|
||||
|
||||
stats = service_api_client.get_service_notification_statistics_by_day(
|
||||
service_id, start_date=date_range["start_date"], days=date_range["days"]
|
||||
)
|
||||
return jsonify(stats)
|
||||
|
||||
|
||||
@main.route("/daily_stats_by_user.json")
|
||||
def get_daily_stats_by_user():
|
||||
@main.route("/services/<uuid:service_id>/daily_stats_by_user.json")
|
||||
def get_daily_stats_by_user(service_id):
|
||||
service_id = session.get("service_id")
|
||||
date_range = get_stats_date_range()
|
||||
user_id = current_user.id
|
||||
@@ -360,7 +339,35 @@ def aggregate_notifications_stats(template_statistics):
|
||||
return notifications
|
||||
|
||||
|
||||
def fetch_daily_stats(service_id):
|
||||
date_range = get_stats_date_range()
|
||||
stats = service_api_client.get_service_notification_statistics_by_day(
|
||||
service_id, start_date='2024-12-31', days=date_range["days"]
|
||||
)
|
||||
return stats
|
||||
|
||||
# Route using the helper
|
||||
@main.route("/daily_stats.json")
|
||||
def get_daily_stats():
|
||||
service_id = session.get("service_id")
|
||||
stats = fetch_daily_stats(service_id) # Use the helper
|
||||
return jsonify(stats)
|
||||
|
||||
|
||||
def get_dashboard_partials(service_id):
|
||||
date_range = get_stats_date_range()
|
||||
yearly_usage = billing_api_client.get_annual_usage_for_service(
|
||||
service_id,
|
||||
get_current_financial_year(),
|
||||
)
|
||||
free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
|
||||
current_service.id,
|
||||
)
|
||||
|
||||
usage_data = get_annual_usage_breakdown(yearly_usage, free_sms_allowance)
|
||||
sms_sent = usage_data["sms_sent"]
|
||||
sms_allowance_remaining = usage_data["sms_allowance_remaining"]
|
||||
activityStats = fetch_daily_stats
|
||||
all_statistics = template_statistics_client.get_template_statistics_for_service(
|
||||
service_id, limit_days=7
|
||||
)
|
||||
@@ -384,6 +391,12 @@ def get_dashboard_partials(service_id):
|
||||
get_current_financial_year(),
|
||||
)
|
||||
return {
|
||||
"activity": render_template(
|
||||
"views/dashboard/_activity.html",
|
||||
activityStats=activityStats,
|
||||
sms_sent=sms_sent,
|
||||
sms_allowance_remaining=sms_allowance_remaining,
|
||||
),
|
||||
"upcoming": render_template(
|
||||
"views/dashboard/_upcoming.html",
|
||||
),
|
||||
|
||||
@@ -334,6 +334,18 @@ def get_status_filters(service, message_type, statistics):
|
||||
|
||||
|
||||
def _get_job_counts(job):
|
||||
print('''
|
||||
|
||||
|
||||
|
||||
job
|
||||
|
||||
|
||||
|
||||
|
||||
''', dir(job))
|
||||
print(job.notifications_sending)
|
||||
|
||||
job_type = job.template_type
|
||||
return [
|
||||
(
|
||||
@@ -358,7 +370,7 @@ def _get_job_counts(job):
|
||||
],
|
||||
[
|
||||
Markup(
|
||||
f"""pending<span class="usa-sr-only">
|
||||
f"""pending--fdsjfisodj<span class="usa-sr-only">
|
||||
{message_count_noun(job.notifications_sending, job_type)}</span>"""
|
||||
),
|
||||
"pending",
|
||||
|
||||
Reference in New Issue
Block a user