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

[database] Fix protocol view definition generation

The parameter field was missing.
parent ae490fad
No related branches found
No related tags found
1 merge request!44Fix protocol view definition generation
Pipeline #29431 passed
...@@ -455,6 +455,9 @@ class Database(object): ...@@ -455,6 +455,9 @@ class Database(object):
protocol_template = ProtocolTemplate(self.prefix, template_name) protocol_template = ProtocolTemplate(self.prefix, template_name)
view_definition = protocol_template.set(set_name) view_definition = protocol_template.set(set_name)
view_definition["view"] = protocol["views"][set_name]["view"] view_definition["view"] = protocol["views"][set_name]["view"]
parameters = protocol["views"][set_name].get("parameters")
if parameters is not None:
view_definition["parameters"] = parameters
return view_definition return view_definition
......
{
"root_folder": "/tmp/foo/bar",
"protocols": [
{
"name": "test_with_parameters",
"template": "protocol",
"sets": [
{
"name": "double",
"template": "double",
"view": "Parametrized",
"outputs": {
"a": "user/single_integer/1",
"b": "user/single_integer/1",
"sum": "user/single_integer/1"
},
"parameters": {
"threshold": 3
}
}
]
},
{
"name": "test_with_empty_parameters",
"template": "protocol",
"sets": [
{
"name": "double",
"template": "double",
"view": "Parametrized",
"outputs": {
"a": "user/single_integer/1",
"b": "user/single_integer/1",
"sum": "user/single_integer/1"
},
"parameters": {
}
}
]
}
]
}
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
import numpy
from collections import namedtuple
from beat.backend.python.database import View as BaseView
class Parametrized(BaseView):
def index(self, root_folder, parameters):
Entry = namedtuple("Entry", ["out"])
return [Entry(42)]
def get(self, output, index):
obj = self.objs[index]
if output == "out":
return {"value": numpy.int32(obj.out)}
{
"root_folder": "/tmp/foo/bar",
"protocols": [
{
"name": "test_with_parameters",
"template": "double/1",
"views": {
"double": {
"view": "Parametrized",
"parameters": {
"threshold": 3
}
}
}
},
{
"name": "test_with_empty_parameters",
"template": "double/1",
"views": {
"double": {
"view": "Parametrized",
"parameters": {
}
}
}
}
],
"schema_version": 2
}
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
###################################################################################
# #
# Copyright (c) 2019 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions are met: #
# #
# 1. Redistributions of source code must retain the above copyright notice, this #
# list of conditions and the following disclaimer. #
# #
# 2. Redistributions in binary form must reproduce the above copyright notice, #
# this list of conditions and the following disclaimer in the documentation #
# and/or other materials provided with the distribution. #
# #
# 3. Neither the name of the copyright holder nor the names of its contributors #
# may be used to endorse or promote products derived from this software without #
# specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED #
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE #
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE #
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR #
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER #
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, #
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE #
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
# #
###################################################################################
import numpy
from collections import namedtuple
from beat.backend.python.database import View as BaseView
class Parametrized(BaseView):
def index(self, root_folder, parameters):
Entry = namedtuple("Entry", ["out"])
return [Entry(42)]
def get(self, output, index):
obj = self.objs[index]
if output == "out":
return {"value": numpy.int32(obj.out)}
...@@ -129,3 +129,24 @@ def load_protocol_with_two_sets(db_name): ...@@ -129,3 +129,24 @@ def load_protocol_with_two_sets(db_name):
nose.tools.assert_is_not_none(set_["outputs"]["b"]) nose.tools.assert_is_not_none(set_["outputs"]["b"])
nose.tools.assert_is_not_none(set_["outputs"]["c"]) nose.tools.assert_is_not_none(set_["outputs"]["c"])
nose.tools.assert_is_not_none(set_["outputs"]["sum"]) nose.tools.assert_is_not_none(set_["outputs"]["sum"])
# ----------------------------------------------------------
def test_view_definitions():
yield compare_definitions, "integers_db", "double", "double"
yield compare_definitions, "with_parameters", "test_with_parameters", "double"
yield compare_definitions, "with_parameters", "test_with_empty_parameters", "double"
def compare_definitions(db_name, protocol_name, view_name):
db_1 = load("{}/1".format(db_name))
db_1_view_definition = db_1.view_definition(protocol_name, view_name)
db_1_view_definition.pop("template") # Unused property
db_2 = load("{}/2".format(db_name))
db_2_view_definition = db_2.view_definition(protocol_name, view_name)
nose.tools.eq_(db_1_view_definition, db_2_view_definition)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment