Skip to content

Commit 1257f10

Browse files
authored
Enh/demo tools (#869)
Implements tools under [scripts](scripts) folder - Moves isan demo from sandbox to [scripts/demo](scripts/demo) - Create converter tool to convert template studies into csv that can be injected via portainer ( #866 ) * Converts json projects to csv * Changes create_portal_markdown - adds cli - hard codes mock-codes - produces table of codes as csv file which is importable into postgres using adminer * Demo unnecesary in osparc.io * MaG review: Changes url master. Regenerated portal_markdown and invitation timestamps
1 parent 24ae5b6 commit 1257f10

File tree

10 files changed

+224
-79
lines changed

10 files changed

+224
-79
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
/ops/ @sanderegg, @pcrespov
88
/docs/ @pcrespov
99
/packages/service-library @pcrespov
10+
/scripts/demo @odeimaiz, @pcrespov
1011
/scripts/json-schema-to-openapi-schema @sanderegg
12+
/scripts/template-projects @odeimaiz, @pcrespov
1113
/services/dy* @sanderegg
1214
/services/sidecar @pcrespov, @mguidon
1315
/services/web/client @odeimaiz, @oetiker, @ignapas
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
code,user_id,action,data,created_at
2+
AOuAejUGDv34i9QtxYK61V7GZmCE4B,1,INVITATION,"{
3+
""guest"": ""[email protected]"" ,
4+
""host"" : ""[email protected]""
5+
}",2019-06-07 14:38:56.202844
6+
uQhnK20tuXWdleIRhZaBcmrWaIrb2p,1,INVITATION,"{
7+
""guest"": ""[email protected]"" ,
8+
""host"" : ""[email protected]""
9+
}",2019-06-07 14:38:56.202856
10+
weedI0YvR6tMA7XEpaxgJZT2Z8SCUy,1,INVITATION,"{
11+
""guest"": ""[email protected]"" ,
12+
""host"" : ""[email protected]""
13+
}",2019-06-07 14:38:56.202860
14+
Q9m5C98ALYZDr1BjilkaaXWSMKxU21,1,INVITATION,"{
15+
""guest"": ""[email protected]"" ,
16+
""host"" : ""[email protected]""
17+
}",2019-06-07 14:38:56.202864
18+
jvhSQfoAAfin4htKgvvRYi3pkYdPhM,1,INVITATION,"{
19+
""guest"": ""[email protected]"" ,
20+
""host"" : ""[email protected]""
21+
}",2019-06-07 14:38:56.202867
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
""" This script produces a markdown document with links to template studies
3+
4+
Aims to emulate links
5+
6+
"""
7+
import argparse
8+
import json
9+
import logging
10+
import sys
11+
from datetime import datetime
12+
from pathlib import Path
13+
14+
from simcore_service_webserver.login.registration import (URL,
15+
get_invitation_url)
16+
from simcore_service_webserver.login.utils import get_random_string
17+
from simcore_service_webserver.resources import resources
18+
from contextlib import contextmanager
19+
20+
21+
CONFIRMATIONS_FILENAME = "confirmations-invitations.csv"
22+
23+
ISSUE = r"https://github.com/ITISFoundation/osparc-simcore/issues/"
24+
25+
HOST_URLS_MAPS = [
26+
('localhost', r'http://127.0.0.1:9081'),
27+
('master', r'http://master.osparc.io'),
28+
('staging', r'https://staging.osparc.io'),
29+
('production', r'https://osparc.io')
30+
]
31+
32+
MOCK_CODES = [
33+
"AOuAejUGDv34i9QtxYK61V7GZmCE4B",
34+
"uQhnK20tuXWdleIRhZaBcmrWaIrb2p",
35+
"weedI0YvR6tMA7XEpaxgJZT2Z8SCUy",
36+
"Q9m5C98ALYZDr1BjilkaaXWSMKxU21",
37+
"jvhSQfoAAfin4htKgvvRYi3pkYdPhM"
38+
]
39+
40+
current_path = Path( sys.argv[0] if __name__ == "__main__" else __file__).resolve()
41+
logging.basicConfig(level=logging.INFO)
42+
43+
log = logging.getLogger(__name__)
44+
45+
46+
@contextmanager
47+
def _open(filepath):
48+
filepath = Path(filepath)
49+
50+
log.info("Writing %s ... ", filepath)
51+
with open(filepath, "wt") as fh:
52+
yield fh
53+
log.info("%s ready", filepath.name)
54+
55+
56+
def write_list(hostname, url, data, fh):
57+
print("## studies available @{}".format(hostname), file=fh)
58+
print("", file=fh)
59+
for prj in data:
60+
print("- [{name}]({base_url}/study/{uuid})".format(base_url=url, **prj), file=fh)
61+
print("", file=fh)
62+
63+
64+
def main(mock_codes):
65+
66+
with resources.stream('data/fake-template-projects.isan.json') as fp:
67+
data = json.load(fp)
68+
69+
file_path = str(current_path.with_suffix(".md")).replace("create_", "")
70+
with _open(file_path) as fh:
71+
print("<!-- Generated by {} on {} -->".format(current_path.name, datetime.utcnow()), file=fh)
72+
print("# THE PORTAL Emulator\n", file=fh)
73+
print("This pages is for testing purposes for issue [#{1}]({0}{1})\n".format(ISSUE, 715), file=fh)
74+
for hostname, url in HOST_URLS_MAPS:
75+
write_list(hostname, url, data, fh)
76+
77+
print("---", file=fh)
78+
79+
print("# INVITATIONS Samples:", file=fh)
80+
for hostname, url in HOST_URLS_MAPS[:-1]:
81+
# invitations for production are not openly published
82+
print("## urls for @{}".format(hostname), file=fh)
83+
for code in mock_codes:
84+
print("- [{code}]({base_url})".format(
85+
base_url=get_invitation_url({'code':code, 'action':"INVITATION"}, URL(url)),
86+
code=code),
87+
file=fh)
88+
89+
print("", file=fh)
90+
91+
92+
file_path = current_path.parent / CONFIRMATIONS_FILENAME
93+
with _open(file_path) as fh:
94+
print("code,user_id,action,data,created_at", file=fh)
95+
for code in mock_codes:
96+
print('%s,1,INVITATION,"{' % code, file=fh)
97+
print('""guest"": ""[email protected]"" ,', file=fh)
98+
print('""host"" : ""[email protected]""', file=fh)
99+
print('}",%s' % datetime.now().isoformat(sep=" "), file=fh)
100+
101+
102+
if __name__ == "__main__":
103+
parser = argparse.ArgumentParser(description='Generates some material for demos')
104+
parser.add_argument("--renew-invitation-codes", "-c", action="store_true",
105+
help="Regenerates codes for invitations")
106+
107+
args = parser.parse_args()
108+
109+
codes = MOCK_CODES
110+
if args.renew_invitation_codes:
111+
codes =[ get_random_string(30) for _ in MOCK_CODES]
112+
113+
main(codes)

services/web/server/tests/sandbox/study_access_demo.md renamed to scripts/demo/portal_markdown.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Generated by create_portal_markdown.py on 2019-06-04 17:34:25.051383 -->
1+
<!-- Generated by create_portal_markdown.py on 2019-06-07 12:38:56.197106 -->
22
# THE PORTAL Emulator
33

44
This pages is for testing purposes for issue [#715](https://github.com/ITISFoundation/osparc-simcore/issues/715)
@@ -7,23 +7,29 @@ This pages is for testing purposes for issue [#715](https://github.com/ITISFound
77

88
- [ISAN: 2D Plot](http://127.0.0.1:9081/study/template-uuid-4d5e-b80e-401c8066782f)
99
- [ISAN: 3D Paraview](http://127.0.0.1:9081/study/template-uuid-4d5e-b80e-401c8066781f)
10-
- [ISAN: UCDavis use case: 0D](http://127.0.0.1:9081/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
1110
- [ISAN: MattWard use case](http://127.0.0.1:9081/study/template-uuid-420d-b82d-e80bfa272ebd)
11+
- [ISAN: UCDavis use case: 0D](http://127.0.0.1:9081/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
1212

1313
## studies available @master
1414

15-
- [ISAN: 2D Plot](http://osparc01.itis.ethz.ch:9081/study/template-uuid-4d5e-b80e-401c8066782f)
16-
- [ISAN: 3D Paraview](http://osparc01.itis.ethz.ch:9081/study/template-uuid-4d5e-b80e-401c8066781f)
17-
- [ISAN: UCDavis use case: 0D](http://osparc01.itis.ethz.ch:9081/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
18-
- [ISAN: MattWard use case](http://osparc01.itis.ethz.ch:9081/study/template-uuid-420d-b82d-e80bfa272ebd)
15+
- [ISAN: 2D Plot](http://master.osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
16+
- [ISAN: 3D Paraview](http://master.osparc.io/study/template-uuid-4d5e-b80e-401c8066781f)
17+
- [ISAN: MattWard use case](http://master.osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd)
18+
- [ISAN: UCDavis use case: 0D](http://master.osparc.io/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
1919

2020
## studies available @staging
2121

2222
- [ISAN: 2D Plot](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
2323
- [ISAN: 3D Paraview](https://staging.osparc.io/study/template-uuid-4d5e-b80e-401c8066781f)
24-
- [ISAN: UCDavis use case: 0D](https://staging.osparc.io/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
2524
- [ISAN: MattWard use case](https://staging.osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd)
25+
- [ISAN: UCDavis use case: 0D](https://staging.osparc.io/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
26+
27+
## studies available @production
2628

29+
- [ISAN: 2D Plot](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066782f)
30+
- [ISAN: 3D Paraview](https://osparc.io/study/template-uuid-4d5e-b80e-401c8066781f)
31+
- [ISAN: MattWard use case](https://osparc.io/study/template-uuid-420d-b82d-e80bfa272ebd)
32+
- [ISAN: UCDavis use case: 0D](https://osparc.io/study/template-uuid-1234-a1a7-f7d4f3a8f26b)
2733

2834
---
2935
# INVITATIONS Samples:
@@ -34,21 +40,15 @@ This pages is for testing purposes for issue [#715](https://github.com/ITISFound
3440
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://127.0.0.1:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
3541
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://127.0.0.1:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
3642
## urls for @master
37-
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
38-
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
39-
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
40-
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
41-
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
43+
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://master.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
44+
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://master.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
45+
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://master.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
46+
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://master.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
47+
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://master.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
4248
## urls for @staging
4349
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://staging.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
4450
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://staging.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
4551
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://staging.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
4652
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://staging.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
4753
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://staging.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
48-
## urls for @osparc.io
49-
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
50-
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
51-
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
52-
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
53-
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
5454

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
""" Produces csv with a table of projects that can be inserted in the postgres db by importing it via adminer website
2+
3+
"""
4+
5+
import json
6+
7+
from change_case import ChangeCase
8+
9+
from simcore_service_webserver.projects.projects_models import ProjectType, projects
10+
from simcore_service_webserver.resources import resources
11+
12+
TEMPLATE_STUDIES_NAME = "data/fake-template-projects.isan.json"
13+
TEMPLATE_STUDIES_TABLE = "template-projects-table.csv"
14+
15+
COLS = [c.name for c in projects.columns if c!=projects.c.id] #pylint: disable=not-an-iterable
16+
PROJECT_KEYS = [ChangeCase.snake_to_camel(key) for key in COLS]
17+
ROW = ",".join( ["{}", ]*len(PROJECT_KEYS) )
18+
19+
def normalize(key, value):
20+
if key == "type":
21+
return ProjectType.TEMPLATE.name
22+
23+
if value is None:
24+
return '""'
25+
26+
value = str(value)
27+
value = value.replace("'", '"')
28+
value = value.replace('"', '""')
29+
value = '"' + value + '"'
30+
return value
31+
32+
33+
34+
def main():
35+
with resources.stream(TEMPLATE_STUDIES_NAME) as fp:
36+
data = json.load(fp)
37+
38+
with open(TEMPLATE_STUDIES_TABLE, 'wt') as fh:
39+
print(",".join(COLS), file=fh)
40+
for project in data:
41+
values = [normalize(key, project.get(key)) for key in PROJECT_KEYS]
42+
print(ROW.format(*values), file=fh)
43+
44+
45+
if __name__ == "__main__":
46+
main()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type,uuid,name,description,thumbnail,prj_owner,creation_date,last_change_date,workbench
2+
TEMPLATE,"template-uuid-4d5e-b80e-401c8066782f","ISAN: 2D Plot","2D RawGraphs viewer with one input","","maiz","2019-05-24T10:36:57.813Z","2019-05-24T11:36:12.015Z","{""template-uuid-48eb-a9d2-aaad6b72400a"": {""key"": ""simcore/services/frontend/file-picker"", ""version"": ""1.0.0"", ""label"": ""File Picker"", ""inputs"": {}, ""inputNodes"": [], ""outputNode"": False, ""outputs"": {""outFile"": {""store"": 1, ""path"": ""Shared Data/Height-Weight""}}, ""progress"": 100, ""thumbnail"": """", ""position"": {""x"": 100, ""y"": 100}}, ""template-uuid-4c63-a705-03a2c339646c"": {""key"": ""simcore/services/dynamic/raw-graphs"", ""version"": ""2.8.0"", ""label"": ""2D plot"", ""inputs"": {""input_1"": {""nodeUuid"": ""template-uuid-48eb-a9d2-aaad6b72400a"", ""output"": ""outFile""}}, ""inputNodes"": [""template-uuid-48eb-a9d2-aaad6b72400a""], ""outputNode"": False, ""outputs"": {}, ""progress"": 0, ""thumbnail"": """", ""position"": {""x"": 400, ""y"": 100}}}"
3+
TEMPLATE,"template-uuid-4d5e-b80e-401c8066781f","ISAN: 3D Paraview","3D Paraview viewer with two inputs","","maiz","2019-05-24T10:36:57.813Z"," 2019-05-24T10:38:12.888Z","{""template-uuid-403e-865a-8c5ca30671c6"": {""key"": ""simcore/services/frontend/file-picker"", ""version"": ""1.0.0"", ""label"": ""File Picker 1"", ""inputs"": {}, ""inputNodes"": [], ""outputNode"": False, ""outputs"": {""outFile"": {""store"": 1, ""path"": ""Shared Data/HField_Big.vtk""}}, ""progress"": 100, ""thumbnail"": """", ""position"": {""x"": 100, ""y"": 100}}, ""template-uuid-421f-be24-d44d112cc5c1"": {""key"": ""simcore/services/frontend/file-picker"", ""version"": ""1.0.0"", ""label"": ""File Picker 2"", ""inputs"": {}, ""inputNodes"": [], ""outputNode"": False, ""outputs"": {""outFile"": {""store"": 1, ""path"": ""Shared Data/bunny.vtk""}}, ""progress"": 100, ""thumbnail"": """", ""position"": {""x"": 100, ""y"": 250}}, ""template-uuid-4ecd-9636-62e619a9ca69"": {""key"": ""simcore/services/dynamic/3d-viewer"", ""version"": ""2.10.0"", ""label"": ""3D ParaViewer"", ""inputs"": {""A"": {""nodeUuid"": ""template-uuid-403e-865a-8c5ca30671c6"", ""output"": ""outFile""}, ""B"": {""nodeUuid"": ""template-uuid-421f-be24-d44d112cc5c1"", ""output"": ""outFile""}}, ""inputNodes"": [""template-uuid-403e-865a-8c5ca30671c6"", ""template-uuid-421f-be24-d44d112cc5c1""], ""outputNode"": False, ""outputs"": {}, ""progress"": 0, ""thumbnail"": """", ""position"": {""x"": 400, ""y"": 175}}}"
4+
TEMPLATE,"template-uuid-420d-b82d-e80bfa272ebd","ISAN: MattWard use case","MattWard Solver/PostPro viewer","","MattWard","2019-04-30T08:52:20.937Z","2019-04-30T08:59:26.090Z","{""template-uuid-4021-b2ef-b2e163bfbd16"": {""key"": ""simcore/services/dynamic/mattward-viewer"", ""version"": ""2.9.0"", ""label"": ""MattWard"", ""inputs"": {}, ""inputNodes"": [], ""outputNode"": False, ""outputs"": {}, ""progress"": 0, ""thumbnail"": """", ""position"": {""x"": 100, ""y"": 100}}}"
5+
TEMPLATE,"template-uuid-1234-a1a7-f7d4f3a8f26b","ISAN: UCDavis use case: 0D","Colleen Clancy Single Cell solver with a file picker and PostPro viewer","https://placeimg.com/171/96/tech/grayscale/?18.jpg","Colleen Clancy","2018-10-22T09:13:13.360Z","2018-10-22T09:33:41.858Z","{""template-uuid-4674-b758-946151cae351"": {""key"": ""simcore/services/frontend/file-picker"", ""version"": ""1.0.0"", ""label"": ""File Picker 0D"", ""inputs"": {}, ""inputNodes"": [], ""outputNode"": False, ""outputs"": {""outFile"": {""store"": 1, ""path"": ""Shared Data/initial_WStates""}}, ""progress"": 100, ""parent"": None, ""position"": {""x"": 50, ""y"": 150}}, ""template-uuid-409d-998c-c1f04de67f8b"": {""key"": ""simcore/services/comp/ucdavis-singlecell-cardiac-model"", ""version"": ""1.0.0"", ""label"": ""DBP-Clancy-Rabbit-Single-Cell solver"", ""inputAccess"": {""Na"": ""ReadAndWrite"", ""Kr"": ""ReadOnly"", ""BCL"": ""ReadAndWrite"", ""NBeats"": ""ReadOnly"", ""Ligand"": ""Invisible"", ""cAMKII"": ""Invisible""}, ""inputs"": {""Na"": 0, ""Kr"": 0, ""BCL"": 200, ""NBeats"": 5, ""Ligand"": 0, ""cAMKII"": ""WT"", ""initfile"": {""nodeUuid"": ""template-uuid-4674-b758-946151cae351"", ""output"": ""outFile""}}, ""inputNodes"": [""template-uuid-4674-b758-946151cae351""], ""outputNode"": False, ""outputs"": {}, ""parent"": None, ""position"": {""x"": 300, ""y"": 150}}, ""template-uuid-43e7-9fda-cf9625e59986"": {""key"": ""simcore/services/dynamic/cc-0d-viewer"", ""version"": ""2.8.0"", ""label"": ""cc-0d-viewer"", ""inputs"": {""vm_1Hz"": {""nodeUuid"": ""template-uuid-409d-998c-c1f04de67f8b"", ""output"": ""out_4""}, ""all_results_1Hz"": {""nodeUuid"": ""template-uuid-409d-998c-c1f04de67f8b"", ""output"": ""out_1""}}, ""inputNodes"": [""template-uuid-409d-998c-c1f04de67f8b""], ""outputNode"": False, ""outputs"": {}, ""parent"": None, ""position"": {""x"": 550, ""y"": 150}}}"

0 commit comments

Comments
 (0)