Skip to content
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

Merged
merged 4 commits into from
Nov 4, 2024
Merged

Conversation

WilsonNet
Copy link
Collaborator

@WilsonNet WilsonNet commented Nov 1, 2024

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

  1. Run the server
  2. Run both of the scripts for the fast and slow path.

@WilsonNet WilsonNet changed the base branch from main to epic/hardware November 1, 2024 15:38
@WilsonNet WilsonNet changed the title feat/hardware listing feat/hardware listing backend Nov 1, 2024
Comment on lines 29 to 34
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
Copy link
Collaborator

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")
Copy link
Collaborator

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

Comment on lines 55 to 61
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)
Copy link
Collaborator

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

Copy link
Collaborator

@lfjnascimento lfjnascimento left a 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))
Copy link
Collaborator

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)

Copy link
Collaborator

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

Copy link
Collaborator

@Francisco2002 Francisco2002 left a 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
- 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.
@WilsonNet WilsonNet merged commit 11b5d66 into epic/hardware Nov 4, 2024
5 checks passed
@WilsonNet WilsonNet deleted the feat/hardware-listing branch November 13, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants