2017-08-23 15:04:37 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from app import performance_platform_client
|
|
|
|
|
from app.dao.notifications_dao import get_total_sent_notifications_in_date_range
|
|
|
|
|
from app.utils import (
|
|
|
|
|
get_london_midnight_in_utc,
|
2017-08-24 17:08:39 +01:00
|
|
|
get_midnight_for_day_before
|
2017-08-23 15:04:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2017-08-24 17:08:39 +01:00
|
|
|
def send_total_notifications_sent_for_day_stats(date, notification_type, count):
|
|
|
|
|
payload = performance_platform_client.format_payload(
|
2017-08-23 15:04:37 +01:00
|
|
|
dataset='notifications',
|
2017-08-24 17:08:39 +01:00
|
|
|
date=date,
|
|
|
|
|
group_name='channel',
|
|
|
|
|
group_value=notification_type,
|
|
|
|
|
count=count
|
2017-08-23 15:04:37 +01:00
|
|
|
)
|
|
|
|
|
|
2017-08-24 17:08:39 +01:00
|
|
|
performance_platform_client.send_stats_to_performance_platform(payload)
|
|
|
|
|
|
2017-08-24 10:52:47 +01:00
|
|
|
|
2017-08-23 15:04:37 +01:00
|
|
|
def get_total_sent_notifications_yesterday():
|
|
|
|
|
today = datetime.utcnow()
|
|
|
|
|
start_date = get_midnight_for_day_before(today)
|
|
|
|
|
end_date = get_london_midnight_in_utc(today)
|
|
|
|
|
|
|
|
|
|
email_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'email')
|
|
|
|
|
sms_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'sms')
|
2018-03-02 16:05:26 +00:00
|
|
|
letter_count = get_total_sent_notifications_in_date_range(start_date, end_date, 'letter')
|
2017-08-23 15:04:37 +01:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"start_date": start_date,
|
|
|
|
|
"email": {
|
|
|
|
|
"count": email_count
|
|
|
|
|
},
|
|
|
|
|
"sms": {
|
|
|
|
|
"count": sms_count
|
2018-03-02 16:05:26 +00:00
|
|
|
},
|
|
|
|
|
"letter": {
|
|
|
|
|
"count": letter_count
|
|
|
|
|
},
|
2017-08-23 15:04:37 +01:00
|
|
|
}
|