Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
da993328
Commit
da993328
authored
5 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
added a parameter tester to the lib.tools module
parent
b13b87be
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
saqc/lib/tools.py
+84
-0
84 additions, 0 deletions
saqc/lib/tools.py
with
84 additions
and
0 deletions
saqc/lib/tools.py
+
84
−
0
View file @
da993328
...
...
@@ -7,6 +7,8 @@ from typing import Union
import
numpy
as
np
import
pandas
as
pd
import
numba
as
nb
import
logging
import
sys
from
..lib.types
import
PandasLike
,
ArrayLike
...
...
@@ -169,3 +171,85 @@ def offset2periods(input_offset, period_offset):
"""
return
offset2seconds
(
input_offset
)
/
offset2seconds
(
period_offset
)
def
check_QC_parameters
(
para_dict
,
called_by
):
"""
The function is designed to check parameter passed to the QC functions. The checking method is determined by
a nested dictionary that has to be passed to the parameter para dict and should have the following form:
check_dict = {value_name_1: {
'
value
'
: value,
'
type
'
: [class_1, class_2, ..., classM],
'
range
'
: [min , max],
'
member
'
:[e1, e2, ...,eN]}}
'
tests
'
: {test_1_name: test_func1,
test_2_name: test_func2,...
test_M_name: test_funcM},
value_name_2: {....}}
"""
global_checker
=
0
for
para
in
para_dict
.
keys
():
local_checker
=
0
sub_dict
=
para_dict
[
para
]
# check the type
if
'
type
'
in
sub_dict
.
keys
():
type_check
=
0
for
type
in
sub_dict
[
'
type
'
]:
if
isinstance
(
sub_dict
[
'
value
'
],
type
):
type_check
+=
1
if
type_check
==
0
:
logging
.
error
(
'
Parameter {} passed to Function {} didnt pass type Test.
'
'
It has to be one out of:
'
.
format
(
para
,
called_by
,
str
(
sub_dict
[
'
type
'
])))
local_checker
-=
1
if
local_checker
<
0
:
global_checker
-=
1
continue
# check range
if
'
range
'
in
sub_dict
.
keys
():
if
not
(
sub_dict
[
'
range
'
][
0
]
<
sub_dict
[
'
value
'
]
<
sub_dict
[
'
range
'
][
1
]):
logging
.
error
(
'
Parameter {} passed to Function {}, didnt pass range Test.
'
'
Range restrains for this parameter are:
'
'
[{}, {}]:
'
.
format
(
para
,
called_by
,
str
(
sub_dict
[
'
range
'
][
0
]),
sub_dict
[
'
range
'
][
1
]))
local_checker
-=
1
if
local_checker
<
0
:
global_checker
-=
1
continue
# member test
if
'
member
'
in
sub_dict
.
keys
():
if
not
(
sub_dict
[
'
value
'
]
in
sub_dict
[
'
member
'
]):
logging
.
error
(
'
Parameter {} passed to Function {}, didnt pass member-of Test.
'
'
The parameter has to be one out of:
'
'
{}.
'
.
format
(
para
,
called_by
,
str
(
sub_dict
[
'
member
'
])))
local_checker
-=
1
if
local_checker
<
0
:
global_checker
-=
1
continue
# apply individual tests
if
'
tests
'
in
sub_dict
.
keys
():
test_dict
=
sub_dict
[
'
tests
'
]
for
test
in
test_dict
.
keys
():
try
:
test_check
=
test_dict
[
test
](
sub_dict
[
'
value
'
])
except
:
logging
.
error
(
'
Parameter {}, passed to Function {}, caused the Exception: {},
'
'
when tested by {} - test.
'
.
format
(
para
,
called_by
,
sys
.
exc_info
()[
0
],
test
))
test_check
=
False
if
test_check
is
False
:
logging
.
error
(
'
Parameter {}, passed to Function {}, didnt pass the {} -
'
'
test.
'
.
format
(
para
,
called_by
,
test
))
local_checker
-=
1
break
if
local_checker
<
0
:
global_checker
-=
1
continue
return
global_checker
\ 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