Skip to content
Snippets Groups Projects
Commit e91a174a authored by Philip ABBET's avatar Philip ABBET
Browse files

Remove simple/2, only keep an updated simple/1

parent 212d30aa
No related branches found
No related tags found
No related merge requests found
......@@ -22,80 +22,194 @@
# #
###############################################################################
import numpy
import numpy as np
#----------------------------------------------------------
class View:
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.outputs = outputs
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 0
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def __init(self):
self.current_index = None
self.force_start_index = None
self.force_end_index = None
def setup(self, root_folder, outputs, parameters, force_start_index=None, force_end_index=None):
self.outputs = outputs
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(42)
},
self.next_index
)
if force_start_index is not None: self.force_start_index = force_start_index
else: self.force_start_index = 0
if force_end_index is not None: self.force_end_index = force_end_index
else: self.force_end_index = 1
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
self.current_index = self.force_start_index
return True
return True
def done(self):
return self.current_index != 0
def next(self):
self.outputs['out'].write({
'value': numpy.int32(42),
})
self.current_index += 1
return True
#----------------------------------------------------------
class View2:
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
def setup(self, root_folder, outputs, parameters, force_start_index=None, force_end_index=None):
self.outputs = outputs
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
if force_start_index is not None: self.force_start_index = force_start_index
else: self.force_start_index = 0
if force_end_index is not None: self.force_end_index = force_end_index
else: self.force_end_index = 1
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
self.current_index = self.force_start_index
return True
# Initialisations
self.outputs = outputs
def done(self):
return self.current_index != 0
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 0
def next(self):
self.outputs['out'].write({
'value': numpy.int32(53),
})
self.current_index += 1
return True
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(53)
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class LargeView:
def setup(self, root_folder, outputs, parameters, force_start_index=None, force_end_index=None):
self.outputs = outputs
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.outputs = outputs
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 4
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(self.next_index)
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
def setup_tests():
pass
#----------------------------------------------------------
# Test the behavior of the views (on fake data)
if __name__ == '__main__':
setup_tests()
if force_start_index is not None: self.force_start_index = force_start_index
else: self.force_start_index = 0
if force_end_index is not None: self.force_end_index = force_end_index
else: self.force_end_index = 4
from beat.backend.python.database import DatabaseTester
self.current_index = self.force_start_index
return True
DatabaseTester('View', View,
[
'out',
],
parameters=dict(
),
)
def done(self):
return self.current_index > self.force_end_index
DatabaseTester('View2', View2,
[
'out',
],
parameters=dict(
),
)
def next(self):
self.outputs['out'].write({
'value': numpy.int32(self.current_index),
})
self.current_index += 1
return True
DatabaseTester('LargeView', LargeView,
[
'out',
],
parameters=dict(
),
)
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Copyright (c) 2017 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. ..
......
{
"description": "A test database that emits integers",
"root_folder": "/this/database/does/not/require/a/path",
"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"
}
}
]
}
]
}
###############################################################################
# #
# 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
#----------------------------------------------------------
class View:
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.outputs = outputs
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 0
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(42)
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class View2:
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.outputs = outputs
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 0
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(53)
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
class LargeView:
"""Outputs:
- out: "{{ system_user.username }}/integer/1"
--------------- --------------- --------------- ---------------
| out | | out | | out | | out |
--------------- --------------- --------------- ---------------
"""
def setup(self, root_folder, outputs, parameters, force_start_index=None,
force_end_index=None):
# Initialisations
self.outputs = outputs
# Determine the range of indices that must be provided
self.start_index = force_start_index if force_start_index is not None else 0
self.end_index = force_end_index if force_end_index is not None else 4
self.next_index = self.start_index
return True
def done(self, last_data_index):
return last_data_index >= self.end_index
def next(self):
# Output: out (provide data at each iteration)
if self.outputs['out'].isConnected():
self.outputs['out'].write(
{
'value': np.int32(self.next_index)
},
self.next_index
)
# Determine the next data index that must be provided
self.next_index = 1 + min([ x.last_written_data_index for x in self.outputs
if x.isConnected() ]
)
return True
#----------------------------------------------------------
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) 2017 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
-------------------------
Changelog
=========
* **Version 2**, 02/Nov/2017:
- Port to beat.backend.python v1.4.2
* **Version 1**:
- Initial release
Description
===========
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.
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