Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
ArchiveExtractor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
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
DG
ArchiveExtractor
Commits
c936ee8a
Commit
c936ee8a
authored
3 years ago
by
System User
Browse files
Options
Downloads
Patches
Plain Diff
Corrections after test
parent
ccbef0ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ArchiveExtractor.py
+60
-50
60 additions, 50 deletions
ArchiveExtractor.py
with
60 additions
and
50 deletions
ArchiveExtractor.py
+
60
−
50
View file @
c936ee8a
...
...
@@ -13,20 +13,20 @@ import PyTango as tango
__version__
=
"
1.0.1
"
class
ArchiveExtractor
:
##########################################################################
"""
Commodity variables
"""
##########################################################################
"""
Commodity variables
""
"
# Extractor date format for GetAttDataBetweenDates
DBDFMT
=
"
%Y-%m-%d %H:%M:%S
"
# Extractor date format for Get
AttDataBetweenDates
DBDFMT
=
"
%
Y
-%m-%
d
%H:%M:%S
"
# Extractor date format for Get
NearestValue
DBDFMT
2
=
"
%
d
-%m-%
Y
%H:%M:%S
"
# Extractor date format for GetNearestValue
DBDFMT2
=
"
%d-%m-%Y %H:%M:%S
"
# Vectorized fromtimestamp function
ArrayTimeStampToDatetime
=
np
.
vectorize
(
datetime
.
datetime
.
fromtimestamp
)
# Vectorized fromtimestamp function
ArrayTimeStampToDatetime
=
np
.
vectorize
(
datetime
.
datetime
.
fromtimestamp
)
class
ArchiveExtractor
:
# Max number of point per extraction chunks
Nmax
=
100000
...
...
@@ -66,7 +66,9 @@ class ArchiveExtractor:
#######################################################
# Select Extractor
if
ExtractorPath
is
None
:
self
.
extractor
=
"
archiving/%sDBExtractor/%d
"
%
(
ExtractKind
,
ExtractorNumber
)
self
.
extractor
=
tango
.
DeviceProxy
(
"
archiving/%sDBExtractor/%d
"
%
(
ExtractorKind
,
ExtractorNumber
)
)
else
:
self
.
extractor
=
tango
.
DeviceProxy
(
ExtractorPath
)
...
...
@@ -158,41 +160,14 @@ class ArchiveExtractor:
Number of points on the date range.
"""
# Check that the attribute is in the database
self
.
logger
.
debug
(
"
Check that %s is archived.
"
%
attribute
)
if
not
self
.
extractor
.
IsArchived
(
attribute
):
self
.
logger
.
error
(
"
Attribute
'
%s
'
is not archived in DB %s
"
%
(
attribute
,
extractor
))
raise
ValueError
(
"
Attribute
'
%s
'
is not archived in DB %s
"
%
(
attribute
,
extractor
))
# Get its sampling period in seconds
req
=
self
.
extractor
.
GetArchivingMode
(
attribute
)
self
.
logger
.
debug
(
"
GetArchivingMode:
"
+
str
(
req
))
if
req
[
0
]
==
"
MODE_P
"
:
samplingPeriod
=
int
(
req
[
1
])
*
10
**-
3
self
.
logger
.
debug
(
"
Attribute is sampled every %g seconds
"
%
samplingPeriod
)
elif
req
[
0
]
==
"
MODE_EVT
"
:
self
.
logger
.
warning
(
"
Attribute is archived on event. Chunks of data are sized with an estimated datarate of 0.1Hz
"
)
samplingPeriod
=
10
else
:
self
.
logger
.
error
(
"
Archive mode not implemented in this script
"
)
raise
NotImplemented
(
"
Archive mode not implemented in this script
"
)
# Evaluate the number of points
N
=
(
dateStop
-
dateStart
).
total_seconds
()
/
samplingPeriod
self
.
logger
.
debug
(
"
Which leads to %d points to extract.
"
%
est_N
)
return
N
##---------------------------------------------------------------------------##
def
B
etweenDates
(
def
b
etweenDates
(
self
,
attr
,
attr
ibute
,
dateStart
,
dateStop
=
datetime
.
datetime
.
now
(),
):
...
...
@@ -205,11 +180,11 @@ class ArchiveExtractor:
attr : String
Name of the attribute. Full Tango name i.e.
"
test/dg/panda/current
"
.
dateStart : datetime.datetime
Start date for extraction.
dateStart : datetime.datetime
, string
Start date for extraction.
If string, it will be parsed.
dateStop : datetime.datetime
Stop date for extraction.
dateStop : datetime.datetime
, string
Stop date for extraction.
If string, it will be parsed.
Default is now (datetime.datetime.now())
Exceptions
...
...
@@ -227,12 +202,47 @@ class ArchiveExtractor:
"""
# Check and estimate the number of points
est_N
=
self
.
evalPoints
(
attribute
,
dateStart
,
dateStop
)
# Parse date if it is string
if
type
(
dateStart
)
is
str
:
dateStart
=
self
.
dateparse
(
dateStart
)
if
type
(
dateStop
)
is
str
:
dateStop
=
self
.
dateparse
(
dateStop
)
# Check that the attribute is in the database
self
.
logger
.
debug
(
"
Check that %s is archived.
"
%
attribute
)
if
not
self
.
extractor
.
IsArchived
(
attribute
):
self
.
logger
.
error
(
"
Attribute
'
%s
'
is not archived in DB %s
"
%
(
attribute
,
extractor
))
raise
ValueError
(
"
Attribute
'
%s
'
is not archived in DB %s
"
%
(
attribute
,
extractor
))
# Get its sampling period in seconds
req
=
self
.
extractor
.
GetArchivingMode
(
attribute
)
self
.
logger
.
debug
(
"
GetArchivingMode:
"
+
str
(
req
))
if
req
[
0
]
==
"
MODE_P
"
:
samplingPeriod
=
int
(
req
[
1
])
*
10
**-
3
self
.
logger
.
debug
(
"
Attribute is sampled every %g seconds
"
%
samplingPeriod
)
elif
req
[
0
]
==
"
MODE_EVT
"
:
self
.
logger
.
warning
(
"
Attribute is archived on event. Chunks of data are sized with an estimated datarate of 0.1Hz
"
)
samplingPeriod
=
10
else
:
self
.
logger
.
error
(
"
Archive mode not implemented in this script
"
)
raise
NotImplemented
(
"
Archive mode not implemented in this script
"
)
# Get the number of points
N
=
self
.
extractor
.
GetAttDataBetweenDatesCount
([
attribute
,
dateStart
.
strftime
(
DBDFMT2
),
dateStop
.
strftime
(
DBDFMT2
)
])
self
.
logger
.
debug
(
"
On the period, there is %d entries
"
%
N
)
# If data chunk is too much, we need to cut it
if
est_N
>
Nmax
:
dt
=
datetime
.
timedelta
(
seconds
=
samplingPeriod
)
*
Nmax
if
N
>
self
.
Nmax
:
dt
=
datetime
.
timedelta
(
seconds
=
samplingPeriod
)
*
self
.
Nmax
dt
=
(
dateStop
-
dateStart
)
/
(
N
//
self
.
Nmax
)
cdates
=
[
dateStart
]
while
cdates
[
-
1
]
<
dateStop
:
cdates
.
append
(
cdates
[
-
1
]
+
dt
)
...
...
@@ -249,13 +259,13 @@ class ArchiveExtractor:
for
i_d
in
range
(
len
(
cdates
)
-
1
):
# Make retrieval request
self
.
logger
.
debug
(
"
Perform ExtractBetweenDates (%s, %s, %s)
"
%
(
attr
,
attr
ibute
,
cdates
[
i_d
].
strftime
(
DBDFMT
),
cdates
[
i_d
+
1
].
strftime
(
DBDFMT
))
)
_date
,
_value
=
self
.
extractor
.
ExtractBetweenDates
([
attr
,
attr
ibute
,
cdates
[
i_d
].
strftime
(
DBDFMT
),
cdates
[
i_d
+
1
].
strftime
(
DBDFMT
)
])
...
...
@@ -273,7 +283,7 @@ class ArchiveExtractor:
date
=
np
.
concatenate
(
date
)
self
.
logger
.
debug
(
"
Extraction done for %s.
"
%
attr
)
self
.
logger
.
debug
(
"
Extraction done for %s.
"
%
attr
ibute
)
return
[
date
,
value
]
##---------------------------------------------------------------------------##
...
...
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