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

L2SS-235: start archiving only if production env var is true

parent e1f04057
No related branches found
No related tags found
1 merge request!108Resolve L2SS-235 "Archive pcc attribute"
...@@ -32,6 +32,8 @@ from clients.attribute_wrapper import attribute_wrapper ...@@ -32,6 +32,8 @@ from clients.attribute_wrapper import attribute_wrapper
from devices.hardware_device import hardware_device from devices.hardware_device import hardware_device
from common.lofar_logging import device_logging_to_python, log_exceptions from common.lofar_logging import device_logging_to_python, log_exceptions
from common.lofar_git import get_version from common.lofar_git import get_version
from common.lofar_environment import isProduction
from toolkit.archiver import Archiver
__all__ = ["PCC", "main"] __all__ = ["PCC", "main"]
...@@ -110,6 +112,8 @@ class PCC(hardware_device): ...@@ -110,6 +112,8 @@ class PCC(hardware_device):
RCU_translator_busy_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_translator_busy_R"], datatype=numpy.bool_) RCU_translator_busy_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_translator_busy_R"], datatype=numpy.bool_)
RCU_version_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_version_R"], datatype=numpy.str_, dims=(32,)) RCU_version_R = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_version_R"], datatype=numpy.str_, dims=(32,))
test_att = RCU_temperature_R
@log_exceptions() @log_exceptions()
def delete_device(self): def delete_device(self):
"""Hook to delete resources allocated in init_device. """Hook to delete resources allocated in init_device.
...@@ -160,6 +164,21 @@ class PCC(hardware_device): ...@@ -160,6 +164,21 @@ class PCC(hardware_device):
self.OPCua_client.start() self.OPCua_client.start()
# TODO(Stefano): check if all attributes are ready to be archived
# add an attribute for testing purpose
self.archiver = Archiver() # define a standard archiver
attr_name = str(self.get_name()+'/'+self.test_att.get_name()).lower()
if isProduction():
# Add attribute to subscriber list if not already present
try:
result = self.archiver.check_attribute_in_archiving_list(attr_name)
self.debug_stream("ARCHIVING: %s added to archiving list" % result)
except Exception as e:
self.warn_stream("error while adding attributes to archiving list. {}".format(e))
else:
# Remove attribute from subscriber list to prevent automatic archiving
self.archiver.remove_attribute_from_archiver(attr_name)
# -------- # --------
......
%% Cell type:code id:7a417be6 tags: %% Cell type:code id:7a417be6 tags:
``` python ``` python
import sys, time import sys, time
import numpy as np import numpy as np
sys.path.append('/hosthome/tango/devices') sys.path.append('/hosthome/tango/devices')
from toolkit.archiver import Archiver,Retriever from toolkit.archiver import Archiver,Retriever
from toolkit.archiver_base import * from toolkit.archiver_base import *
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
``` ```
%% Cell type:code id:a3b8ab54 tags:
``` python
from common.lofar_environment import isProduction
print(isProduction())
```
%% Cell type:code id:b0f8a926 tags: %% Cell type:code id:b0f8a926 tags:
``` python ``` python
# Define an attribute for archiving # Define an attribute for archiving
device_name = 'LTS/PCC/1' device_name = 'LTS/PCC/1'
attr_name = 'rcu_temperature_r'
attr_fq_name = str(device_name+'/'+attr_name).lower()
archiver = Archiver()
d=DeviceProxy(device_name) d=DeviceProxy(device_name)
state = str(d.state()) state = str(d.state())
print(state) print(state)
archiver = Archiver()
# Attribute chosen to be archived
attr_name = 'rcu_temperature_r'
attr_fq_name = str(device_name+'/'+attr_name).lower()
``` ```
%% Cell type:code id:4fdfe60f tags: %% Cell type:code id:4fdfe60f tags:
``` python ``` python
# Print the list of the attributes ready to be archived # Print the list of the attributes in the event subscriber
print(archiver.es.AttributeList) # If any attribute is present, its archiving will begin when device will reach ON state,
# Otherwise, attribute will be added to the list at the device initializing phase only in PRODUCTION mode
archiver.get_subscriber_attributes()
``` ```
%% Cell type:code id:6756d93c tags: %% Cell type:code id:6756d93c tags:
``` python ``` python
# Start the device # Start the device
#d.set_timeout_millis(5000)
if state == "OFF": if state == "OFF":
d.initialise() # Workaround to avoid device timeout error
d.command_inout_asynch(cmd_name='Initialise')
time.sleep(1) time.sleep(1)
state = str(d.state()) state = str(d.state())
if state == "STANDBY": if state == "STANDBY":
d.on() d.on()
state = str(d.state()) state = str(d.state())
if state == "ON": if state == "ON":
print("Device is now in ON state") print("Device is now in ON state")
``` ```
%% Cell type:code id:ab496017 tags:
``` python
# Modify attribute archiving features
archiver.update_archiving_attribute(attr_fq_name,polling_period=1000,event_period=1000,strategy='RUN')
```
%% Cell type:code id:0d3a7cbe tags: %% Cell type:code id:0d3a7cbe tags:
``` python ``` python
# Add attribute to the archiving list (starts the archiving if device is running) # Add attribute to the archiving list (starts the archiving if device is running)
# Archiving strategies are ['ALWAYS','RUN','SHUTDOWN','SERVICE'] # Archiving strategies are ['ALWAYS','RUN','SHUTDOWN','SERVICE']
#Read [0] ALWAYS:always stored #Read [0] ALWAYS:always stored
#Read [1] RUN:stored during run #Read [1] RUN:stored during run
#Read [2] SHUTDOWN:stored during shutdown #Read [2] SHUTDOWN:stored during shutdown
#Read [3] SERVICE:stored during maintenance activities #Read [3] SERVICE:stored during maintenance activities
archiver.add_attribute_to_archiver(attr_fq_name, polling_period=1000, event_period=1000, strategy='RUN') archiver.add_attribute_to_archiver(attr_fq_name, polling_period=1000, event_period=1000, strategy='RUN')
``` ```
%% Cell type:code id:266ad6c6 tags: %% Cell type:code id:266ad6c6 tags:
``` python ``` python
# Stop the attribute archiving but do not remove it from the list # Stop the attribute archiving but do not remove it from the list
# This means that archiving is stopped for the current session, but if the device is restarted, # This means that archiving is stopped for the current session, but if the device is restarted,
# the attribute archiving will be restarted as well # the attribute archiving will be restarted as well
# In order to definitely stop the archiving, the attribute must be removed from the attribute list (go to last cell) # In order to definitely stop the archiving, the attribute must be removed from the attribute list (go to last cell)
archiver.stop_archiving_attribute(attr_fq_name) archiver.stop_archiving_attribute(attr_fq_name)
``` ```
%% Cell type:code id:ec567395 tags: %% Cell type:code id:ec567395 tags:
``` python ``` python
# Starts the attribute archiving if it was stopped # Starts the attribute archiving if it was stopped
archiver.start_archiving_attribute(attr_fq_name) archiver.start_archiving_attribute(attr_fq_name)
``` ```
%% Cell type:code id:e629a396 tags: %% Cell type:code id:e629a396 tags:
``` python ``` python
# Initialise the retriever object and print the archived attributes in the database
retriever = Retriever() retriever = Retriever()
retriever.get_all_archived_attributes() retriever.get_all_archived_attributes()
``` ```
%% Cell type:code id:b79dc679 tags: %% Cell type:code id:b79dc679 tags:
``` python ``` python
# Retrieve records in the last n hours (works even with decimals) # Retrieve records in the last n hours (works even with decimals)
# Use alternatively one of the following two methods to retrieve data (last n hours or interval) # Use alternatively one of the following two methods to retrieve data (last n hours or interval)
records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.04) records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.1)
#records = retriever.get_attribute_value_by_interval(attr_fq_name,'2021-09-01 16:00:00', '2021-09-01 16:03:00') #records = retriever.get_attribute_value_by_interval(attr_fq_name,'2021-09-01 16:00:00', '2021-09-01 16:03:00')
if not records: if not records:
print('Empty result!') print('Empty result!')
else: else:
# Convert DB Array records into Python lists # Convert DB Array records into Python lists
data = build_array_from_record(records,records[0].dim_x_r) data = build_array_from_record(records,records[0].dim_x_r)
# Extract only the value from the array # Extract only the value from the array
array_values = get_values_from_record(data) array_values = get_values_from_record(data)
#records #records
#data #data
#array_values #array_values
``` ```
%% Cell type:code id:0638cfd3 tags: %% Cell type:code id:0638cfd3 tags:
``` python ``` python
# Extract and process timestamps for plotting purposes # Extract and process timestamps for plotting purposes
def get_timestamps(data,strformat): def get_timestamps(data,strformat):
timestamps = [] timestamps = []
for i in range(len(data)): for i in range(len(data)):
timestamps.append(data[i][0].recv_time.strftime(strformat)) timestamps.append(data[i][0].recv_time.strftime(strformat))
return timestamps return timestamps
timestamps = get_timestamps(data,"%Y-%m-%d %X") timestamps = get_timestamps(data,"%Y-%m-%d %X")
``` ```
%% Cell type:code id:d72904fa tags: %% Cell type:code id:d72904fa tags:
``` python ``` python
# Plot of array values # Plot of array values
heatmap = np.array(array_values,dtype=np.float) heatmap = np.array(array_values,dtype=np.float)
fig = plt.figure() fig = plt.figure()
#plt.rcParams['figure.figsize'] = [32, 64] plt.rcParams['figure.figsize'] = [128, 64]
#plt.rcParams['figure.dpi'] = 128 #plt.rcParams['figure.dpi'] = 128
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm') im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm')
ax.set_xlabel('Array index') ax.set_xlabel('Array index')
ax.set_ylabel('Timestamp') ax.set_ylabel('Timestamp')
ax.set_xlim([0,(records[0].dim_x_r)-1]) ax.set_xlim([0,(records[0].dim_x_r)-1])
ax.set_xticks(np.arange(0,records[0].dim_x_r)) ax.set_xticks(np.arange(0,records[0].dim_x_r))
ax.set_yticks(range(0,len(timestamps))) ax.set_yticks(range(0,len(timestamps)))
ax.set_yticklabels(timestamps,fontsize=4) ax.set_yticklabels(timestamps,fontsize=4)
# Comment the previous two lines and uncomment the following line if there are too many timestamp labels # Comment the previous two lines and uncomment the following line if there are too many timestamp labels
#ax.set_yticks(range(0,len(timestamps),10)) #ax.set_yticks(range(0,len(timestamps),10))
ax.set_title('Archived data for '+ attr_fq_name) ax.set_title('Archived data for '+ attr_fq_name)
ax.grid() ax.grid()
cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal') cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal')
#plt.show() plt.show()
``` ```
%% Cell type:code id:824b3d83 tags: %% Cell type:code id:824b3d83 tags:
``` python ``` python
# Turn off the device # Turn off the device
d.off() d.off()
# Remove attribute from archiving list # Remove attribute from archiving list
archiver.remove_attribute_from_archiver(attr_fq_name) #archiver.remove_attribute_from_archiver(attr_fq_name)
``` ```
%% Cell type:code id:8e9fd9a5 tags: %% Cell type:code id:8e9fd9a5 tags:
``` python ``` python
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment