Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: Filter Heartbeats #2108

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/dao/fact_notification_status_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def fetch_notification_status_for_service_by_month(start_date, end_date, service
)


def fetch_delivered_notification_stats_by_month():
return (
def fetch_delivered_notification_stats_by_month(filter_heartbeat=None):
query = (
db.session.query(
func.date_trunc("month", FactNotificationStatus.bst_date).cast(db.Text).label("month"),
FactNotificationStatus.notification_type,
Expand All @@ -169,8 +169,17 @@ def fetch_delivered_notification_stats_by_month():
func.date_trunc("month", FactNotificationStatus.bst_date).desc(),
FactNotificationStatus.notification_type,
)
.all()
)
if filter_heartbeat:
query = query.filter(
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_LOW"],
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_MEDIUM"],
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_EMAIL_HIGH"],
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_SMS_LOW"],
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_SMS_MEDIUM"],
FactNotificationStatus.template_id != current_app.config["HEARTBEAT_TEMPLATE_SMS_HIGH"],
)
return query.all()


def fetch_notification_stats_for_trial_services():
Expand Down
2 changes: 1 addition & 1 deletion app/dao/services_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def dao_count_live_services():
).count()


def dao_fetch_live_services_data():
def dao_fetch_live_services_data(filter_heartbeats=None):
year_start_date, year_end_date = get_current_financial_year()

most_recent_annual_billing = (
Expand Down
6 changes: 4 additions & 2 deletions app/service/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@

@service_blueprint.route("/live-services-data", methods=["GET"])
def get_live_services_data():
data = dao_fetch_live_services_data()
filter_heartbeats = request.args.get("filter_heartbeats", None)
data = dao_fetch_live_services_data(filter_heartbeats=filter_heartbeats)
return jsonify(data=data)


@service_blueprint.route("/delivered-notifications-stats-by-month-data", methods=["GET"])
def get_delivered_notification_stats_by_month_data():
return jsonify(data=fetch_delivered_notification_stats_by_month())
filter_heartbeats = request.args.get("filter_heartbeats", None)
return jsonify(data=fetch_delivered_notification_stats_by_month(filter_heartbeats=filter_heartbeats))
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved


@service_blueprint.route("/<uuid:service_id>", methods=["GET"])
Expand Down
Loading