From 05706f16411ed3bb22e8205333b993a3e4f62e62 Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Mon, 24 Feb 2025 17:24:53 +0530 Subject: [PATCH] (feat:feedback and tokens) count apiKey docs separately --- application/api/user/routes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 0781f574..d9056238 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -1361,6 +1361,7 @@ class GetTokenAnalytics(Resource): except Exception as err: current_app.logger.error(f"Error getting API key: {err}") return make_response(jsonify({"success": False}), 400) + end_date = datetime.datetime.now(datetime.timezone.utc) if filter_option == "last_hour": @@ -1381,7 +1382,6 @@ class GetTokenAnalytics(Resource): }, } } - elif filter_option == "last_24_hour": start_date = end_date - datetime.timedelta(hours=24) group_format = "%Y-%m-%d %H:00" @@ -1400,7 +1400,6 @@ class GetTokenAnalytics(Resource): }, } } - else: if filter_option in ["last_7_days", "last_15_days", "last_30_days"]: filter_days = ( @@ -1442,6 +1441,8 @@ class GetTokenAnalytics(Resource): } if api_key: match_stage["$match"]["api_key"] = api_key + else: + match_stage["$match"]["api_key"] = {"$exists": False} token_usage_data = token_usage_collection.aggregate( [ @@ -1553,6 +1554,8 @@ class GetFeedbackAnalytics(Resource): } if api_key: match_stage["$match"]["api_key"] = api_key + else: + match_stage["$match"]["api_key"] = {"$exists":False} # Unwind the queries array to process each query separately pipeline = [