-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat/hardware listing backend #492
Conversation
if test["build__valid"] is None: | ||
hardware[compatible]["buildCount"]["null"] += 1 | ||
elif test["build__valid"] is True: | ||
hardware[compatible]["buildCount"]["valid"] += 1 | ||
else: | ||
hardware[compatible]["buildCount"]["invalid"] += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit but you can create a reusable map in utils
for build status
build_status_map = {True: 'valid', False: 'invalid', None: 'null'}
# and then
build_status = build_status_map[test["build__valid"]] # or using a function get_build_status(...)
hardware[compatible]["buildCount"][build_status] += 1
hardwares = set() | ||
tests = Tests.objects.filter( | ||
start_time__gte=start_date, environment_compatible__isnull=False | ||
).values("environment_compatible", "start_time") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not using start_time
here
try: | ||
daysInterval = int(request.GET.get("daysInterval", 3)) | ||
except ValueError: | ||
return JsonResponse({"error": "Invalid daysInterval"}, status=400) | ||
|
||
if daysInterval < 1: | ||
return JsonResponse({"error": "Invalid daysInterval"}, status=400) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are using this logic in 3 different queries, let's create a function to handle this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
def get(self, request): | ||
mode = request.GET.get("mode", "fast") | ||
try: | ||
daysInterval = int(request.GET.get("daysInterval", 3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would either move this logic to a separate function as @lfjnascimento said or use the same variable name as it is in treeView and treeViewFast (interval_days for the variable and intervalInDays for the url parameter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, use a const for the default daysInterval instead of a magic number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!!!
Added two new scripts for hardware listing: - hardware-listing-fast.sh for fast mode - hardware-listing-slow.sh for slow mode These scripts make HTTP requests to the hardware API endpoint with different modes. Part of #445
- Added a new URL pattern for the hardware endpoint in `urls.py`. - Created `HardwareView` in `views/hardwareView.py` to handle hardware data. - Implemented `__getSlowResult` and `__getFastResult` methods to fetch hardware data based on the mode. - Added error handling for invalid `daysInterval` and `mode` parameters. Closes #445
57004fa
to
d5425a9
Compare
- Added build_status_map to map build status to string values. - Implemented parseIntervalInDaysGetParameter to parse and validate intervalInDays parameter. - Created ExceptionWithJsonResponse class to handle exceptions with JSON responses. Part of #445
- Replaced `daysInterval` with `intervalInDays` in `hardwareDetailsView.py` and `treeView.py`. - Updated import statements to include `parseIntervalInDaysGetParameter` and `ExceptionWithJsonResponse`. - Modified `hardware.sh` to use the new `intervalInDays` parameter. - Adjusted error handling to use `ExceptionWithJsonResponse` for better consistency.
d5425a9
to
9b40060
Compare
Add endpoints for the hardware listing page:
This PR adds the endpoint for the hardware listing page, it adds both a fast and slow view that are accessed via query parameters.
How to test