Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.web
Commits
b50b95b4
Commit
b50b95b4
authored
5 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[algorithms][serializers] Pre-commit cleanup
parent
9bc60ab5
No related branches found
No related tags found
1 merge request
!324
Return compatibility information for algorithms and libraries
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/algorithms/serializers.py
+36
-21
36 additions, 21 deletions
beat/web/algorithms/serializers.py
with
36 additions
and
21 deletions
beat/web/algorithms/serializers.py
+
36
−
21
View file @
b50b95b4
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment