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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
423d65a7
Commit
423d65a7
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-555
: Shortened error handling
parent
b8ffbcf2
No related branches found
No related tags found
1 merge request
!213
L2SS-555: Touch up archiver retriever
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tangostationcontrol/tangostationcontrol/toolkit/retriever.py
+15
-25
15 additions, 25 deletions
tangostationcontrol/tangostationcontrol/toolkit/retriever.py
with
15 additions
and
25 deletions
tangostationcontrol/tangostationcontrol/toolkit/retriever.py
+
15
−
25
View file @
423d65a7
...
@@ -74,10 +74,8 @@ class Retriever(ABC):
...
@@ -74,10 +74,8 @@ class Retriever(ABC):
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
att_conf_id
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
att_conf_id
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
return
result
[
0
]
return
result
[
0
]
except
TypeError
as
e
:
except
(
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
except
NoResultFound
as
e
:
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
@abstractmethod
@abstractmethod
def
get_attribute_datatype
(
self
,
attribute_fqname
:
str
):
def
get_attribute_datatype
(
self
,
attribute_fqname
:
str
):
...
@@ -103,8 +101,8 @@ class Retriever(ABC):
...
@@ -103,8 +101,8 @@ class Retriever(ABC):
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_id
==
base_class
.
att_conf_id
).
\
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_id
==
base_class
.
att_conf_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
att_conf_id
==
attr_id
,
base_class
.
data_time
>=
time_delta_db
,
\
filter
(
and_
(
self
.
ab
.
Attribute
.
att_conf_id
==
attr_id
,
base_class
.
data_time
>=
time_delta_db
,
\
base_class
.
data_time
<=
time_now_db
)).
order_by
(
base_class
.
data_time
).
all
()
base_class
.
data_time
<=
time_now_db
)).
order_by
(
base_class
.
data_time
).
all
()
except
AttributeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
f
"
Empty result:
Attribute
{
attribute_fqname
}
not found
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found
!
"
)
from
e
return
result
return
result
def
get_attribute_value_by_interval
(
self
,
attribute_fqname
:
str
,
start_time
:
datetime
,
stop_time
:
datetime
,
tablename
:
str
):
def
get_attribute_value_by_interval
(
self
,
attribute_fqname
:
str
,
start_time
:
datetime
,
stop_time
:
datetime
,
tablename
:
str
):
...
@@ -121,8 +119,8 @@ class Retriever(ABC):
...
@@ -121,8 +119,8 @@ class Retriever(ABC):
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_id
==
base_class
.
att_conf_id
).
\
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_id
==
base_class
.
att_conf_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
att_conf_id
==
attr_id
,
base_class
.
data_time
>=
str
(
start_time
),
\
filter
(
and_
(
self
.
ab
.
Attribute
.
att_conf_id
==
attr_id
,
base_class
.
data_time
>=
str
(
start_time
),
\
base_class
.
data_time
<=
str
(
stop_time
))).
order_by
(
base_class
.
data_time
).
all
()
base_class
.
data_time
<=
str
(
stop_time
))).
order_by
(
base_class
.
data_time
).
all
()
except
AttributeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
f
"
Empty result:
Attribute
{
attribute_fqname
}
not found
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found
!
"
)
from
e
return
result
return
result
class
RetrieverMySQL
(
Retriever
):
class
RetrieverMySQL
(
Retriever
):
...
@@ -162,10 +160,8 @@ class RetrieverMySQL(Retriever):
...
@@ -162,10 +160,8 @@ class RetrieverMySQL(Retriever):
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
data_type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_data_type_id
==
self
.
ab
.
DataType
.
att_conf_data_type_id
).
\
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
data_type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_data_type_id
==
self
.
ab
.
DataType
.
att_conf_data_type_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
return
result
[
0
]
return
result
[
0
]
except
TypeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
f
"
Attribute not
{
attribute_fqname
}
found!
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
except
NoResultFound
as
e
:
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
def
get_attribute_value_by_hours
(
self
,
attribute_fqname
:
str
,
hours
:
float
=
1.0
):
def
get_attribute_value_by_hours
(
self
,
attribute_fqname
:
str
,
hours
:
float
=
1.0
):
"""
"""
...
@@ -258,10 +254,8 @@ class RetrieverTimescale(Retriever):
...
@@ -258,10 +254,8 @@ class RetrieverTimescale(Retriever):
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_type_id
==
self
.
ab
.
DataType
.
att_conf_type_id
).
\
result
=
self
.
session
.
query
(
self
.
ab
.
DataType
.
type
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_type_id
==
self
.
ab
.
DataType
.
att_conf_type_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
return
result
[
0
]
return
result
[
0
]
except
TypeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
f
"
Attribute not
{
attribute_fqname
}
found!
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
except
NoResultFound
as
e
:
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
def
get_attribute_format
(
self
,
attribute_fqname
:
str
):
def
get_attribute_format
(
self
,
attribute_fqname
:
str
):
"""
"""
...
@@ -274,10 +268,8 @@ class RetrieverTimescale(Retriever):
...
@@ -274,10 +268,8 @@ class RetrieverTimescale(Retriever):
result
=
self
.
session
.
query
(
self
.
ab
.
Format
.
format
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_format_id
==
self
.
ab
.
Format
.
att_conf_format_id
).
\
result
=
self
.
session
.
query
(
self
.
ab
.
Format
.
format
).
join
(
self
.
ab
.
Attribute
,
self
.
ab
.
Attribute
.
att_conf_format_id
==
self
.
ab
.
Format
.
att_conf_format_id
).
\
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
return
result
[
0
]
return
result
[
0
]
except
TypeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
"
Attribute not found!
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
except
NoResultFound
as
e
:
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
def
get_attribute_tablename
(
self
,
attribute_fqname
:
str
):
def
get_attribute_tablename
(
self
,
attribute_fqname
:
str
):
"""
"""
...
@@ -289,10 +281,8 @@ class RetrieverTimescale(Retriever):
...
@@ -289,10 +281,8 @@ class RetrieverTimescale(Retriever):
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
table_name
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
result
=
self
.
session
.
query
(
self
.
ab
.
Attribute
.
table_name
).
filter
(
and_
(
self
.
ab
.
Attribute
.
domain
==
domain
,
self
.
ab
.
Attribute
.
family
==
family
,
\
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
self
.
ab
.
Attribute
.
member
==
member
,
self
.
ab
.
Attribute
.
name
==
name
)).
one
()
return
result
[
0
]
return
result
[
0
]
except
TypeError
as
e
:
except
(
AttributeError
,
TypeError
,
NoResultFound
)
as
e
:
raise
Exception
(
"
Attribute not found!
"
)
from
e
raise
ValueError
(
f
"
Attribute
{
attribute_fqname
}
not found!
"
)
from
e
except
NoResultFound
as
e
:
raise
Exception
(
f
"
No records of attribute
{
attribute_fqname
}
found in DB
"
)
from
e
def
get_attribute_value_by_hours
(
self
,
attribute_fqname
:
str
,
hours
:
float
=
1.0
):
def
get_attribute_value_by_hours
(
self
,
attribute_fqname
:
str
,
hours
:
float
=
1.0
):
"""
"""
...
@@ -311,4 +301,4 @@ class RetrieverTimescale(Retriever):
...
@@ -311,4 +301,4 @@ class RetrieverTimescale(Retriever):
"""
"""
tablename
=
self
.
get_attribute_tablename
(
attribute_fqname
)
tablename
=
self
.
get_attribute_tablename
(
attribute_fqname
)
return
super
().
get_attribute_value_by_interval
(
attribute_fqname
,
start_time
,
stop_time
,
tablename
)
return
super
().
get_attribute_value_by_interval
(
attribute_fqname
,
start_time
,
stop_time
,
tablename
)
\ No newline at end of file
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