Add statsd annotations for the fact table queries.

This commit is contained in:
Rebecca Law
2020-02-18 14:33:17 +00:00
parent ce253a990b
commit 291c6d6dc9
2 changed files with 26 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
from datetime import datetime, timedelta, time, date
from flask import current_app
from notifications_utils.statsd_decorators import statsd
from notifications_utils.timezones import convert_bst_to_utc, convert_utc_to_bst
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy import func, case, desc, Date, Integer, and_
@@ -29,6 +30,7 @@ from app.models import (
from app.utils import get_london_midnight_in_utc, get_notification_table_to_use
@statsd(namespace="dao")
def fetch_sms_free_allowance_remainder(start_date):
# ASSUMPTION: AnnualBilling has been populated for year.
billing_year = get_financial_year_for_datetime(start_date)
@@ -59,6 +61,7 @@ def fetch_sms_free_allowance_remainder(start_date):
return query
@statsd(namespace="dao")
def fetch_sms_billing_for_all_services(start_date, end_date):
# ASSUMPTION: AnnualBilling has been populated for year.
@@ -111,6 +114,7 @@ def fetch_sms_billing_for_all_services(start_date, end_date):
return query.all()
@statsd(namespace="dao")
def fetch_letter_costs_for_all_services(start_date, end_date):
query = db.session.query(
Organisation.name.label("organisation_name"),
@@ -142,6 +146,7 @@ def fetch_letter_costs_for_all_services(start_date, end_date):
return query.all()
@statsd(namespace="dao")
def fetch_letter_line_items_for_all_services(start_date, end_date):
query = db.session.query(
Organisation.name.label("organisation_name"),
@@ -177,6 +182,7 @@ def fetch_letter_line_items_for_all_services(start_date, end_date):
return query.all()
@statsd(namespace="dao")
def fetch_billing_totals_for_year(service_id, year):
year_start_date, year_end_date = get_financial_year(year)
"""
@@ -225,6 +231,7 @@ def fetch_billing_totals_for_year(service_id, year):
return yearly_data
@statsd(namespace="dao")
def fetch_monthly_billing_for_year(service_id, year):
year_start_datetime, year_end_datetime = get_financial_year(year)
@@ -287,6 +294,7 @@ def fetch_monthly_billing_for_year(service_id, year):
return yearly_data
@statsd(namespace="dao")
def delete_billing_data_for_service_for_day(process_day, service_id):
"""
Delete all ft_billing data for a given service on a given bst_date
@@ -299,6 +307,7 @@ def delete_billing_data_for_service_for_day(process_day, service_id):
).delete()
@statsd(namespace="dao")
def fetch_billing_data_for_day(process_day, service_id=None):
start_date = convert_bst_to_utc(datetime.combine(process_day, time.min))
end_date = convert_bst_to_utc(datetime.combine(process_day + timedelta(days=1), time.min))
@@ -373,12 +382,14 @@ def _query_for_billing_data(table, notification_type, start_date, end_date, serv
return query.all()
@statsd(namespace="dao")
def get_rates_for_billing():
non_letter_rates = Rate.query.order_by(desc(Rate.valid_from)).all()
letter_rates = LetterRate.query.order_by(desc(LetterRate.start_date)).all()
return non_letter_rates, letter_rates
@statsd(namespace="dao")
def get_service_ids_that_need_billing_populated(start_date, end_date):
return db.session.query(
NotificationHistory.service_id
@@ -419,6 +430,7 @@ def get_rate(
return 0
@statsd(namespace="dao")
def update_fact_billing(data, process_day):
non_letter_rates, letter_rates = get_rates_for_billing()
rate = get_rate(non_letter_rates,
@@ -462,6 +474,7 @@ def update_fact_billing(data, process_day):
db.session.commit()
@statsd(namespace="dao")
def create_billing_record(data, rate, process_day):
billing_record = FactBilling(
bst_date=process_day,