Skip to content
Snippets Groups Projects
Commit b50b95b4 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[algorithms][serializers] Pre-commit cleanup

parent 9bc60ab5
No related branches found
No related tags found
1 merge request!324Return compatibility information for algorithms and libraries
......@@ -42,7 +42,7 @@ import simplejson as json
import beat.core.algorithm
#----------------------------------------------------------
# ----------------------------------------------------------
class AlgorithmCreationSerializer(CodeCreationSerializer):
......@@ -51,7 +51,7 @@ class AlgorithmCreationSerializer(CodeCreationSerializer):
beat_core_class = beat.core.algorithm
#----------------------------------------------------------
# ----------------------------------------------------------
class AlgorithmSerializer(CodeSerializer):
......@@ -62,13 +62,16 @@ class AlgorithmSerializer(CodeSerializer):
outputs = serializers.SerializerMethodField()
referencing_experiments = serializers.SerializerMethodField()
referenced_libraries = LibraryReferenceSerializer(many=True)
referenced_dataformats = ReferencedDataFormatSerializer(many=True, source='all_referenced_dataformats')
needed_dataformats = ReferencedDataFormatSerializer(many=True, source='all_needed_dataformats')
referenced_dataformats = ReferencedDataFormatSerializer(
many=True, source="all_referenced_dataformats"
)
needed_dataformats = ReferencedDataFormatSerializer(
many=True, source="all_needed_dataformats"
)
class Meta(CodeSerializer.Meta):
model = Algorithm
def get_result_dataformat(self, obj):
return json.loads(obj.result_dataformat) if obj.result_dataformat else None
......@@ -76,33 +79,45 @@ class AlgorithmSerializer(CodeSerializer):
return json.loads(obj.parameters) if obj.parameters else None
def get_inputs(self, obj):
return map(lambda x: {
'name': x.name,
'dataformat': x.dataformat.fullname(),
'channel': x.channel
}, obj.endpoints.filter(input=True).order_by('name'))
return map(
lambda x: {
"name": x.name,
"dataformat": x.dataformat.fullname(),
"channel": x.channel,
},
obj.endpoints.filter(input=True).order_by("name"),
)
def get_outputs(self, obj):
return map(lambda x: {
'name': x.name,
'dataformat': x.dataformat.fullname(),
'channel': x.channel,
}, obj.endpoints.filter(input=False).order_by('name'))
return map(
lambda x: {
"name": x.name,
"dataformat": x.dataformat.fullname(),
"channel": x.channel,
},
obj.endpoints.filter(input=False).order_by("name"),
)
def get_referencing_experiments(self, obj):
user = self.context.get('user')
experiments = Experiment.objects.for_user(user, True).filter(blocks=obj.blocks.all()).distinct()
user = self.context.get("user")
experiments = (
Experiment.objects.for_user(user, True)
.filter(blocks=obj.blocks.all())
.distinct()
)
serializer = ExperimentSerializer(experiments, many=True)
referencing_experiments = serializer.data
# Put the pending experiments first
return sorted(referencing_experiments, key=itemgetter('creation_date'))
return sorted(referencing_experiments, key=itemgetter("creation_date"))
#----------------------------------------------------------
# ----------------------------------------------------------
class FullAlgorithmSerializer(AlgorithmSerializer):
class Meta(AlgorithmSerializer.Meta):
default_fields = AlgorithmSerializer.Meta.default_fields + AlgorithmSerializer.Meta.extra_fields
default_fields = (
AlgorithmSerializer.Meta.default_fields
+ AlgorithmSerializer.Meta.extra_fields
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment