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

[test][databases] Add database for raw data access

parent f6c61dd5
No related branches found
No related tags found
1 merge request!27Refactor raw data access
{
"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",
"sets": [
{
"name": "set",
"template": "set",
"view": "View",
"outputs": {
"out": "{{ system_user.username }}/integer/1"
}
},
{
"name": "set2",
"template": "set",
"view": "View2",
"outputs": {
"out": "{{ system_user.username }}/integer/1"
}
}
]
},
{
"name": "protocol2",
"template": "test_integers",
"sets": [
{
"name": "set",
"template": "set",
"view": "LargeView",
"outputs": {
"out": "{{ system_user.username }}/integer/1"
}
},
{
"name": "set2",
"template": "set",
"view": "View2",
"outputs": {
"out": "{{ system_user.username }}/integer/1"
}
}
]
},
{
"name": "10_numbers",
"template": "one_block",
"sets": [
{
"name": "numbers",
"template": "numbers",
"view": "View10",
"outputs": {
"out": "{{ system_user.username }}/integer/1"
}
}
]
},
{
"name": "duo",
"template": "one_block_two_inputs",
"sets": [
{
"name": "numbers",
"template": "numbers",
"view": "ViewDuo",
"outputs": {
"a": "{{ system_user.username }}/integer/1",
"b": "{{ system_user.username }}/integer/1"
}
}
]
}
]
}
###############################################################################
# #
# 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(
),
)
.. Copyright (c) 2020 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/. ..
The Simple Digit Database with raw data access
----------------------------------------------
This database emits two integers (one from each of its set). The first integer
(from ``set``) has a value of 42, while the second (from ``set2``), a value of
53.
In addition to that it enables direct raw data access.
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