mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Added new endpoint for getting statistics for a
service, for a user, by a number of days
This commit is contained in:
@@ -243,6 +243,32 @@ def get_service_statistics_for_specific_days(service_id, start, days=1):
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
@service_blueprint.route("/<uuid:service_id>/statistics/user/<uuid:user_id>/<string:start>/<int:days>")
|
||||||
|
def get_service_notification_statistics_by_day_by_user(service_id, user_id, start, days):
|
||||||
|
return jsonify(
|
||||||
|
data=get_service_statistics_for_specific_days_by_user(service_id, user_id, start, int(days))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_service_statistics_for_specific_days_by_user(service_id, user_id, start, days=1):
|
||||||
|
start_date = datetime.strptime(start, "%Y-%m-%d").date()
|
||||||
|
|
||||||
|
if days == 1:
|
||||||
|
stats = {}
|
||||||
|
stats[start] = statistics.format_statistics(
|
||||||
|
dao_fetch_stats_for_service_from_day_for_user(service_id, start_date, user_id)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
stats = {}
|
||||||
|
for d in range(days):
|
||||||
|
new_date = start_date - timedelta(days=d)
|
||||||
|
key = new_date.strftime("%Y-%m-%d")
|
||||||
|
stats[key] = statistics.format_statistics(
|
||||||
|
dao_fetch_stats_for_service_from_day_for_user(service_id, new_date, user_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
return stats
|
||||||
|
|
||||||
|
|
||||||
@service_blueprint.route("", methods=["POST"])
|
@service_blueprint.route("", methods=["POST"])
|
||||||
def create_service():
|
def create_service():
|
||||||
|
|||||||
Reference in New Issue
Block a user