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
7498657e
Commit
7498657e
authored
5 years ago
by
Mikhail Karnevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Get run starting date from the MDC
parent
4dc10dd3
No related branches found
No related tags found
1 merge request
!157
Feat: Get run starting date from the MDC
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cal_tools/cal_tools/mdc_config.py
+11
-0
11 additions, 0 deletions
cal_tools/cal_tools/mdc_config.py
cal_tools/cal_tools/tools.py
+45
-3
45 additions, 3 deletions
cal_tools/cal_tools/tools.py
with
56 additions
and
3 deletions
cal_tools/cal_tools/mdc_config.py
0 → 100644
+
11
−
0
View file @
7498657e
class
MDC_config
:
mdconf
=
{}
mdconf
[
'
user-id
'
]
=
''
mdconf
[
'
user-secret
'
]
=
''
mdconf
[
'
user-email
'
]
=
'
calibration@example.com
'
mdconf
[
'
token-url
'
]
=
'
https://in.xfel.eu/metadata/oauth/token
'
mdconf
[
'
refresh-url
'
]
=
'
https://in.xfel.eu/metadata/oauth/token
'
mdconf
[
'
auth-url
'
]
=
'
https://in.xfel.eu/metadata/oauth/authorize
'
mdconf
[
'
scope
'
]
=
''
mdconf
[
'
base-api-url
'
]
=
'
https://in.xfel.eu/metadata/api/
'
This diff is collapsed.
Click to expand it.
cal_tools/cal_tools/tools.py
+
45
−
3
View file @
7498657e
...
@@ -13,14 +13,16 @@ from textwrap import dedent
...
@@ -13,14 +13,16 @@ from textwrap import dedent
from
time
import
sleep
from
time
import
sleep
from
urllib.parse
import
urljoin
from
urllib.parse
import
urljoin
import
dateutil.parser
import
ipykernel
import
ipykernel
from
metadata_client.metadata_client
import
MetadataClient
from
notebook.notebookapp
import
list_running_servers
from
notebook.notebookapp
import
list_running_servers
import
numpy
as
np
import
numpy
as
np
import
requests
import
requests
import
tabulate
import
tabulate
from
jinja2
import
Template
from
jinja2
import
Template
from
.mdc_config
import
MDC_config
from
xfel_calibrate
import
settings
from
xfel_calibrate
import
settings
...
@@ -425,15 +427,55 @@ def get_notebook_name():
...
@@ -425,15 +427,55 @@ def get_notebook_name():
return
environ
.
get
(
"
CAL_NOTEBOOK_NAME
"
,
"
Unknown Notebook
"
)
return
environ
.
get
(
"
CAL_NOTEBOOK_NAME
"
,
"
Unknown Notebook
"
)
def
get_dir_creation_date
(
directory
,
run
,
tsdir
=
False
):
def
get_run_info
(
proposal
,
run
):
"""
Return information about run from the MDC
:param proposal: proposal number
:param run: run number
:return: dictionary with run information
"""
mdconf
=
MDC_config
.
mdconf
mdc
=
MetadataClient
(
client_id
=
mdconf
[
'
user-id
'
],
client_secret
=
mdconf
[
'
user-secret
'
],
user_email
=
mdconf
[
'
user-email
'
],
token_url
=
mdconf
[
'
token-url
'
],
refresh_url
=
mdconf
[
'
refresh-url
'
],
auth_url
=
mdconf
[
'
auth-url
'
],
scope
=
mdconf
[
'
scope
'
],
base_api_url
=
mdconf
[
'
base-api-url
'
])
runs
=
mdc
.
get_proposal_runs
(
mdc
,
proposal_number
=
proposal
,
run_number
=
run
)
run_id
=
runs
[
'
data
'
][
'
runs
'
][
0
][
'
id
'
]
resp
=
mdc
.
get_run_by_id_api
(
run_id
)
return
resp
.
json
()
def
get_dir_creation_date
(
directory
,
run
,
tsdir
=
False
,
verbosity
=
0
):
"""
"""
Return modification time of oldest file.h5 in [directory]/[run]04
Return run starting time from the MDC.
If not succeeded, return modification time of oldest file.h5
in [directory]/[run]04.
:param directory: path to directory which contains runs
:param directory: path to directory which contains runs
:param run: run number
:param run: run number
:param tsdir: to get modification time of [directory]/[run]04.
:param tsdir: to get modification time of [directory]/[run]04.
:param verbosity: Level of verbosity (0 - silent)
:return: (datetime) modification time
:return: (datetime) modification time
"""
"""
try
:
path_list
=
list
(
filter
(
None
,
directory
.
strip
(
'
/
'
).
split
(
'
/
'
)))
proposal
=
int
(
path_list
[
-
2
][
1
:])
run_info
=
get_run_info
(
proposal
,
run
)
return
dateutil
.
parser
.
parse
(
run_info
[
'
begin_at
'
])
except
Exception
as
e
:
if
verbosity
>
0
:
print
(
e
)
ntries
=
100
ntries
=
100
while
ntries
>
0
:
while
ntries
>
0
:
try
:
try
:
...
...
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