diff --git a/tangostationcontrol/tangostationcontrol/integration_test/default/toolkit/test_archiver.py b/tangostationcontrol/tangostationcontrol/integration_test/default/toolkit/test_archiver.py index 091db2c253e5e163167afc204170d89cf087c61a..05cfe5bf41241d2cf142479026d91b07f332e384 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/default/toolkit/test_archiver.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/default/toolkit/test_archiver.py @@ -136,6 +136,55 @@ class TestArchiver(BaseIntegrationTestCase): """ sdp_proxy.off() + def test_archive_image_boolean_attribute(self): + """Test if a boolean image attribute is correctly archived""" + # Start RECV Device + recv_proxy = TestDeviceProxy("STAT/RECV/1") + recv_proxy.off() + time.sleep(1) # To be deleted with L2SS-592 + recv_proxy.initialise() + time.sleep(1) # To be deleted with L2SS-592 + self.assertEqual(DevState.STANDBY, recv_proxy.state()) + recv_proxy.set_defaults() + recv_proxy.on() + self.assertEqual(DevState.ON, recv_proxy.state()) + + """ + # Safety operation that prevents event subscriber to go in Fault state + self.archiver.remove_attributes_in_error() + time.sleep(3) + """ + polling_period=1000 + archive_event_period=5000 + attr_fullname = 'stat/recv/1/ant_mask_rw' # boolean 3x32 + self.archiver.add_attribute_to_archiver(attr_fullname, polling_period, archive_event_period) + time.sleep(3) + # Test if the attribute has been correctly added to event subscriber + self.assertTrue(self.archiver.is_attribute_archived(attribute_fqdn(attr_fullname))) + + # Retrieve data from DB views + self.retriever = RetrieverTimescale() + self.assertIsNotNone(self.retriever) + records = self._wait_for_archiving(attr_fullname, archive_event_period) + self.assertTrue(len(records)>0) + item = records[-1] # last table record + self.assertEqual('stat/recv/1',item.device) # column device + self.assertEqual('ant_mask_rw',item.name) # column attribute + self.assertEqual(datetime,type(item.data_time)) # column datetime + self.assertEqual(int,type(item.x)) # column index x + self.assertEqual(int,type(item.y)) # column index y + self.assertEqual(int,type(item.value)) # column value (bool stored as int) + self.assertLessEqual(item.value,1) # column value (must be 0 or 1) + + """ + # Remove attribute at the end of the test + self.archiver.remove_attribute_from_archiver(attr_fullname) + time.sleep(3) + # Test if the attribute has been correctly removed + self.assertFalse(self.archiver.is_attribute_archived(attribute_fqdn(attr_fullname))) + """ + recv_proxy.off() + def test_get_maximum_device_load(self): """ Test if the maximum device load is correctly computed """ # Start RECV Device diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver_base_ts.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver_base_ts.py index fd6f8f7aa0f39d52f79798e89923e75c60de0b5e..801ba8634209b73918b54e6f3fb716563cb73b1b 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver_base_ts.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver_base_ts.py @@ -154,6 +154,79 @@ class Lofar_Array_Ulong64(Lofar_Array_Attribute): class Lofar_Array_Ushort(Lofar_Array_Attribute): __tablename__ = 'lofar_array_ushort' value = Column(INTEGER) + +class Lofar_Image_Attribute(Base): + """ + Abstract Class that represents a Lofar customized Tango Attribute view + """ + __abstract__ = True + __table_args__ = {'extend_existing': True} + + data_time = Column(TIMESTAMP, primary_key=True) + device = Column(String, primary_key=True) + name = Column(String, primary_key=True) + x = Column(INTEGER, primary_key=True) + y = Column(INTEGER, primary_key=True) + + def __repr__(self): + return f"<Attribute(device='{self.device}', name='{self.name}', data_time='{self.data_time}',index_x='{self.x}',index_y='{self.y}',value='{self.value}'>" + +class Lofar_Image_Boolean(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_boolean' + value = Column(Boolean) + +class Lofar_Image_Double(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_double' + value = Column(FLOAT) + +class Lofar_Image_Encoded(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_encoded' + value = Column(BYTEA) + +class Lofar_Image_Enum(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_enum' + value = Column(INTEGER) + +class Lofar_Image_Float(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_float' + value = Column(FLOAT) + +class Lofar_Image_Long(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_long' + value = Column(INT4RANGE) + +class Lofar_Image_Long64(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_long64' + value = Column(INT8RANGE) + +class Lofar_Image_Short(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_short' + value = Column(INTEGER) + +class Lofar_Image_State(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_state' + value = Column(INTEGER) + +class Lofar_Image_String(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_string' + value = Column(TEXT) + +class Lofar_Image_Uchar(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_uchar' + value = Column(INTEGER) + +class Lofar_Image_Ulong(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_ulong' + value = Column(INTEGER) + +class Lofar_Image_Ulong64(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_ulong64' + value = Column(INTEGER) + +class Lofar_Image_Ushort(Lofar_Image_Attribute): + __tablename__ = 'lofar_image_ushort' + value = Column(INTEGER) + # ----------------- ----------------- ----------------- # class Attribute(Base): @@ -777,6 +850,8 @@ def get_viewclass_by_tablename(tablename: str): return c elif format=='array' and c.__tablename__ == f"lofar_array_{datatype}": return c + elif format=='image' and c.__tablename__ == f"lofar_image_{datatype}": + return c return None def build_array_from_record(rows: List[Array], dim_x: int):