Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jupyter-openbis-gui-widget
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
openbis
openbis-public
jupyter
jupyter-openbis-gui-widget
Commits
0c0c7113
Commit
0c0c7113
authored
6 years ago
by
Swen Vermeul
Browse files
Options
Downloads
Patches
Plain Diff
return sample/experiment attributes and properties when asked for datasets
parent
ca1e3eba
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
jupyter-openbis-extension/sample.py
+47
-25
47 additions, 25 deletions
jupyter-openbis-extension/sample.py
with
47 additions
and
25 deletions
jupyter-openbis-extension/sample.py
+
47
−
25
View file @
0c0c7113
from
notebook.base.handlers
import
IPythonHandler
import
numpy
as
np
import
os
from
.connection
import
openbis_connections
class
SampleHandler
(
IPythonHandler
):
"""
Handle the requests for /openbis/sample/connection/permId
"""
def
get_datasets
(
self
,
conn
,
permId
):
if
not
conn
.
is_session_active
():
try
:
conn
.
login
()
except
Exception
as
exc
:
self
.
write
({
"
reason
"
:
'
connection to {} could not be established: {}
'
.
format
(
conn
.
name
,
exc
)
})
def
get_entity_for_identifier
(
conn
,
identifier
):
entity
=
None
try
:
entity
=
conn
.
openbis
.
get_sample
(
identifier
)
except
Exception
as
exc
:
pass
sample
=
None
if
entity
is
None
:
try
:
sample
=
conn
.
openbis
.
get_
sample
(
permId
)
entity
=
conn
.
openbis
.
get_
experiment
(
identifier
)
except
Exception
as
exc
:
self
.
set_status
(
404
)
self
.
write
({
"
reason
"
:
'
No such sample: {}
'
.
format
(
permId
)
})
if
sample
is
None
:
return
pass
return
entity
def
get_datasets
(
entity
):
datasets
=
sample
.
get_datasets
().
df
datasets
.
replace
({
np
.
nan
:
None
},
inplace
=
True
)
# replace NaN with None, otherwise we cannot convert it correctly
return
datasets
.
to_dict
(
orient
=
'
records
'
)
# is too stupid to handle NaN
datasets
=
entity
.
get_datasets
().
df
datasets
.
replace
({
np
.
nan
:
None
},
inplace
=
True
)
# replace NaN with None, otherwise we cannot convert it correctly
datasets_dict
=
datasets
.
to_dict
(
orient
=
'
records
'
)
# is too stupid to handle NaN
return
datasets_dict
class
SampleHandler
(
IPythonHandler
):
"""
Handle the requests for /openbis/sample/connection/permId
"""
def
get
(
self
,
**
params
):
"""
Handle a request to /openbis/sample/connection_name/permId
download the data and return a message
download the data
set list
and return a message
"""
try
:
conn
=
openbis_connections
[
params
[
'
connection_name
'
]]
except
KeyError
:
self
.
set_status
(
500
)
self
.
write
({
"
reason
"
:
'
connection {} was not found
'
.
format
(
params
[
'
connection_name
'
]
...
...
@@ -44,11 +46,31 @@ class SampleHandler(IPythonHandler):
})
return
datasets
=
self
.
get_datasets
(
conn
,
params
[
'
permId
'
])
if
not
conn
.
is_session_active
():
try
:
conn
.
login
()
except
Exception
as
exc
:
self
.
set_status
(
500
)
self
.
write
({
"
reason
"
:
'
connection to {} could not be established: {}
'
.
format
(
conn
.
name
,
exc
)
})
return
entity
=
get_entity_for_identifier
(
conn
,
params
[
'
identifier
'
])
if
entity
is
None
:
self
.
set_status
(
404
)
self
.
write
({
"
reason
"
:
'
No such Sample or Experiment: {}
'
.
format
(
identifier
)
})
return
None
datasets
=
get_datasets
(
entity
)
if
datasets
is
not
None
:
self
.
set_status
(
200
)
self
.
write
({
"
dataSets
"
:
datasets
"
dataSets
"
:
datasets
,
"
entity_attrs
"
:
entity
.
attrs
.
all
(),
"
entity_props
"
:
entity
.
props
.
all
(),
"
cwd
"
:
os
.
getcwd
()
})
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