Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Nov 30, 2024
1 parent 5abc6f8 commit 58ca8df
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions backend/app/api/v1/commons/hce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from app.services.search import ElasticService


async def getData(start_datetime: date, end_datetime: date, size:int, offset:int, configpath: str):
async def getData(start_datetime: date, end_datetime: date, size: int, offset: int, configpath: str):
query = {
"size": size,
"from": offset,
Expand All @@ -27,5 +27,5 @@ async def getData(start_datetime: date, end_datetime: date, size:int, offset:int
jobs[['group']] = jobs[['group']].fillna(0)
jobs.fillna('', inplace=True)
if len(jobs) == 0:
return jobs
return({'data':jobs, 'total': 0})
return ({'data':jobs, 'total': response['total']})
2 changes: 1 addition & 1 deletion backend/app/api/v1/commons/ocm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def getData(start_datetime: date, end_datetime: date, size:int, offset:int
tasks = [item['_source'] for item in response['data']]
jobs = pd.json_normalize(tasks)
if len(jobs) == 0:
return jobs
return {"data":jobs,"total": 0}

if 'buildUrl' not in jobs.columns:
jobs.insert(len(jobs.columns), "buildUrl", "")
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/commons/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def getData(start_datetime: date, end_datetime: date, size:int, offset:int
tasks = [item['_source'] for item in response["data"]]
jobs = pd.json_normalize(tasks)
if len(jobs) == 0:
return jobs
return ({'data':jbs, 'total': 0})
jobs[['masterNodesCount', 'workerNodesCount',
'infraNodesCount', 'totalNodesCount']] = jobs[['masterNodesCount', 'workerNodesCount', 'infraNodesCount', 'totalNodesCount']].fillna(0)
jobs.fillna('', inplace=True)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/commons/quay.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def getData(start_datetime: date, end_datetime: date, size, offset, config
tasks = [item['_source'] for item in response['data']]
jobs = pd.json_normalize(tasks)
if len(jobs) == 0:
return jobs
return ({'data':jbs, 'total': 0})

jobs[['masterNodesCount', 'workerNodesCount',
'infraNodesCount', 'totalNodesCount']] = jobs[['masterNodesCount', 'workerNodesCount', 'infraNodesCount', 'totalNodesCount']].fillna(0)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/commons/telco.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ async def getData(start_datetime: date, end_datetime: date, size: int, offset: i

jobs = pd.json_normalize(mapped_list)
if len(jobs) == 0:
return jobs
return {'data':jobs, 'total': 0}

return {'data':jobs, 'total':response['total']}
16 changes: 9 additions & 7 deletions backend/app/api/v1/endpoints/cpt/cptJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
},)
async def jobs(start_date: date = Query(None, description="Start date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-10"]),
end_date: date = Query(None, description="End date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-15"]),
pretty: bool = Query(False, description="Output contet in pretty format."),
pretty: bool = Query(False, description="Output content in pretty format."),
size: int = Query(None, description="Number of jobs to fetch"),
offset: int = Query(None, description="Offset Number to fetch jobs from"),
totalJobs: int = Query(None, description="Offset Number to fetch jobs from")
totalJobs: int = Query(None, description="Total number of jobs")
):
if start_date is None:
start_date = datetime.utcnow().date()
Expand All @@ -66,12 +66,11 @@ async def jobs(start_date: date = Query(None, description="Start date for search
except Exception as e:
print(f"Error fetching data for product {product}: {e}")

num = 0 if totalJobs is None else int(totalJobs)
# on first hit, totalJobs is 0
if totalJobs == 0:
for product in total_dict:
total += int(total_dict[product])

totalJobs =max(total,num)
total += int(total_dict[product])
totalJobs = total
response = {
'startDate': start_date.__str__(),
'endDate': end_date.__str__(),
Expand Down Expand Up @@ -104,6 +103,7 @@ async def fetch_product_async(product, start_date, end_date, size, offset):
def fetch_product(product, start_date, end_date, size, offset):
return asyncio.run(fetch_product_async(product, start_date, end_date, size, offset))


def is_requested_size_available(total_count, offset, requested_size):
"""
Check if the requested size of data is available starting from a given offset.
Expand All @@ -117,6 +117,8 @@ def is_requested_size_available(total_count, offset, requested_size):
bool: True if the requested size is available, False otherwise.
"""
return (offset + requested_size) <= total_count


def calculate_remaining_data(total_count, offset, requested_size):
"""
Calculate the remaining number of data items that can be fetched based on the requested size.
Expand All @@ -130,4 +132,4 @@ def calculate_remaining_data(total_count, offset, requested_size):
int: The number of records that can be fetched, which may be less than or equal to requested_size.
"""
available_data = total_count - offset # Data available from the offset
return min(available_data, requested_size)
return min(available_data, requested_size)
4 changes: 2 additions & 2 deletions backend/app/api/v1/endpoints/cpt/maps/hce.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import date

################################################################
# This will return a Dictionary with from HCE required by the CPT
# This will return a Dictionary from HCE required by the CPT
# endpoint, it contians totalJobs and a Dataframe with the following columns:
# "ciSystem"
# "uuid"
Expand All @@ -26,7 +26,7 @@ async def hceMapper(start_datetime: date, end_datetime: date, size: int, offset:
df["ciSystem"] = "Jenkins"
df["testName"] = df["product"] + ":" + df["test"]
df["product"] = df["group"]
df["jobStatus"] = df['result'].apply(lambda x: "SUCCESS" if x == 'PASS' else "FAILURE")
df["jobStatus"] = df['result'].apply(lambda x: "SUCCESS" if x == "PASS" else "FAILURE")
df["version"] = df['version'].apply(lambda x: x if len(x.split(":")) == 1 else x.split(":")[1][:7])
df["uuid"] = df["result_id"]
df["buildUrl"] = df["link"]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/endpoints/ocm/ocmJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},)
async def jobs(start_date: date = Query(None, description="Start date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-10"]),
end_date: date = Query(None, description="End date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-15"]),
pretty: bool = Query(False, description="Output contet in pretty format."),
pretty: bool = Query(False, description="Output content in pretty format."),
size: int = Query(None, description="Number of jobs to fetch"),
offset: int = Query(None, description="Offset Number to fetch jobs from")):
if start_date is None:
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/v1/endpoints/ocp/ocpJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@router.get('/api/v1/ocp/jobs',
summary="Returns a job list",
description="Returns a list of jobs in the specified dates of requested size. \
description="Returns a list of jobs in the specified dates. \
If not dates are provided the API will default the values. \
`startDate`: will be set to the day of the request minus 5 days.\
`endDate`: will be set to the day of the request.",
Expand All @@ -22,7 +22,7 @@
},)
async def jobs(start_date: date = Query(None, description="Start date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-10"]),
end_date: date = Query(None, description="End date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-15"]),
pretty: bool = Query(False, description="Output contet in pretty format."),
pretty: bool = Query(False, description="Output content in pretty format."),
size: int = Query(None, description="Number of jobs to fetch"),
offset: int = Query(None, description="Offset Number to fetch jobs from")):
if start_date is None:
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/endpoints/quay/quayJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},)
async def jobs(start_date: date = Query(None, description="Start date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-10"]),
end_date: date = Query(None, description="End date for searching jobs, format: 'YYYY-MM-DD'", examples=["2020-11-15"]),
pretty: bool = Query(False, description="Output contet in pretty format."),
pretty: bool = Query(False, description="Output content in pretty format."),
size: int = Query(None, description="Number of jobs to fetch"),
offset: int = Query(None, description="Offset Number to fetch jobs from")):
if start_date is None:
Expand Down
1 change: 0 additions & 1 deletion frontend/src/actions/homeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const fetchOCPJobsData =
payload: {
total: response.data.total,
offset: response.data.offset,
// currProd: response.data.currProd,
},
});

Expand Down

0 comments on commit 58ca8df

Please sign in to comment.