diff --git a/test/databases/simple/1.py b/test/databases/simple/1.py index 99ac56c076e1a454698791f1fd1465cfc2879f79..4501e7e85bda1ed9c57fc6f3674a6e7d6709f591 100644 --- a/test/databases/simple/1.py +++ b/test/databases/simple/1.py @@ -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( + ), + ) diff --git a/test/databases/simple/1.rst b/test/databases/simple/1.rst index c0c2620106f5bd0db75830a3f5c921d187fffa55..fa93ea6558ab76d682cfb7f3d97780e3a8d2fdec 100644 --- a/test/databases/simple/1.rst +++ b/test/databases/simple/1.rst @@ -1,4 +1,4 @@ -.. 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. .. diff --git a/test/databases/simple/2.json b/test/databases/simple/2.json deleted file mode 100644 index fac11173d761586ed9d7b692ca3de594925d6edd..0000000000000000000000000000000000000000 --- a/test/databases/simple/2.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "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" - } - } - ] - } - ] -} diff --git a/test/databases/simple/2.py b/test/databases/simple/2.py deleted file mode 100644 index 4501e7e85bda1ed9c57fc6f3674a6e7d6709f591..0000000000000000000000000000000000000000 --- a/test/databases/simple/2.py +++ /dev/null @@ -1,215 +0,0 @@ -############################################################################### -# # -# 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( - ), - ) diff --git a/test/databases/simple/2.rst b/test/databases/simple/2.rst deleted file mode 100644 index f4040d80865167f17466636a6eab373625ffe08c..0000000000000000000000000000000000000000 --- a/test/databases/simple/2.rst +++ /dev/null @@ -1,42 +0,0 @@ -.. 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.