remove letters from platform_stats

This commit is contained in:
stvnrlly
2023-02-24 13:35:58 -05:00
parent 030d22bd6d
commit 0a3260c030
4 changed files with 38 additions and 64 deletions

View File

@@ -7,7 +7,6 @@ from app.dao.fact_billing_dao import (
fetch_billing_details_for_all_services,
fetch_daily_sms_provider_volumes_for_platform,
fetch_daily_volumes_for_platform,
fetch_letter_costs_and_totals_for_all_services,
fetch_sms_billing_for_all_services,
fetch_volumes_by_service,
)
@@ -73,7 +72,7 @@ def get_data_for_billing_report():
start_date, end_date = validate_date_range_is_within_a_financial_year(start_date, end_date)
sms_costs = fetch_sms_billing_for_all_services(start_date, end_date)
letter_overview = fetch_letter_costs_and_totals_for_all_services(start_date, end_date)
# letter_overview = fetch_letter_costs_and_totals_for_all_services(start_date, end_date)
combined = {}
for s in sms_costs:
@@ -85,29 +84,29 @@ def get_data_for_billing_report():
"service_name": s.service_name,
"sms_cost": float(s.sms_cost),
"sms_chargeable_units": s.chargeable_billable_sms,
"total_letters": 0,
"letter_cost": 0,
# "total_letters": 0,
# "letter_cost": 0,
}
combined[s.service_id] = entry
for data in letter_overview:
if data.service_id in combined:
combined[data.service_id].update(
{'total_letters': data.total_letters, 'letter_cost': float(data.letter_cost)}
)
# for data in letter_overview:
# if data.service_id in combined:
# combined[data.service_id].update(
# {'total_letters': data.total_letters, 'letter_cost': float(data.letter_cost)}
# )
else:
letter_entry = {
"organisation_id": str(data.organisation_id) if data.organisation_id else "",
"organisation_name": data.organisation_name or "",
"service_id": str(data.service_id),
"service_name": data.service_name,
"sms_cost": 0,
"sms_chargeable_units": 0,
"total_letters": data.total_letters,
"letter_cost": float(data.letter_cost),
}
combined[data.service_id] = letter_entry
# else:
# letter_entry = {
# "organisation_id": str(data.organisation_id) if data.organisation_id else "",
# "organisation_name": data.organisation_name or "",
# "service_id": str(data.service_id),
# "service_name": data.service_name,
# "sms_cost": 0,
# "sms_chargeable_units": 0,
# "total_letters": data.total_letters,
# "letter_cost": float(data.letter_cost),
# }
# combined[data.service_id] = letter_entry
billing_details = fetch_billing_details_for_all_services()
for service in billing_details:
@@ -144,8 +143,8 @@ def daily_volumes_report():
"sms_fragment_totals": int(row.sms_fragment_totals),
"sms_chargeable_units": int(row.sms_chargeable_units),
"email_totals": int(row.email_totals),
"letter_totals": int(row.letter_totals),
"letter_sheet_totals": int(row.letter_sheet_totals)
# "letter_totals": int(row.letter_totals),
# "letter_sheet_totals": int(row.letter_sheet_totals)
})
return jsonify(report)
@@ -189,16 +188,16 @@ def volumes_by_service_report():
"sms_notifications": int(row.sms_notifications),
"sms_chargeable_units": int(row.sms_chargeable_units),
"email_totals": int(row.email_totals),
"letter_totals": int(row.letter_totals),
"letter_sheet_totals": int(row.letter_sheet_totals),
"letter_cost": float(row.letter_cost),
# "letter_totals": int(row.letter_totals),
# "letter_sheet_totals": int(row.letter_sheet_totals),
# "letter_cost": float(row.letter_cost),
})
return jsonify(report)
def format_letter_rate(number):
if number >= 1:
return f"£{number:,.2f}"
# def format_letter_rate(number):
# if number >= 1:
# return f"£{number:,.2f}"
return f"{number * 100:.0f}p"
# return f"{number * 100:.0f}p"

View File

@@ -37,7 +37,7 @@ def format_admin_stats(statistics):
def create_stats_dict():
stats_dict = {}
for template in NOTIFICATION_TYPES:
for template in ['sms', 'email']: # TODO: return to NOTIFICATION_TYPES after removing letters
stats_dict[template] = {}
for status in ('total', 'test-key'):

View File

@@ -72,11 +72,6 @@ def test_get_platform_stats_with_real_query(admin_request, notify_db_session):
'virus-scan-failed': 0, 'temporary-failure': 0, 'permanent-failure': 0, 'technical-failure': 0},
'total': 4, 'test-key': 0
},
'letter': {
'failures': {
'virus-scan-failed': 0, 'temporary-failure': 0, 'permanent-failure': 0, 'technical-failure': 0},
'total': 0, 'test-key': 0
},
'sms': {
'failures': {
'virus-scan-failed': 0, 'temporary-failure': 0, 'permanent-failure': 0, 'technical-failure': 0},
@@ -141,8 +136,6 @@ def test_get_data_for_billing_report(notify_db_session, admin_request):
assert response[0]["service_id"] == str(fixtures["service_with_sms_without_org"].id)
assert response[0]["sms_cost"] == 0.33
assert response[0]["sms_chargeable_units"] == 3
assert response[0]["total_letters"] == 0
assert response[0]["letter_cost"] == 0
assert response[0]["purchase_order_number"] == "sms purchase order number"
assert response[0]["contact_names"] == "sms billing contact names"
assert response[0]["contact_email_addresses"] == "sms@billing.contact email@addresses.gov.uk"
@@ -160,11 +153,11 @@ def test_daily_volumes_report(
)
assert len(response) == 3
assert response[0] == {'day': '2022-03-01', 'email_totals': 10, 'letter_sheet_totals': 0,
'letter_totals': 0, 'sms_chargeable_units': 2, 'sms_fragment_totals': 2, 'sms_totals': 1}
assert response[1] == {'day': '2022-03-03', 'email_totals': 0, 'letter_sheet_totals': 0, 'letter_totals': 0,
assert response[0] == {'day': '2022-03-01', 'email_totals': 10,
'sms_chargeable_units': 2, 'sms_fragment_totals': 2, 'sms_totals': 1}
assert response[1] == {'day': '2022-03-03', 'email_totals': 0,
'sms_chargeable_units': 2, 'sms_fragment_totals': 2, 'sms_totals': 2}
assert response[2] == {'day': '2022-03-08', 'email_totals': 0, 'letter_sheet_totals': 0, 'letter_totals': 0,
assert response[2] == {'day': '2022-03-08', 'email_totals': 0,
'sms_chargeable_units': 4, 'sms_fragment_totals': 4, 'sms_totals': 2}
@@ -181,26 +174,22 @@ def test_volumes_by_service_report(
assert len(response) == 5
# since we are using a pre-set up fixture, we only care about some of the results
assert response[0] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0,
'letter_sheet_totals': 0, 'letter_totals': 0,
assert response[0] == {'email_totals': 0, 'free_allowance': 10,
'organisation_id': str(fixture['org_1'].id),
'organisation_name': fixture['org_1'].name,
'service_id': str(fixture['service_1_sms_and_letter'].id),
'service_name': fixture['service_1_sms_and_letter'].name,
'sms_chargeable_units': 2, 'sms_notifications': 1}
assert response[1] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
'letter_totals': 0, 'organisation_id': str(fixture['org_1'].id),
assert response[1] == {'email_totals': 0, 'free_allowance': 10, 'organisation_id': str(fixture['org_1'].id),
'organisation_name': fixture['org_1'].name,
'service_id': str(fixture['service_with_out_ft_billing_this_year'].id),
'service_name': fixture['service_with_out_ft_billing_this_year'].name,
'sms_chargeable_units': 0, 'sms_notifications': 0}
assert response[3] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
assert response[3] == {'email_totals': 0, 'free_allowance': 10, 'organisation_id': '', 'organisation_name': '',
'service_id': str(fixture['service_with_sms_without_org'].id),
'service_name': fixture['service_with_sms_without_org'].name,
'sms_chargeable_units': 0, 'sms_notifications': 0}
assert response[4] == {'email_totals': 0, 'free_allowance': 10, 'letter_cost': 0.0, 'letter_sheet_totals': 0,
'letter_totals': 0, 'organisation_id': '', 'organisation_name': '',
assert response[4] == {'email_totals': 0, 'free_allowance': 10, 'organisation_id': '', 'organisation_name': '',
'service_id': str(fixture['service_with_sms_within_allowance'].id),
'service_name': fixture['service_with_sms_within_allowance'].name,
'sms_chargeable_units': 0, 'sms_notifications': 0}

View File

@@ -95,12 +95,6 @@ def test_create_stats_dict():
'permanent-failure': 0,
'temporary-failure': 0,
'virus-scan-failed': 0}},
'letter': {'total': 0,
'test-key': 0,
'failures': {'technical-failure': 0,
'permanent-failure': 0,
'temporary-failure': 0,
'virus-scan-failed': 0}}
}
@@ -108,7 +102,6 @@ def test_format_admin_stats_only_includes_test_key_notifications_in_test_key_sec
rows = [
NewStatsRow('email', 'technical-failure', 'test', 3),
NewStatsRow('sms', 'permanent-failure', 'test', 4),
NewStatsRow('letter', 'virus-scan-failed', 'test', 5),
]
stats_dict = format_admin_stats(rows)
@@ -120,10 +113,6 @@ def test_format_admin_stats_only_includes_test_key_notifications_in_test_key_sec
assert stats_dict['sms']['failures']['permanent-failure'] == 0
assert stats_dict['sms']['test-key'] == 4
assert stats_dict['letter']['total'] == 0
assert stats_dict['letter']['failures']['virus-scan-failed'] == 0
assert stats_dict['letter']['test-key'] == 5
def test_format_admin_stats_counts_non_test_key_notifications_correctly():
rows = [
@@ -131,7 +120,6 @@ def test_format_admin_stats_counts_non_test_key_notifications_correctly():
NewStatsRow('email', 'created', 'team', 3),
NewStatsRow('sms', 'temporary-failure', 'normal', 6),
NewStatsRow('sms', 'sent', 'normal', 2),
NewStatsRow('letter', 'pending-virus-check', 'normal', 1),
]
stats_dict = format_admin_stats(rows)
@@ -141,8 +129,6 @@ def test_format_admin_stats_counts_non_test_key_notifications_correctly():
assert stats_dict['sms']['total'] == 8
assert stats_dict['sms']['failures']['permanent-failure'] == 0
assert stats_dict['letter']['total'] == 1
def _stats(requested, delivered, failed):
return {'requested': requested, 'delivered': delivered, 'failed': failed}