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

[test][databases][simple_rawdata_access] Add new version following V2 implementation

parent 83b0004a
No related branches found
No related tags found
1 merge request!28Add protocoltemplates
{
"description": "A test database that emits integers",
"root_folder": "/this/database/does/not/require/a/path",
"environment": {
"name": "Example databases",
"version": "1.4.1"
},
"direct_rawdata_access": true,
"protocols": [
{
"name": "protocol",
"template": "test_integers/1",
"views": {
"set": {
"view": "View",
"parameters": {}
},
"set2": {
"view": "View2",
"parameters": {}
}
}
},
{
"name": "protocol2",
"template": "test_integers/1",
"views": {
"set": {
"view": "LargeView",
"parameters": {}
},
"set2": {
"view": "View2",
"parameters": {}
}
}
},
{
"name": "10_numbers",
"template": "one_block/1",
"views": {
"numbers": {
"view": "View10",
"parameters": {}
}
}
},
{
"name": "duo",
"template": "one_block_two_inputs/1",
"views": {
"numbers": {
"view": "ViewDuo",
"parameters": {}
}
}
}
],
"schema_version": 2
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy as np
from collections import namedtuple
from beat.backend.python.database import View as BaseView
#----------------------------------------------------------
class View(BaseView):
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
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': np.int32(obj.out)
}
#----------------------------------------------------------
class View2(BaseView):
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['out'])
return [
Entry(53),
]
def get(self, output, index):
obj = self.objs[index]
if output == 'out':
return {
'value': np.int32(obj.out)
}
#----------------------------------------------------------
class LargeView(BaseView):
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['out'])
return [
Entry(0),
Entry(1),
Entry(2),
Entry(3),
Entry(4),
]
def get(self, output, index):
obj = self.objs[index]
if output == 'out':
return {
'value': np.int32(obj.out)
}
#----------------------------------------------------------
class View10(BaseView):
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['out'])
return [
Entry(0),
Entry(1),
Entry(2),
Entry(3),
Entry(4),
Entry(5),
Entry(6),
Entry(7),
Entry(8),
Entry(9),
]
def get(self, output, index):
obj = self.objs[index]
if output == 'out':
return {
'value': np.int32(obj.out)
}
#----------------------------------------------------------
class ViewDuo(BaseView):
"""Outputs:
- a: "{{ system_user.username }}/integer/1"
- b: "{{ system_user.username }}/integer/1"
------------------------------- -------------------------------
| a | | a |
------------------------------- -------------------------------
--------------- --------------- --------------- ---------------
| b | | b | | b | | b |
--------------- --------------- --------------- ---------------
"""
def index(self, root_folder, parameters):
Entry = namedtuple('Entry', ['a', 'b'])
return [
Entry(0, 0),
Entry(0, 1),
Entry(0, 2),
Entry(10, 3),
Entry(10, 4),
Entry(10, 5),
Entry(20, 6),
Entry(20, 7),
Entry(20, 8),
]
def get(self, output, index):
obj = self.objs[index]
if output == 'a':
return {
'value': np.int32(obj.a)
}
elif output == 'b':
return {
'value': np.int32(obj.b)
}
#----------------------------------------------------------
def setup_tests():
pass
#----------------------------------------------------------
# Test the behavior of the views (on fake data)
if __name__ == '__main__':
setup_tests()
from beat.backend.python.database import DatabaseTester
DatabaseTester('View', View,
[
'out',
],
parameters=dict(
),
)
DatabaseTester('View2', View2,
[
'out',
],
parameters=dict(
),
)
DatabaseTester('LargeView', LargeView,
[
'out',
],
parameters=dict(
),
)
A test database that emits integers
\ No newline at end of file
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