Skip to content

Commit

Permalink
Add AlgorithmInterfaceSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan committed Jan 24, 2025
1 parent 994c43b commit bc4ad33
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/grandchallenge/algorithms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from grandchallenge.algorithms.models import (
Algorithm,
AlgorithmImage,
AlgorithmInterface,
AlgorithmModel,
Job,
)
Expand All @@ -38,12 +39,28 @@
logger = logging.getLogger(__name__)


class AlgorithmInterfaceSerializer(serializers.ModelSerializer):
"""Serializer without hyperlinks for internal use"""

inputs = ComponentInterfaceSerializer(many=True, read_only=True)
outputs = ComponentInterfaceSerializer(many=True, read_only=True)

class Meta:
model = AlgorithmInterface
fields = [
"inputs",
"outputs",
]


class AlgorithmSerializer(serializers.ModelSerializer):
average_duration = SerializerMethodField()
# TODO remove inputs and outputs
inputs = ComponentInterfaceSerializer(many=True, read_only=True)
outputs = ComponentInterfaceSerializer(many=True, read_only=True)
logo = URLField(source="logo.x20.url", read_only=True)
url = URLField(source="get_absolute_url", read_only=True)
interfaces = AlgorithmInterfaceSerializer(many=True)

class Meta:
model = Algorithm
Expand All @@ -58,6 +75,7 @@ class Meta:
"average_duration",
"inputs",
"outputs",
"interfaces",
]

def get_average_duration(self, obj: Algorithm) -> float | None:
Expand Down Expand Up @@ -108,6 +126,7 @@ class JobSerializer(serializers.ModelSerializer):

algorithm_image = StringRelatedField()

algorithm_interface = AlgorithmInterfaceSerializer(read_only=True)
inputs = ComponentInterfaceValueSerializer(many=True)
outputs = ComponentInterfaceValueSerializer(many=True)

Expand Down Expand Up @@ -160,7 +179,6 @@ class HyperlinkedJobSerializer(JobSerializer):
view_name="api:algorithm-detail",
read_only=True,
)

inputs = HyperlinkedComponentInterfaceValueSerializer(many=True)
outputs = HyperlinkedComponentInterfaceValueSerializer(many=True)

Expand Down

0 comments on commit bc4ad33

Please sign in to comment.