Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
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
calibration
pycalibration
Commits
6021c964
Commit
6021c964
authored
3 months ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Try to simplify various bits of CalCat API use
parent
2add8f72
No related branches found
No related tags found
1 merge request
!1026
Feat[Jungfrau]: Inject CCVs using RESTful API
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/constants.py
+18
-28
18 additions, 28 deletions
src/cal_tools/constants.py
with
18 additions
and
28 deletions
src/cal_tools/constants.py
+
18
−
28
View file @
6021c964
...
...
@@ -32,10 +32,9 @@ class CCVAlreadyInjectedError(InjectionError):
@dataclass
class
ParameterConditionAttribute
:
value
:
str
parameter_id
:
str
=
""
# Default value, allowing assignment later
lower_deviation_value
:
float
=
0
upper_deviation_value
:
float
=
0
flg_available
:
str
=
'
t
rue
'
flg_available
:
bool
=
T
rue
description
:
str
=
''
...
...
@@ -51,13 +50,7 @@ def generate_unique_condition_name(
detector_type (str): detector type.
pdu_name (str): Physical detector unit db name.
pdu_uuid (float): Physical detector unit db id.
cond_params (dict): A list of dictionary with each condition
e.g. [{
"
parameter_name
"
:
"
Memory Cells
"
,
"
value
"
: 352.0,
"
lower-deviation
"
: 0.0,
"
upper-deviation
"
: 0.0
}]
cond_params (dict): Keys DB names, values ParameterConditionAttribute
Returns:
str: A unique name used for the table of conditions.
...
...
@@ -242,9 +235,9 @@ def get_or_create_calibration_constant(
calibration_id
=
cal_id
,
condition_id
=
cond_id
,
detector_type_id
=
det_type_id
,
flg_auto_approve
=
'
t
rue
'
,
flg_available
=
'
t
rue
'
,
description
=
""
,
flg_auto_approve
=
T
rue
,
flg_available
=
T
rue
,
description
=
""
,
)
try
:
cc_id
=
client
.
get
(
...
...
@@ -269,18 +262,15 @@ def create_condition(
cond_name
=
generate_unique_condition_name
(
detector_type
,
pdu_name
,
pdu_uuid
,
cond_params
)
# Add the missing parameter_id value in `ParameterConditionAttribute`s.
for
param
,
cond
in
cond_params
.
items
():
cond
.
parameter_id
=
client
.
parameter_by_name
(
param
)[
'
id
'
]
cond_params
[
param
]
=
asdict
(
cond
)
# Create condition table in database, if not available.
cond
=
dict
(
name
=
cond_name
,
parameters_conditions_attributes
=
list
(
cond_params
.
values
()),
flg_available
=
'
true
'
,
event_at
=
str
(
datetime
.
today
()),
# TODO: Why is this needed? it is not written in swagger.
description
=
''
,
parameters_conditions_attributes
=
[
asdict
(
cond
)
|
{
"
parameter_name
"
:
db_name
}
for
(
db_name
,
cond
)
in
cond_params
.
items
()
],
flg_available
=
True
,
description
=
''
,
)
resp
=
client
.
post
(
"
conditions/set_expected_condition
"
,
{
"
condition
"
:
cond
}
...
...
@@ -364,9 +354,9 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None):
if
report_to
:
report_path
=
Path
(
report_to
).
absolute
().
with_suffix
(
'
.pdf
'
)
resp
=
client
.
post
(
"
reports/set
"
,
dict
(
name
=
report_path
.
stem
,
name
=
report_path
.
name
,
file_path
=
str
(
report_path
),
flg_available
=
'
t
rue
'
,
flg_available
=
T
rue
,
description
=
""
,
))
report_id
=
resp
[
'
id
'
]
...
...
@@ -375,7 +365,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None):
pdu_id
=
client
.
pdu_by_name
(
pdu_name
)[
'
id
'
]
# Prepare CCV data and inject it to CALCAT.
start_idx
=
'
0
'
start_idx
=
0
ccv
=
dict
(
name
=
create_unique_ccv_name
(
start_idx
),
file_name
=
const_filename
,
...
...
@@ -389,10 +379,10 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None):
end_validity_at
=
''
,
begin_at
=
begin_at
,
start_idx
=
start_idx
,
end_idx
=
'
0
'
,
flg_deployed
=
'
t
rue
'
,
flg_good_quality
=
'
t
rue
'
,
description
=
''
,
end_idx
=
0
,
flg_deployed
=
T
rue
,
flg_good_quality
=
T
rue
,
description
=
''
,
)
try
:
client
.
post
(
"
calibration_constant_versions
"
,
ccv
)
...
...
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