Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Notebook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Tropolink
Notebook
Commits
ecd4fb74
Commit
ecd4fb74
authored
3 years ago
by
Gagaro
Browse files
Options
Downloads
Patches
Plain Diff
#59: get token from query params
parent
e5caff1c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Connectivities Analysis.ipynb
+23
-19
23 additions, 19 deletions
Connectivities Analysis.ipynb
nbconnectivity/utils.py
+11
-70
11 additions, 70 deletions
nbconnectivity/utils.py
with
34 additions
and
89 deletions
Connectivities Analysis.ipynb
+
23
−
19
View file @
ecd4fb74
...
...
@@ -32,29 +32,33 @@
"execution_count": 3,
"metadata": {
"init_cell": true,
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c733bdce80ec469c86e3f6382c7915b4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(HBox(children=(Button(description='Plot', disabled=True, layout=Layout(height='42px', widt…"
]
},
"metadata": {},
"output_type": "display_data"
"scrolled": false,
"pycharm": {
"name": "#%%\n"
}
]
,
}
,
"source": [
"importer = utils.ImporterUI()\n",
"importer.UI"
"%%javascript\n",
"var params = new URLSearchParams(window.location.search)\n",
"IPython.notebook.kernel.execute(\"ACCESS_TOKEN = '\" + params.get(\"access_token\") + \"'\");\n",
"IPython.notebook.kernel.execute(\"REFRESH_TOKEN = '\" + params.get(\"refresh_token\") + \"'\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"importer = utils.ImporterUI(access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)\n",
"importer.UI"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"metadata": {},
...
...
%% Cell type:markdown id: tags:
# Connectivities analysis
This notebook is prepared to help you in the analysis of your connectivities.
%% Cell type:code id: tags:
```
python
from
nbconnectivity
import
utils
```
%% Cell type:markdown id: tags:
## Visualize graph
%% Cell type:code id: tags:
```
python
importer
=
utils
.
ImporterUI
()
importer
.
UI
%%
javascript
var
params
=
new
URLSearchParams
(
window
.
location
.
search
)
IPython
.
notebook
.
kernel
.
execute
(
"
ACCESS_TOKEN =
'"
+
params
.
get
(
"
access_token
"
)
+
"'"
);
IPython
.
notebook
.
kernel
.
execute
(
"
REFRESH_TOKEN =
'"
+
params
.
get
(
"
refresh_token
"
)
+
"'"
);
```
%%
Output
%%
Cell type:code id: tags:
```
python
importer
=
utils
.
ImporterUI
(
access_token
=
ACCESS_TOKEN
,
refresh_token
=
REFRESH_TOKEN
)
importer
.
UI
```
%% Cell type:markdown id: tags:
## Use raw data
You can directly use the connectivity matrix and the dataframe containing your locations. They are accessible in the attributes
`connectivty_matrix`
and
`locations`
on the
`importerUI`
object.
%% Cell type:code id: tags:
```
python
importer
.
connectivity_matrix
```
%% Cell type:code id: tags:
```
python
importer
.
locations
```
...
...
This diff is collapsed.
Click to expand it.
nbconnectivity/utils.py
+
11
−
70
View file @
ecd4fb74
...
...
@@ -10,39 +10,28 @@ from .graph import *
class
ImporterUI
(
widgets
.
Box
):
def
__init__
(
self
):
def
__init__
(
self
,
access_token
,
refresh_token
):
"""
Constructor
"""
super
(
ImporterUI
,
self
).
__init__
()
self
.
access_token
=
None
self
.
refresh_token
=
None
self
.
access_token
=
access_token
self
.
refresh_token
=
refresh_token
# Initialize UI
self
.
init_ui
()
def
_login
(
self
):
try
:
response
=
requests
.
post
(
TROPOLINK_API_TOKEN
,
data
=
{
'
username
'
:
self
.
userarea
.
value
,
'
password
'
:
self
.
userpassword
.
value
,
})
response
.
raise_for_status
()
data
=
response
.
json
()
self
.
access_token
=
data
[
'
access_token
'
]
self
.
refresh_token
=
data
[
'
refresh_token
'
]
except
requests
.
exceptions
.
RequestException
as
e
:
self
.
studies_errormsg
.
value
=
str
(
e
)
self
.
load_studies
()
def
_refresh
(
self
):
try
:
response
=
requests
.
post
(
TROPOLINK_API_REFRESH_TOKEN
,
data
=
{
'
refresh
_token
'
:
self
.
access_token
,
'
refresh
'
:
self
.
access_token
,
})
response
.
raise_for_status
()
data
=
response
.
json
()
self
.
access_token
=
data
[
'
access_token
'
]
self
.
refresh_token
=
data
[
'
refresh_token
'
]
except
requests
.
exceptions
.
RequestException
as
e
:
self
.
studies_errormsg
.
value
=
str
(
e
)
...
...
@@ -55,14 +44,9 @@ class ImporterUI(widgets.Box):
def
get
(
self
,
url
):
# Log in if necessary
if
self
.
access_token
is
None
:
self
.
_login
()
elif
self
.
_is_access_token_expired
(
self
.
access_token
):
if
self
.
_is_access_token_expired
(
self
.
access_token
):
self
.
access_token
=
None
self
.
_refresh
()
# Could not log in
if
self
.
access_token
is
None
:
return
try
:
r
=
requests
.
get
(
url
,
headers
=
{
'
Authorization
'
:
f
'
Bearer
{
self
.
access_token
}
'
})
r
.
raise_for_status
()
...
...
@@ -86,16 +70,12 @@ class ImporterUI(widgets.Box):
self
.
widgetsDict
=
json
.
load
(
json_data
)
# Initialize widgets
self
.
init_username
(
self
.
widgetsDict
[
"
username
"
])
self
.
init_studies
(
self
.
widgetsDict
[
"
study_name
"
])
self
.
init_graph
(
self
.
widgetsDict
[
"
graph_plot
"
])
center
=
widgets
.
GridspecLayout
(
2
,
3
)
center
[
0
,
0
]
=
self
.
userarea
center
[
0
,
1
]
=
self
.
userpassword
center
[
0
,
2
]
=
self
.
userbutton
center
[
1
,
0
]
=
self
.
studies_dropdown
center
[
1
,
1
:]
=
self
.
studies_errormsg
center
=
widgets
.
GridspecLayout
(
1
,
2
)
center
[
0
,
0
]
=
self
.
studies_dropdown
center
[
0
,
1
]
=
self
.
studies_errormsg
self
.
UI
=
widgets
.
AppLayout
(
header
=
None
,
...
...
@@ -106,31 +86,6 @@ class ImporterUI(widgets.Box):
pane_heights
=
[
1
,
'
100px
'
,
'
170px
'
],
)
def
init_username
(
self
,
widgets_dict
):
"""
Initializes a text area to enter the username
:param widgetsDict: a dictionary with widgets strings
"""
self
.
userbutton
=
widgets
.
Button
(
description
=
widgets_dict
[
"
button
"
][
"
label
"
],
tooltip
=
widgets_dict
[
"
button
"
][
"
description
"
]
)
self
.
userarea
=
widgets
.
Text
(
placeholder
=
widgets_dict
[
"
userarea
"
][
"
placeholder
"
],
description
=
widgets_dict
[
"
userarea
"
][
"
label
"
],
description_tooltip
=
widgets_dict
[
"
userarea
"
][
"
description
"
]
)
self
.
userpassword
=
widgets
.
Password
(
placeholder
=
widgets_dict
[
"
password
"
][
"
placeholder
"
],
description
=
widgets_dict
[
"
password
"
][
"
label
"
],
description_tooltip
=
widgets_dict
[
"
password
"
][
"
description
"
]
)
self
.
userbutton
.
on_click
(
self
.
load_studies
)
self
.
userarea
.
observe
(
self
.
reinit_username
,
"
value
"
)
def
init_studies
(
self
,
widgets_dict
):
self
.
studies_dropdown
=
widgets
.
Dropdown
(
...
...
@@ -202,17 +157,7 @@ class ImporterUI(widgets.Box):
children
=
[
self
.
plotbutton
,
plotoptions
],
)
def
reinit_username
(
self
,
change
):
"""
Reinit UI when the username is changed
:param change: a username is provided
"""
self
.
userbutton
.
button_style
=
''
self
.
userbutton
.
icon
=
''
self
.
studies_errormsg
.
value
=
''
self
.
studies_dropdown
.
options
=
[]
def
load_studies
(
self
,
change
):
def
load_studies
(
self
):
"""
Load the list of previous studies names
"""
...
...
@@ -231,13 +176,9 @@ class ImporterUI(widgets.Box):
if
len
(
studies_list
)
==
0
:
self
.
studies_errormsg
.
value
=
"
No connectivities calculation was found.
"
self
.
userbutton
.
icon
=
''
self
.
userbutton
.
button_style
=
'
warning
'
else
:
studies_list
.
sort
()
self
.
studies_dropdown
.
options
=
studies_list
self
.
userbutton
.
icon
=
'
check
'
self
.
userbutton
.
button_style
=
'
success
'
def
get_connectivity_matrix
(
self
,
connectivity_name
):
"""
...
...
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