Skip to content
GitLab
Explore
Sign in
Register
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
f40eb758
Commit
f40eb758
authored
3 years ago
by
Stefano Di Frischia
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-235
: fix get archive load bug
parent
882e175b
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!108
Resolve L2SS-235 "Archive pcc attribute"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
devices/toolkit/archiver.py
+1
-1
1 addition, 1 deletion
devices/toolkit/archiver.py
jupyter-notebooks/PCC_archive_attribute.ipynb
+11
-8
11 additions, 8 deletions
jupyter-notebooks/PCC_archive_attribute.ipynb
with
12 additions
and
9 deletions
devices/toolkit/archiver.py
+
1
−
1
View file @
f40eb758
...
...
@@ -216,7 +216,7 @@ class Archiver():
if
use_freq
:
return
str
(
es
.
AttributeRecordFreq
)
+
(
'
events/period
'
)
else
:
return
len
(
es
.
AttributeList
)
return
len
(
es
.
AttributeList
or
[])
class
AttributeFormatException
(
Exception
):
"""
...
...
This diff is collapsed.
Click to expand it.
jupyter-notebooks/PCC_archive_attribute.ipynb
+
11
−
8
View file @
f40eb758
...
...
@@ -226,24 +226,27 @@
{
"cell_type": "code",
"execution_count": null,
"id": "
a0e8dcab
",
"id": "
1c753ed9
",
"metadata": {},
"outputs": [],
"source": [
"# Turn off the device\n",
"d.off()\n",
"# Remove attribute from archiving list\n",
"#archiver.remove_attribute_from_archiver(attr_fq_name)\n",
"#archiver.remove_attributes_by_device(device_name)"
"# Count number of archive events per minute\n",
"archiver.get_subscriber_load()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "
32ab34a9
",
"id": "
a0e8dcab
",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Turn off the device\n",
"d.off()\n",
"# Remove attribute from archiving list\n",
"#archiver.remove_attribute_from_archiver(attr_fq_name)\n",
"#archiver.remove_attributes_by_device(device_name)"
]
}
],
"metadata": {
...
...
%% Cell type:code id:42e7f25a tags:
```
python
import
sys
,
time
import
numpy
as
np
sys
.
path
.
append
(
'
/hosthome/tango/devices
'
)
from
toolkit.archiver
import
Archiver
,
Retriever
from
toolkit.archiver_base
import
*
from
matplotlib
import
pyplot
as
plt
```
%% Cell type:code id:1f025912 tags:
```
python
from
common.lofar_environment
import
isProduction
print
(
isProduction
())
```
%% Cell type:code id:e0656e2d tags:
```
python
# Define an attribute for archiving
device_name
=
'
LTS/PCC/1
'
d
=
DeviceProxy
(
device_name
)
state
=
str
(
d
.
state
())
print
(
device_name
,
'
is
'
,
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:153d9420 tags:
```
python
# Print the list of the attributes in the event subscriber
# 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:2ebb00f8 tags:
```
python
# Start the device
if
state
==
"
OFF
"
:
if
isProduction
():
archiver
.
check_and_add_attribute_in_archiving_list
(
attr_fq_name
)
else
:
archiver
.
remove_attribute_from_archiver
(
attr_fq_name
)
time
.
sleep
(
1
)
d
.
initialise
()
time
.
sleep
(
1
)
state
=
str
(
d
.
state
())
if
state
==
"
STANDBY
"
:
d
.
on
()
state
=
str
(
d
.
state
())
if
state
==
"
ON
"
:
print
(
"
Device is now in ON state
"
)
```
%% Cell type:code id:75163627 tags:
```
python
# Modify attribute archiving features
archiver
.
update_archiving_attribute
(
attr_fq_name
,
polling_period
=
1000
,
event_period
=
5000
,
strategy
=
'
RUN
'
)
```
%% Cell type:code id:7814715e tags:
```
python
# Add attribute to the archiving list (starts the archiving if device is running)
# Archiving strategies are ['ALWAYS','RUN','SHUTDOWN','SERVICE']
#Read [0] ALWAYS:always stored
#Read [1] RUN:stored during run
#Read [2] SHUTDOWN:stored during shutdown
#Read [3] SERVICE:stored during maintenance activities
archiver
.
add_attribute_to_archiver
(
attr_fq_name
,
polling_period
=
1000
,
event_period
=
1000
,
strategy
=
'
RUN
'
)
```
%% Cell type:code id:52a27abb tags:
```
python
# 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,
# 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)
archiver
.
stop_archiving_attribute
(
attr_fq_name
)
```
%% Cell type:code id:c064e337 tags:
```
python
# Starts the attribute archiving if it was stopped
archiver
.
start_archiving_attribute
(
attr_fq_name
)
```
%% Cell type:code id:d199916c tags:
```
python
# Initialise the retriever object and print the archived attributes in the database
retriever
=
Retriever
()
retriever
.
get_all_archived_attributes
()
```
%% Cell type:code id:80e2a560 tags:
```
python
# 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)
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')
if
not
records
:
print
(
'
Empty result!
'
)
else
:
# Convert DB Array records into Python lists
data
=
build_array_from_record
(
records
,
records
[
0
].
dim_x_r
)
# Extract only the value from the array
array_values
=
get_values_from_record
(
data
)
#records
#data
#array_values
```
%% Cell type:code id:64c8e060 tags:
```
python
# Extract and process timestamps for plotting purposes
def
get_timestamps
(
data
,
strformat
):
timestamps
=
[]
for
i
in
range
(
len
(
data
)):
timestamps
.
append
(
data
[
i
][
0
].
recv_time
.
strftime
(
strformat
))
return
timestamps
timestamps
=
get_timestamps
(
data
,
"
%Y-%m-%d %X
"
)
```
%% Cell type:code id:59a0c05c tags:
```
python
# Plot of array values
heatmap
=
np
.
array
(
array_values
,
dtype
=
np
.
float
)
fig
=
plt
.
figure
()
plt
.
rcParams
[
'
figure.figsize
'
]
=
[
128
,
64
]
#plt.rcParams['figure.dpi'] = 128
ax
=
fig
.
add_subplot
(
111
)
im
=
ax
.
imshow
(
heatmap
,
interpolation
=
'
nearest
'
,
cmap
=
'
coolwarm
'
)
ax
.
set_xlabel
(
'
Array index
'
)
ax
.
set_ylabel
(
'
Timestamp
'
)
ax
.
set_xlim
([
0
,(
records
[
0
].
dim_x_r
)
-
1
])
ax
.
set_xticks
(
np
.
arange
(
0
,
records
[
0
].
dim_x_r
))
ax
.
set_yticks
(
range
(
0
,
len
(
timestamps
)))
ax
.
set_yticklabels
(
timestamps
,
fontsize
=
4
)
# 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_title
(
'
Archived data for
'
+
attr_fq_name
)
ax
.
grid
()
cbar
=
fig
.
colorbar
(
ax
=
ax
,
mappable
=
im
,
orientation
=
'
horizontal
'
)
plt
.
show
()
```
%% Cell type:code id:1c753ed9 tags:
```
python
# Count number of archive events per minute
archiver
.
get_subscriber_load
()
```
%% Cell type:code id:a0e8dcab tags:
```
python
# Turn off the device
d
.
off
()
# Remove attribute from archiving list
#archiver.remove_attribute_from_archiver(attr_fq_name)
#archiver.remove_attributes_by_device(device_name)
```
%% Cell type:code id:32ab34a9 tags:
```
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