Skip to content

Commit

Permalink
Merge branch 'main' into add-issue-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow authored Jan 18, 2025
2 parents 607010e + 1d40978 commit b8d449d
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 111 deletions.
34 changes: 34 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Summary
Brief description of what this PR does. (tl;dr).

### List of Changes
* Modified class X
* Added model Y
* Fixed problem Z
* etc.

### Related Issues
If the PR closes or is related to an issue, reference it here.
For example, "Closes #123", "Fixes #456" or "Relates to #741" .

## Detailed Description
A clear and detailed description of the changes, how they solve/fix the related issues.

Mention potential side effects or risks associated with the changes, if applicable.

### How to Test the Changes
Instructions on how to test the changes Include references to automated and/or manual tests that were created/used to test the changes.

### Screenshots
If applicable, add screenshots to help explain this PR (ex. Before and after for UI changes).

## Deployment Notes
Include instructions if this PR requires specific steps for its deployment (database migrations, config changes, etc.)

## Checklist

- [ ] I have tested these changes appropriately.
- [ ] I have added and/or modified relevant tests.
- [ ] I updated relevant documentation or comments.
- [ ] I have verified that this PR follows the project's coding standards.
- [ ] Any dependent changes have already been merged to main.
5 changes: 5 additions & 0 deletions ami/jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ class JobType:
name: str
key: str

# @TODO Consider adding custom vocabulary for job types to be used in the UI
# verb: str = "Sync"
# present_participle: str = "syncing"
# past_participle: str = "synced"

@classmethod
def run(cls, job: "Job"):
"""
Expand Down
11 changes: 9 additions & 2 deletions ami/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from django.db.models.query import QuerySet
from django.forms import IntegerField
from django.utils import timezone
from drf_spectacular.utils import extend_schema
from rest_framework.decorators import action
from rest_framework.response import Response

from ami.main.api.views import DefaultViewSet
from ami.utils.fields import url_boolean_param
from ami.utils.requests import get_active_project, project_id_doc_param

from .models import Job, JobState, MLJob
from .serializers import JobListSerializer, JobSerializer
Expand Down Expand Up @@ -35,7 +37,6 @@ class JobViewSet(DefaultViewSet):
"""

queryset = Job.objects.select_related(
"project",
"deployment",
"pipeline",
"source_image_collection",
Expand Down Expand Up @@ -128,7 +129,9 @@ def perform_create(self, serializer):

def get_queryset(self) -> QuerySet:
jobs = super().get_queryset()

project = get_active_project(self.request)
if project:
jobs = jobs.filter(project=project)
cutoff_hours = IntegerField(required=False, min_value=0).clean(
self.request.query_params.get("cutoff_hours", Job.FAILED_CUTOFF_HOURS)
)
Expand All @@ -138,3 +141,7 @@ def get_queryset(self) -> QuerySet:
status=JobState.failed_states(),
updated_at__lt=cutoff_datetime,
)

@extend_schema(parameters=[project_id_doc_param])
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)
43 changes: 30 additions & 13 deletions ami/main/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,40 @@ class Meta:
]


class JobTypeSerializer(serializers.Serializer):
"""
Serializer for the JobType json field in the Job model.
This is duplicated from ami.jobs.serializers to avoid circular imports.
but it is extremely simple.
"""

name = serializers.CharField(read_only=True)
key = serializers.SlugField(read_only=True)


class JobStatusSerializer(DefaultSerializer):
job_type = JobTypeSerializer(read_only=True)

class Meta:
model = Job
fields = [
"id",
"details",
"status",
"job_type",
"created_at",
"updated_at",
]


class DeploymentListSerializer(DefaultSerializer):
events = serializers.SerializerMethodField()
occurrences = serializers.SerializerMethodField()
project = ProjectNestedSerializer(read_only=True)
device = DeviceNestedSerializer(read_only=True)
research_site = SiteNestedSerializer(read_only=True)
jobs = JobStatusSerializer(many=True, read_only=True)

class Meta:
model = Deployment
Expand All @@ -156,6 +184,7 @@ class Meta:
"last_date",
"device",
"research_site",
"jobs",
]

def get_events(self, obj):
Expand Down Expand Up @@ -503,7 +532,7 @@ def get_occurrence_images(self, obj):

# request = self.context.get("request")
# project_id = request.query_params.get("project") if request else None
project_id = self.context["request"].query_params["project"]
project_id = self.context["request"].query_params["project_id"]
classification_threshold = get_active_classification_threshold(self.context["request"])

return obj.occurrence_images(
Expand Down Expand Up @@ -849,18 +878,6 @@ class Meta:
]


class JobStatusSerializer(DefaultSerializer):
class Meta:
model = Job
fields = [
"id",
"details",
"status",
"created_at",
"updated_at",
]


class SourceImageCollectionNestedSerializer(DefaultSerializer):
class Meta:
model = SourceImageCollection
Expand Down
Loading

0 comments on commit b8d449d

Please sign in to comment.