Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
7c996dd8
Commit
7c996dd8
authored
3 years ago
by
Stefano Di Frischia
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-235
: start archiving only if production env var is true
parent
e1f04057
No related branches found
No related tags found
1 merge request
!108
Resolve L2SS-235 "Archive pcc attribute"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
devices/devices/pcc.py
+19
-0
19 additions, 0 deletions
devices/devices/pcc.py
jupyter-notebooks/PCC_archive_attribute.ipynb
+41
-12
41 additions, 12 deletions
jupyter-notebooks/PCC_archive_attribute.ipynb
with
60 additions
and
12 deletions
devices/devices/pcc.py
+
19
−
0
View file @
7c996dd8
...
@@ -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
)
# --------
# --------
...
...
This diff is collapsed.
Click to expand it.
jupyter-notebooks/PCC_archive_attribute.ipynb
+
41
−
12
View file @
7c996dd8
...
@@ -15,6 +15,17 @@
...
@@ -15,6 +15,17 @@
"from matplotlib import pyplot as plt"
"from matplotlib import pyplot as plt"
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3b8ab54",
"metadata": {},
"outputs": [],
"source": [
"from common.lofar_environment import isProduction\n",
"print(isProduction())"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
...
@@ -24,13 +35,15 @@
...
@@ -24,13 +35,15 @@
"source": [
"source": [
"# Define an attribute for archiving\n",
"# Define an attribute for archiving\n",
"device_name = 'LTS/PCC/1'\n",
"device_name = 'LTS/PCC/1'\n",
"attr_name = 'rcu_temperature_r'\n",
"attr_fq_name = str(device_name+'/'+attr_name).lower()\n",
"archiver = Archiver()\n",
"\n",
"d=DeviceProxy(device_name) \n",
"d=DeviceProxy(device_name) \n",
"state = str(d.state())\n",
"state = str(d.state())\n",
"print(state)"
"print(state)\n",
"\n",
"archiver = Archiver()\n",
"\n",
"# Attribute chosen to be archived\n",
"attr_name = 'rcu_temperature_r'\n",
"attr_fq_name = str(device_name+'/'+attr_name).lower()"
]
]
},
},
{
{
...
@@ -40,8 +53,10 @@
...
@@ -40,8 +53,10 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# Print the list of the attributes ready to be archived\n",
"# Print the list of the attributes in the event subscriber\n",
"print(archiver.es.AttributeList)"
"# If any attribute is present, its archiving will begin when device will reach ON state,\n",
"# Otherwise, attribute will be added to the list at the device initializing phase only in PRODUCTION mode\n",
"archiver.get_subscriber_attributes()"
]
]
},
},
{
{
...
@@ -52,8 +67,10 @@
...
@@ -52,8 +67,10 @@
"outputs": [],
"outputs": [],
"source": [
"source": [
"# Start the device\n",
"# Start the device\n",
"#d.set_timeout_millis(5000)\n",
"if state == \"OFF\":\n",
"if state == \"OFF\":\n",
" d.initialise()\n",
" # Workaround to avoid device timeout error\n",
" d.command_inout_asynch(cmd_name='Initialise')\n",
" time.sleep(1)\n",
" time.sleep(1)\n",
"state = str(d.state())\n",
"state = str(d.state())\n",
"if state == \"STANDBY\":\n",
"if state == \"STANDBY\":\n",
...
@@ -63,6 +80,17 @@
...
@@ -63,6 +80,17 @@
" print(\"Device is now in ON state\")"
" print(\"Device is now in ON state\")"
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab496017",
"metadata": {},
"outputs": [],
"source": [
"# Modify attribute archiving features\n",
"archiver.update_archiving_attribute(attr_fq_name,polling_period=1000,event_period=1000,strategy='RUN')"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
...
@@ -113,6 +141,7 @@
...
@@ -113,6 +141,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# Initialise the retriever object and print the archived attributes in the database\n",
"retriever = Retriever()\n",
"retriever = Retriever()\n",
"retriever.get_all_archived_attributes()"
"retriever.get_all_archived_attributes()"
]
]
...
@@ -127,7 +156,7 @@
...
@@ -127,7 +156,7 @@
"# Retrieve records in the last n hours (works even with decimals)\n",
"# Retrieve records in the last n hours (works even with decimals)\n",
"\n",
"\n",
"# Use alternatively one of the following two methods to retrieve data (last n hours or interval)\n",
"# Use alternatively one of the following two methods to retrieve data (last n hours or interval)\n",
"records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.
04
)\n",
"records= retriever.get_attribute_value_by_hours(attr_fq_name,hours=0.
1
)\n",
"#records = retriever.get_attribute_value_by_interval(attr_fq_name,'2021-09-01 16:00:00', '2021-09-01 16:03:00')\n",
"#records = retriever.get_attribute_value_by_interval(attr_fq_name,'2021-09-01 16:00:00', '2021-09-01 16:03:00')\n",
"\n",
"\n",
"if not records:\n",
"if not records:\n",
...
@@ -170,7 +199,7 @@
...
@@ -170,7 +199,7 @@
"\n",
"\n",
"heatmap = np.array(array_values,dtype=np.float)\n",
"heatmap = np.array(array_values,dtype=np.float)\n",
"fig = plt.figure()\n",
"fig = plt.figure()\n",
"
#
plt.rcParams['figure.figsize'] = [
32
, 64]\n",
"plt.rcParams['figure.figsize'] = [
128
, 64]\n",
"#plt.rcParams['figure.dpi'] = 128\n",
"#plt.rcParams['figure.dpi'] = 128\n",
"ax = fig.add_subplot(111)\n",
"ax = fig.add_subplot(111)\n",
"im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm')\n",
"im = ax.imshow(heatmap, interpolation='nearest',cmap='coolwarm')\n",
...
@@ -188,7 +217,7 @@
...
@@ -188,7 +217,7 @@
"ax.set_title('Archived data for '+ attr_fq_name)\n",
"ax.set_title('Archived data for '+ attr_fq_name)\n",
"ax.grid()\n",
"ax.grid()\n",
"cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal')\n",
"cbar = fig.colorbar(ax=ax, mappable=im, orientation='horizontal')\n",
"
#
plt.show()"
"plt.show()"
]
]
},
},
{
{
...
@@ -201,7 +230,7 @@
...
@@ -201,7 +230,7 @@
"# Turn off the device\n",
"# Turn off the device\n",
"d.off()\n",
"d.off()\n",
"# Remove attribute from archiving list\n",
"# Remove attribute from archiving list\n",
"archiver.remove_attribute_from_archiver(attr_fq_name)"
"
#
archiver.remove_attribute_from_archiver(attr_fq_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
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment