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
3b5f9e1a
Commit
3b5f9e1a
authored
2 years ago
by
BRONES Romain
Browse files
Options
Downloads
Patches
Plain Diff
WIP move functions, variables to module
parent
4e9cb7a0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/ArchiveExtractor.py
+112
-2
112 additions, 2 deletions
core/ArchiveExtractor.py
with
112 additions
and
2 deletions
core/ArchiveExtractor.py
+
112
−
2
View file @
3b5f9e1a
...
@@ -10,7 +10,22 @@ import pandas as pd
...
@@ -10,7 +10,22 @@ import pandas as pd
__version__
=
"
1.0.1
"
__version__
=
"
1.0.1
"
##########################################################################
##########################################################################
"""
Commodity private variables
"""
### Install logger for the module ###
##########################################################################
logger
=
logging
.
getLogger
(
__name__
)
#logger.setLevel(getattr(logging, logger.upper()))
if
not
logger
.
hasHandlers
():
# No handlers, create one
sh
=
logging
.
StreamHandler
()
sh
.
setLevel
(
logger
.
level
)
sh
.
setFormatter
(
logging
.
Formatter
(
"
%(levelname)s:%(message)s
"
))
logger
.
addHandler
(
sh
)
##########################################################################
### Commodity private variables ###
##########################################################################
# Extractor date format for GetAttDataBetweenDates
# Extractor date format for GetAttDataBetweenDates
_DBDFMT
=
"
%Y-%m-%d %H:%M:%S
"
_DBDFMT
=
"
%Y-%m-%d %H:%M:%S
"
...
@@ -19,11 +34,106 @@ _DBDFMT = "%Y-%m-%d %H:%M:%S"
...
@@ -19,11 +34,106 @@ _DBDFMT = "%Y-%m-%d %H:%M:%S"
_DBDFMT2
=
"
%d-%m-%Y %H:%M:%S
"
_DBDFMT2
=
"
%d-%m-%Y %H:%M:%S
"
##########################################################################
##########################################################################
"""
Commodity private functions
"""
### Commodity private functions ###
##########################################################################
# Vectorized fromtimestamp function
# Vectorized fromtimestamp function
_ArrayTimeStampToDatetime
=
np
.
vectorize
(
datetime
.
datetime
.
fromtimestamp
)
_ArrayTimeStampToDatetime
=
np
.
vectorize
(
datetime
.
datetime
.
fromtimestamp
)
def
_check_initialized
():
"""
Check if the module is initialized, raise exception RuntimeError if not.
"""
global
_extractors
if
None
in
_extractors
:
logger
.
error
(
"
Module {0} is not initialied. You should run {0}.init().
"
.
format
(
__name__
))
raise
RuntimeError
(
"
Module not initialized
"
)
def
_dateparse
(
datestr
):
"""
Convenient function to parse date strings.
Global format is %Y-%m-%d-%H:%M:%S and it can be reduced to be less precise.
Parameters
---------
datestr : string
Date as a string, format %Y-%m-%d-%H:%M:%S or less precise.
Exceptions
----------
ValueError
If the parsing failed.
Returns
-------
date : datetime.datetime
Parsed date
"""
# This gives all format that will be tried, in order.
# Stop on first parse success. Raise error if none succeed.
fmt
=
[
"
%Y-%m-%d-%H:%M:%S
"
,
"
%Y-%m-%d-%H:%M
"
,
"
%Y-%m-%d-%H
"
,
"
%Y-%m-%d
"
,
"
%Y-%m
"
,
]
date
=
None
for
f
in
fmt
:
try
:
date
=
datetime
.
datetime
.
strptime
(
datestr
,
f
)
except
ValueError
:
continue
else
:
break
else
:
raise
ValueError
(
"
Could not parse argument to a date
"
)
return
date
##########################################################################
### Module private variables ###
##########################################################################
# Tuple of extractor for HDB and TDB
_extractors
=
(
None
,
None
)
# Tuple for attribute tables
_AttrTables
=
(
None
,
None
)
##########################################################################
### Module initialisation functions ###
##########################################################################
def
init
(
HdbExtractorPath
=
"
archiving/hdbextractor/2
"
,
TdbExtractorPath
=
"
archiving/tdbextractor/2
"
,
):
"""
Initialize the module.
Instanciate tango.DeviceProxy for extractors (TDB and HDB)
HdbExtractorPath, TdbExtractorPath: string
Tango path to the extractors.
"""
global
_extractors
logger
.
debug
(
"
Instanciating extractors device proxy...
"
)
_extractors
=
(
tango
.
DeviceProxy
(
HdbExtractorPath
),
tango
.
DeviceProxy
(
TdbExtractorPath
))
logger
.
debug
(
"
{} and {} instanciated.
"
.
format
(
*
_extractors
))
logger
.
debug
(
"
Configuring extractors device proxy...
"
)
for
e
in
_extractors
:
# set timeout to 3 sec
e
.
set_timeout_millis
(
3000
)
logger
.
debug
(
"
Filling attributes lookup tables...
"
)
_AttrTables
=
tuple
(
e
.
getattnameall
()
for
e
in
_extractors
)
logger
.
debug
(
"
HDB: {} TDB: {} attributes counted
"
.
format
(
len
(
_AttrTables
[
0
]),
len
(
_AttrTables
[
1
])))
class
ArchiveExtractor
:
class
ArchiveExtractor
:
...
...
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