Skip to content
Snippets Groups Projects
Commit 79131e09 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-542: add lofar views to archiving base and retriever

parent 08cb499e
Branches
Tags
1 merge request!240Resolve L2SS-542 "Add timescaledb views"
%% Cell type:code id:d56e59b7 tags: %% Cell type:code id:d56e59b7 tags:
``` python ``` python
import sys, time import sys, time
import numpy as np import numpy as np
sys.path.append('/hosthome/tango/tangostationcontrol/tangostationcontrol/') sys.path.append('/hosthome/tango/tangostationcontrol/tangostationcontrol/')
from toolkit.archiver_util import * from toolkit.archiver_util import *
from toolkit.archiver import * from toolkit.archiver import *
from toolkit.retriever import * from toolkit.retriever import *
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
``` ```
%% Cell type:code id:fd619562 tags: %% Cell type:code id:fd619562 tags:
``` python ``` python
# Create an archiver object # Create an archiver object
archiver = Archiver() archiver = Archiver()
``` ```
%% Cell type:code id:c1eedafb tags: %% Cell type:code id:c1eedafb tags:
``` python ``` python
# Apply the chosen JSON configuration file in directory toolkit/archiver_config/ # Apply the chosen JSON configuration file in directory toolkit/archiver_config/
config_dict = archiver.get_configuration() config_dict = archiver.get_configuration()
print(config_dict) print(config_dict)
archiver.apply_configuration(config_dict) archiver.apply_configuration(config_dict)
``` ```
%% Output
Attribute stat/sdp/1/fpga_temp_r already in archiving list!
Attribute stat/sdp/1/tr_fpga_mask_r already in archiving list!
{'global_variables': {'development_polling_time': '10000', 'development_archive_time': '60000'}, 'devices': {'STAT/RECV/1': {'environment': 'development', 'include': [], 'exclude': ['CLK_Enable_PWR_R', 'CLK_I2C_STATUS_R', 'CLK_PLL_error_R', 'CLK_PLL_locked_R', 'CLK_translator_busy_R']}, 'STAT/SDP/1': {'environment': 'development', 'include': ['FPGA_temp_R', 'TR_fpga_mask_R'], 'exclude': ['FPGA_scrap_R', 'FPGA_scrap_RW']}, 'STAT/SST/1': {'environment': 'development', 'include': [], 'exclude': []}, 'STAT/XST/1': {'environment': 'development', 'include': [], 'exclude': []}, 'STAT/UNB2/1': {'environment': 'development', 'include': [], 'exclude': []}}}
Device STAT/SST/1 not found
Device STAT/XST/1 not found
Device STAT/UNB2/1 not found
%% Cell type:code id:948e95f0 tags: %% Cell type:code id:948e95f0 tags:
``` python ``` python
# RECV device # RECV device
device_name = 'STAT/RECV/1' device_name = 'STAT/RECV/1'
d=DeviceProxy(device_name) d=DeviceProxy(device_name)
d.set_timeout_millis(10000) d.set_timeout_millis(10000)
state = str(d.state()) state = str(d.state())
print(device_name + ' : ' + state) print(device_name + ' : ' + state)
``` ```
%% Output
STAT/RECV/1 : ON
%% Cell type:code id:225a5e06 tags: %% Cell type:code id:225a5e06 tags:
``` python ``` python
# Start RECV device # Start RECV device
if state == 'FAULT':
d.off()
time.sleep(3)
if state == "OFF": if state == "OFF":
time.sleep(1) time.sleep(1)
d.initialise() d.initialise()
time.sleep(1) time.sleep(1)
state = str(d.state()) state = str(d.state())
if state == "STANDBY": if state == "STANDBY":
d.set_defaults() d.set_defaults()
d.on() d.on()
state = str(d.state()) state = str(d.state())
if state == "ON": if state == "ON":
print(f"Device {device_name} is now in ON state") print(f"Device {device_name} is now in ON state")
``` ```
%% Output
Device STAT/RECV/1 is now in ON state
%% Cell type:code id:0e27ac40 tags: %% Cell type:code id:0e27ac40 tags:
``` python ``` python
# SDP device # SDP device
device_name = 'STAT/SDP/1' device_name = 'STAT/SDP/1'
d2=DeviceProxy(device_name) d2=DeviceProxy(device_name)
d2.set_timeout_millis(10000) d2.set_timeout_millis(10000)
state = str(d2.state()) state = str(d2.state())
print(device_name + ' : ' + state) print(device_name + ' : ' + state)
``` ```
%% Output
STAT/SDP/1 : OFF
%% Cell type:code id:348a9d44 tags: %% Cell type:code id:348a9d44 tags:
``` python ``` python
# Start SDP device # Start SDP device
if state == 'FAULT':
d2.off()
time.sleep(3)
if state == "OFF": if state == "OFF":
time.sleep(1) time.sleep(1)
d2.initialise() d2.initialise()
time.sleep(1) time.sleep(1)
state = str(d2.state()) state = str(d2.state())
if state == "STANDBY": if state == "STANDBY":
d2.set_defaults() d2.set_defaults()
d2.on() d2.on()
state = str(d2.state()) state = str(d2.state())
if state == "ON": if state == "ON":
print(f"Device {device_name} is now in ON state") print(f"Device {device_name} is now in ON state")
``` ```
%% Output
Device STAT/SDP/1 is now in ON state
%% Cell type:code id:6fad043c tags: %% Cell type:code id:6fad043c tags:
``` python ``` python
# Optional # Optional
archiver.remove_attributes_in_error() archiver.remove_attributes_in_error()
``` ```
%% Cell type:code id:c33fa7ee tags: %% Cell type:code id:c33fa7ee tags:
``` python ``` python
# Add boolean scalar attribute # Add boolean scalar attribute
archiver.add_attribute_to_archiver('stat/recv/1/RECVTR_translator_busy_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/RECVTR_translator_busy_R', polling_period=1000, event_period=5000)
# Add boolean array attribute # Add boolean array attribute
archiver.add_attribute_to_archiver('stat/recv/1/rcu_mask_rw', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/rcu_mask_rw', polling_period=1000, event_period=5000)
# Add double scalar attribute # Add double scalar attribute
archiver.add_attribute_to_archiver('stat/sdp/1/TR_tod_pps_delta_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/sdp/1/TR_tod_pps_delta_R', polling_period=1000, event_period=5000)
# Add double array attribute # Add double array attribute
archiver.add_attribute_to_archiver('stat/sdp/1/fpga_temp_r', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/sdp/1/fpga_temp_r', polling_period=1000, event_period=5000)
# Add ushort array attribute # Add ushort array attribute
archiver.add_attribute_to_archiver('stat/sdp/1/FPGA_beamlet_output_hdr_udp_destination_port_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/sdp/1/FPGA_beamlet_output_hdr_udp_destination_port_R', polling_period=1000, event_period=5000)
# Add long array attribute # Add long array attribute
archiver.add_attribute_to_archiver('stat/sdp/1/FPGA_bsn_monitor_input_nof_err_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/sdp/1/FPGA_bsn_monitor_input_nof_err_R', polling_period=1000, event_period=5000)
# Add ulong scalar attribute # Add ulong scalar attribute
archiver.add_attribute_to_archiver('stat/sdp/1/TR_sdp_config_first_fpga_nr_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/sdp/1/TR_sdp_config_first_fpga_nr_R', polling_period=1000, event_period=5000)
# Add ulong array attribute # Add ulong array attribute
archiver.add_attribute_to_archiver('stat/recv/1/RCU_LED_colour_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/RCU_LED_colour_R', polling_period=1000, event_period=5000)
# Add long64 scalar attribute # Add long64 scalar attribute
archiver.add_attribute_to_archiver('stat/recv/1/RECVTR_monitor_rate_RW', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/RECVTR_monitor_rate_RW', polling_period=1000, event_period=5000)
# Add long64 array attribute # Add long64 array attribute
archiver.add_attribute_to_archiver('stat/recv/1/RCU_PCB_ID_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/RCU_PCB_ID_R', polling_period=1000, event_period=5000)
# Add string scalar attribute # Add string scalar attribute
archiver.add_attribute_to_archiver('stat/recv/1/status', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/status', polling_period=1000, event_period=5000)
# Add string array attribute # Add string array attribute
archiver.add_attribute_to_archiver('stat/recv/1/opcua_missing_attributes_R', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/opcua_missing_attributes_R', polling_period=1000, event_period=5000)
# Add state scalar attribute # Add state scalar attribute
archiver.add_attribute_to_archiver('stat/recv/1/state', polling_period=1000, event_period=5000) archiver.add_attribute_to_archiver('stat/recv/1/state', polling_period=1000, event_period=5000)
``` ```
%% Output
Attribute stat/recv/1/RECVTR_translator_busy_R already in archiving list!
Attribute stat/recv/1/rcu_mask_rw already in archiving list!
Attribute stat/sdp/1/TR_tod_pps_delta_R already in archiving list!
Attribute stat/sdp/1/fpga_temp_r already in archiving list!
Attribute stat/sdp/1/FPGA_beamlet_output_hdr_udp_destination_port_R already in archiving list!
Attribute stat/sdp/1/FPGA_bsn_monitor_input_nof_err_R already in archiving list!
Attribute stat/sdp/1/TR_sdp_config_first_fpga_nr_R already in archiving list!
Attribute stat/recv/1/RCU_LED_colour_R already in archiving list!
Attribute stat/recv/1/RECVTR_monitor_rate_RW already in archiving list!
Attribute stat/recv/1/RCU_PCB_ID_R already in archiving list!
Attribute stat/recv/1/status already in archiving list!
Attribute stat/recv/1/opcua_missing_attributes_R already in archiving list!
Attribute stat/recv/1/state already in archiving list!
%% Cell type:code id:ec7878b2 tags: %% Cell type:code id:ec7878b2 tags:
``` python ``` python
# Print the errors for each attribute # Print the errors for each attribute
# If the device is in OFF state, all its attributes should be in error (normal behaviour) # If the device is in OFF state, all its attributes should be in error (normal behaviour)
err_dict = archiver.get_subscriber_errors() err_dict = archiver.get_subscriber_errors()
err_dict err_dict
``` ```
%% Output
{}
%% Cell type:code id:3d2ce2da tags: %% Cell type:code id:3d2ce2da tags:
``` python ``` python
# Print the attributes currently managed by the event subscriber # Print the attributes currently managed by the event subscriber
attrs = archiver.get_subscriber_attributes() attrs = archiver.get_subscriber_attributes()
attrs attrs
``` ```
%% Output
['tango://databaseds:10000/stat/recv/1/status',
'tango://databaseds:10000/stat/recv/1/state',
'tango://databaseds:10000/stat/recv/1/recvtr_translator_busy_r',
'tango://databaseds:10000/stat/recv/1/rcu_mask_rw',
'tango://databaseds:10000/stat/sdp/1/tr_tod_pps_delta_r',
'tango://databaseds:10000/stat/sdp/1/fpga_temp_r',
'tango://databaseds:10000/stat/sdp/1/fpga_beamlet_output_hdr_udp_destination_port_r',
'tango://databaseds:10000/stat/sdp/1/fpga_bsn_monitor_input_nof_err_r',
'tango://databaseds:10000/stat/sdp/1/tr_sdp_config_first_fpga_nr_r',
'tango://databaseds:10000/stat/recv/1/rcu_led_colour_r',
'tango://databaseds:10000/stat/recv/1/recvtr_monitor_rate_rw',
'tango://databaseds:10000/stat/recv/1/rcu_pcb_id_r',
'tango://databaseds:10000/stat/recv/1/opcua_missing_attributes_r',
'tango://databaseds:10000/stat/sdp/1/tr_fpga_mask_r']
%% Cell type:code id:0ec2abd3 tags: %% Cell type:code id:0ec2abd3 tags:
``` python ``` python
retriever = RetrieverTimescale() retriever = RetrieverTimescale()
attr_name = 'stat/sdp/1/tr_tod_pps_delta_r' attr_name = 'stat/sdp/1/tr_tod_pps_delta_r'
records = retriever.get_attribute_value_by_hours(attr_name,1.5) records = retriever.get_attribute_value_by_hours(attr_name,1.5)
records records
``` ```
%% Output
[<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:55:28.225248+00:00',value_r='21.475996475',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:55:39.233392+00:00',value_r='21.475076675',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:55:49.234332+00:00',value_r='21.475180775',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:55:59.224803+00:00',value_r='21.475021575',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:09.234002+00:00',value_r='21.475289175',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:19.227675+00:00',value_r='21.475744575',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:29.226353+00:00',value_r='21.475331875',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:39.224962+00:00',value_r='21.475764575',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:49.224105+00:00',value_r='21.475591075',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:56:59.225051+00:00',value_r='21.475893675',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:57:09.232141+00:00',value_r='21.475835275',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:57:19.224068+00:00',value_r='21.475500775',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:57:29.230708+00:00',value_r='21.475418075',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:57:40.230619+00:00',value_r='21.475114275',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:57:50.226534+00:00',value_r='21.475703275',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:00.226028+00:00',value_r='21.475547875',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:10.234388+00:00',value_r='21.475125675',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:20.225343+00:00',value_r='21.475631075',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:30.230999+00:00',value_r='21.475126675',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:40.225220+00:00',value_r='21.475385175',value_w='None',quality='0',att_error_desc_id='None',details='None')>,
<Scalar_Double(att_conf_id='5',data_time='2022-02-10 17:58:50.224087+00:00',value_r='21.475278375',value_w='None',quality='0',att_error_desc_id='None',details='None')>]
%% Cell type:code id:81b60192 tags: %% Cell type:code id:81b60192 tags:
``` python ``` python
timestamps = [item.data_time.strftime("%Y-%m-%d %X:%f") for item in records] timestamps = [item.data_time.strftime("%Y-%m-%d %X:%f") for item in records]
values = [float(item.value_r) for item in records] values = [float(item.value_r) for item in records]
``` ```
%% Cell type:code id:3dcab007 tags: %% Cell type:code id:3dcab007 tags:
``` python ``` python
values values
``` ```
%% Output
[21.475996475,
21.475076675,
21.475180775,
21.475021575,
21.475289175,
21.475744575,
21.475331875,
21.475764575,
21.475591075,
21.475893675,
21.475835275,
21.475500775,
21.475418075,
21.475114275,
21.475703275,
21.475547875,
21.475125675,
21.475631075,
21.475126675,
21.475385175,
21.475278375]
%% Cell type:code id:26b4aab8 tags: %% Cell type:code id:26b4aab8 tags:
``` python ``` python
plt.plot(timestamps,values) plt.plot(timestamps,values)
plt.title('Archived data for '+ attr_name) plt.title('Archived data for '+ attr_name)
plt.xticks(rotation=90) plt.xticks(rotation=90)
plt.grid() plt.grid()
#plt.rcParams['figure.figsize'] = [12, 8] #plt.rcParams['figure.figsize'] = [12, 8]
plt.rcParams['figure.dpi'] = 60 plt.rcParams['figure.dpi'] = 60
plt.show() plt.show()
``` ```
%% Output %% Cell type:code id:18aeb91f tags:
``` python
views_records = retriever.get_lofar_attribute('stat/sdp/1/tr_tod_pps_delta_r')
views_records
```
%% Cell type:code id:18aeb91f tags: %% Cell type:code id:eb24ed8f tags:
``` python ``` python
views_records = retriever.get_lofar_attribute('stat/sdp/1/fpga_temp_r')
views_records
``` ```
......
...@@ -12,6 +12,124 @@ import numpy ...@@ -12,6 +12,124 @@ import numpy
# Declarative system used to define classes mapped to relational DB tables # Declarative system used to define classes mapped to relational DB tables
Base = declarative_base() Base = declarative_base()
# ----------------- LOFAR VIEWS ----------------- #
class Lofar_Scalar_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)
value = Column(FLOAT)
def __repr__(self):
return f"<Attribute(device='{self.device}', name='{self.name}', data_time='{self.data_time}',value='{self.value}'>"
class Lofar_Scalar_Boolean(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_boolean'
class Lofar_Scalar_Double(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_double'
class Lofar_Scalar_Encoded(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_encoded'
class Lofar_Scalar_Enum(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_enum'
class Lofar_Scalar_Float(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_float'
class Lofar_Scalar_Long(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_long'
class Lofar_Scalar_Long64(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_long64'
class Lofar_Scalar_Short(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_short'
class Lofar_Scalar_State(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_state'
class Lofar_Scalar_String(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_string'
class Lofar_Scalar_Uchar(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_uchar'
class Lofar_Scalar_Ulong(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_ulong'
class Lofar_Scalar_Ulong64(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_ulong64'
class Lofar_Scalar_Ushort(Lofar_Scalar_Attribute):
__tablename__ = 'lofar_scalar_ushort'
class Lofar_Array_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)
value = Column(FLOAT)
def __repr__(self):
return f"<Attribute(device='{self.device}', name='{self.name}', data_time='{self.data_time}',index='{self.x}',value='{self.value}'>"
class Lofar_Array_Boolean(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_boolean'
class Lofar_Array_Double(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_double'
class Lofar_Array_Encoded(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_encoded'
class Lofar_Array_Enum(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_enum'
class Lofar_Array_Float(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_float'
class Lofar_Array_Long(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_long'
class Lofar_Array_Long64(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_long64'
class Lofar_Array_Short(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_short'
class Lofar_Array_State(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_state'
class Lofar_Array_String(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_string'
class Lofar_Array_Uchar(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_uchar'
class Lofar_Array_Ulong(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_ulong'
class Lofar_Array_Ulong64(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_ulong64'
class Lofar_Array_Ushort(Lofar_Array_Attribute):
__tablename__ = 'lofar_array_ushort'
# ----------------- ----------------- ----------------- #
class Attribute(Base): class Attribute(Base):
""" """
Class that represents a Tango Attribute mapped to table 'att_conf' Class that represents a Tango Attribute mapped to table 'att_conf'
...@@ -444,6 +562,23 @@ def get_class_by_tablename(tablename: str): ...@@ -444,6 +562,23 @@ def get_class_by_tablename(tablename: str):
return c return c
return None return None
def get_viewclass_by_tablename(tablename: str):
"""
Returns class reference mapped to a datatype.
"""
format = tablename.split('_')[1].lower()
datatype = tablename.split('_')[2][3:].lower() # Remove 'dev' prefix
for mapper in Base.registry.mappers:
c = mapper.class_
classname = c.__name__
if not classname.startswith('_'):
if hasattr(c, '__tablename__'):
if format=='scalar' and c.__tablename__ == f"lofar_scalar_{datatype}":
return c
elif format=='array' and c.__tablename__ == f"lofar_array_{datatype}":
return c
return None
def build_array_from_record(rows: List[Array], dim_x: int): def build_array_from_record(rows: List[Array], dim_x: int):
""" """
Converts Array database items in Python lists Converts Array database items in Python lists
......
...@@ -302,3 +302,19 @@ class RetrieverTimescale(Retriever): ...@@ -302,3 +302,19 @@ class RetrieverTimescale(Retriever):
tablename = self.get_attribute_tablename(attribute_fqname) tablename = self.get_attribute_tablename(attribute_fqname)
return super().get_attribute_value_by_interval(attribute_fqname,start_time,stop_time,tablename) return super().get_attribute_value_by_interval(attribute_fqname,start_time,stop_time,tablename)
def get_lofar_attribute(self,attribute_fqname: str):
"""
Takes as input the attribute fully-qualified name and queries the customized lofar attribute views
Returns a list of rows containing device name, attribute name, timestamp and value
"""
# Retrieves the attribute tablename
tablename = self.get_attribute_tablename(attribute_fqname)
# Retrieves the class that maps the DB table given the tablename
base_class = self.ab.get_viewclass_by_tablename(tablename)
domain,family,member,name = split_tango_name(attribute_fqname,'attribute')
try:
result = self.session.query(base_class).\
filter(base_class.name == name).all()
except (AttributeError, TypeError, NoResultFound) as e:
raise ValueError(f"Attribute {attribute_fqname} not found!") from e
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment