From 11b5c0736c8fcf474e8d18c1066f7cca5c480627 Mon Sep 17 00:00:00 2001 From: MVarshini Date: Thu, 12 Dec 2024 18:08:12 +0530 Subject: [PATCH] size and offset check --- backend/app/api/v1/endpoints/cpt/cptJobs.py | 9 +++++++-- backend/app/api/v1/endpoints/cpt/maps/hce.py | 3 +-- backend/app/api/v1/endpoints/ocm/ocmJobs.py | 12 +++++------- backend/app/api/v1/endpoints/ocp/ocpJobs.py | 10 +++++----- backend/app/api/v1/endpoints/quay/quayJobs.py | 12 +++++------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/backend/app/api/v1/endpoints/cpt/cptJobs.py b/backend/app/api/v1/endpoints/cpt/cptJobs.py index 5e29303..3c9839c 100644 --- a/backend/app/api/v1/endpoints/cpt/cptJobs.py +++ b/backend/app/api/v1/endpoints/cpt/cptJobs.py @@ -87,16 +87,21 @@ async def jobs( except Exception as e: print(f"Error fetching data for product {product}: {e}") + jobsCount = totalJobs + # The total is determined by summing the counts of all products and is included in the response. + # However, during pagination, if the count of any product drops to zero, + # the total becomes lower than the actual value, which is undesirable. + # on first hit, totalJobs is 0 if totalJobs == 0: for product in total_dict: total += int(total_dict[product]) - totalJobs = total + jobsCount = total response = { "startDate": start_date.__str__(), "endDate": end_date.__str__(), "results": results_df.to_dict("records"), - "total": totalJobs, + "total": jobsCount, "offset": offset + size, } diff --git a/backend/app/api/v1/endpoints/cpt/maps/hce.py b/backend/app/api/v1/endpoints/cpt/maps/hce.py index 9cb07a0..3c812d0 100644 --- a/backend/app/api/v1/endpoints/cpt/maps/hce.py +++ b/backend/app/api/v1/endpoints/cpt/maps/hce.py @@ -1,6 +1,6 @@ from ....commons.hce import getData from datetime import date - +import pandas as pd ################################################################ # This will return a Dictionary from HCE required by the CPT @@ -16,7 +16,6 @@ # "version" # "testName" ################################################################ -import pandas as pd async def hceMapper(start_datetime: date, end_datetime: date, size: int, offset: int): diff --git a/backend/app/api/v1/endpoints/ocm/ocmJobs.py b/backend/app/api/v1/endpoints/ocm/ocmJobs.py index 605df3f..bbcc39c 100644 --- a/backend/app/api/v1/endpoints/ocm/ocmJobs.py +++ b/backend/app/api/v1/endpoints/ocm/ocmJobs.py @@ -51,15 +51,13 @@ async def jobs( status_code=422, ) - if not offset: - offset = 0 - - if not offset and not size: - size = 10000 - offset = 0 - if offset and not size: raise HTTPException(400, f"offset {offset} specified without size") + elif not offset and not size: + size = 10000 + offset = 0 + elif not offset: + offset = 0 results = await getData(start_date, end_date, size, offset, "ocm.elasticsearch") diff --git a/backend/app/api/v1/endpoints/ocp/ocpJobs.py b/backend/app/api/v1/endpoints/ocp/ocpJobs.py index 0733d44..5637b29 100644 --- a/backend/app/api/v1/endpoints/ocp/ocpJobs.py +++ b/backend/app/api/v1/endpoints/ocp/ocpJobs.py @@ -51,13 +51,13 @@ async def jobs( status_code=422, ) - if not offset: - offset = 0 - if not offset and not size: - size = 10000 - offset = 0 if offset and not size: raise HTTPException(400, f"offset {offset} specified without size") + elif not offset and not size: + size = 10000 + offset = 0 + elif not offset: + offset = 0 results = await getData(start_date, end_date, size, offset, "ocp.elasticsearch") jobs = [] diff --git a/backend/app/api/v1/endpoints/quay/quayJobs.py b/backend/app/api/v1/endpoints/quay/quayJobs.py index 7b4eec2..be05d07 100644 --- a/backend/app/api/v1/endpoints/quay/quayJobs.py +++ b/backend/app/api/v1/endpoints/quay/quayJobs.py @@ -51,15 +51,13 @@ async def jobs( status_code=422, ) - if not offset: - offset = 0 - - if not offset and not size: - size = 10000 - offset = 0 - if offset and not size: raise HTTPException(400, f"offset {offset} specified without size") + elif not offset and not size: + size = 10000 + offset = 0 + elif not offset: + offset = 0 results = await getData(start_date, end_date, size, offset, "quay.elasticsearch")