Skip to content

Commit

Permalink
Enh/demo tools (#869)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pcrespov authored Jun 7, 2019
1 parent 24ae5b6 commit 1257f10
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
/ops/ @sanderegg, @pcrespov
/docs/ @pcrespov
/packages/service-library @pcrespov
/scripts/demo @odeimaiz, @pcrespov
/scripts/json-schema-to-openapi-schema @sanderegg
/scripts/template-projects @odeimaiz, @pcrespov
/services/dy* @sanderegg
/services/sidecar @pcrespov, @mguidon
/services/web/client @odeimaiz, @oetiker, @ignapas
Expand Down
21 changes: 21 additions & 0 deletions scripts/demo/confirmations-invitations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
code,user_id,action,data,created_at
AOuAejUGDv34i9QtxYK61V7GZmCE4B,1,INVITATION,"{
""guest"": ""[email protected]"" ,
""host"" : ""[email protected]""
}",2019-06-07 14:38:56.202844
uQhnK20tuXWdleIRhZaBcmrWaIrb2p,1,INVITATION,"{
""guest"": ""[email protected]"" ,
""host"" : ""[email protected]""
}",2019-06-07 14:38:56.202856
weedI0YvR6tMA7XEpaxgJZT2Z8SCUy,1,INVITATION,"{
""guest"": ""[email protected]"" ,
""host"" : ""[email protected]""
}",2019-06-07 14:38:56.202860
Q9m5C98ALYZDr1BjilkaaXWSMKxU21,1,INVITATION,"{
""guest"": ""[email protected]"" ,
""host"" : ""[email protected]""
}",2019-06-07 14:38:56.202864
jvhSQfoAAfin4htKgvvRYi3pkYdPhM,1,INVITATION,"{
""guest"": ""[email protected]"" ,
""host"" : ""[email protected]""
}",2019-06-07 14:38:56.202867
113 changes: 113 additions & 0 deletions scripts/demo/create_portal_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

""" This script produces a markdown document with links to template studies
Aims to emulate links
"""
import argparse
import json
import logging
import sys
from datetime import datetime
from pathlib import Path

from simcore_service_webserver.login.registration import (URL,
get_invitation_url)
from simcore_service_webserver.login.utils import get_random_string
from simcore_service_webserver.resources import resources
from contextlib import contextmanager


CONFIRMATIONS_FILENAME = "confirmations-invitations.csv"

ISSUE = r"https://github.com/ITISFoundation/osparc-simcore/issues/"

HOST_URLS_MAPS = [
('localhost', r'http://127.0.0.1:9081'),
('master', r'http://master.osparc.io'),
('staging', r'https://staging.osparc.io'),
('production', r'https://osparc.io')
]

MOCK_CODES = [
"AOuAejUGDv34i9QtxYK61V7GZmCE4B",
"uQhnK20tuXWdleIRhZaBcmrWaIrb2p",
"weedI0YvR6tMA7XEpaxgJZT2Z8SCUy",
"Q9m5C98ALYZDr1BjilkaaXWSMKxU21",
"jvhSQfoAAfin4htKgvvRYi3pkYdPhM"
]

current_path = Path( sys.argv[0] if __name__ == "__main__" else __file__).resolve()
logging.basicConfig(level=logging.INFO)

log = logging.getLogger(__name__)


@contextmanager
def _open(filepath):
filepath = Path(filepath)

log.info("Writing %s ... ", filepath)
with open(filepath, "wt") as fh:
yield fh
log.info("%s ready", filepath.name)


def write_list(hostname, url, data, fh):
print("## studies available @{}".format(hostname), file=fh)
print("", file=fh)
for prj in data:
print("- [{name}]({base_url}/study/{uuid})".format(base_url=url, **prj), file=fh)
print("", file=fh)


def main(mock_codes):

with resources.stream('data/fake-template-projects.isan.json') as fp:
data = json.load(fp)

file_path = str(current_path.with_suffix(".md")).replace("create_", "")
with _open(file_path) as fh:
print("<!-- Generated by {} on {} -->".format(current_path.name, datetime.utcnow()), file=fh)
print("# THE PORTAL Emulator\n", file=fh)
print("This pages is for testing purposes for issue [#{1}]({0}{1})\n".format(ISSUE, 715), file=fh)
for hostname, url in HOST_URLS_MAPS:
write_list(hostname, url, data, fh)

print("---", file=fh)

print("# INVITATIONS Samples:", file=fh)
for hostname, url in HOST_URLS_MAPS[:-1]:
# invitations for production are not openly published
print("## urls for @{}".format(hostname), file=fh)
for code in mock_codes:
print("- [{code}]({base_url})".format(
base_url=get_invitation_url({'code':code, 'action':"INVITATION"}, URL(url)),
code=code),
file=fh)

print("", file=fh)


file_path = current_path.parent / CONFIRMATIONS_FILENAME
with _open(file_path) as fh:
print("code,user_id,action,data,created_at", file=fh)
for code in mock_codes:
print('%s,1,INVITATION,"{' % code, file=fh)
print('""guest"": ""[email protected]"" ,', file=fh)
print('""host"" : ""[email protected]""', file=fh)
print('}",%s' % datetime.now().isoformat(sep=" "), file=fh)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generates some material for demos')
parser.add_argument("--renew-invitation-codes", "-c", action="store_true",
help="Regenerates codes for invitations")

args = parser.parse_args()

codes = MOCK_CODES
if args.renew_invitation_codes:
codes =[ get_random_string(30) for _ in MOCK_CODES]

main(codes)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Generated by create_portal_markdown.py on 2019-06-04 17:34:25.051383 -->
<!-- Generated by create_portal_markdown.py on 2019-06-07 12:38:56.197106 -->
# THE PORTAL Emulator

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

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

## studies available @master

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

## studies available @staging

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

## studies available @production

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

---
# INVITATIONS Samples:
Expand All @@ -34,21 +40,15 @@ This pages is for testing purposes for issue [#715](https://github.com/ITISFound
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://127.0.0.1:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://127.0.0.1:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
## urls for @master
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://osparc01.itis.ethz.ch:9081/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](http://master.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](http://master.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](http://master.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](http://master.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](http://master.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
## urls for @staging
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://staging.osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://staging.osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://staging.osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://staging.osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://staging.osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)
## urls for @osparc.io
- [AOuAejUGDv34i9QtxYK61V7GZmCE4B](https://osparc.io/#/registration/?invitation=AOuAejUGDv34i9QtxYK61V7GZmCE4B)
- [uQhnK20tuXWdleIRhZaBcmrWaIrb2p](https://osparc.io/#/registration/?invitation=uQhnK20tuXWdleIRhZaBcmrWaIrb2p)
- [weedI0YvR6tMA7XEpaxgJZT2Z8SCUy](https://osparc.io/#/registration/?invitation=weedI0YvR6tMA7XEpaxgJZT2Z8SCUy)
- [Q9m5C98ALYZDr1BjilkaaXWSMKxU21](https://osparc.io/#/registration/?invitation=Q9m5C98ALYZDr1BjilkaaXWSMKxU21)
- [jvhSQfoAAfin4htKgvvRYi3pkYdPhM](https://osparc.io/#/registration/?invitation=jvhSQfoAAfin4htKgvvRYi3pkYdPhM)

46 changes: 46 additions & 0 deletions scripts/template-projects/create_csv_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
""" Produces csv with a table of projects that can be inserted in the postgres db by importing it via adminer website
"""

import json

from change_case import ChangeCase

from simcore_service_webserver.projects.projects_models import ProjectType, projects
from simcore_service_webserver.resources import resources

TEMPLATE_STUDIES_NAME = "data/fake-template-projects.isan.json"
TEMPLATE_STUDIES_TABLE = "template-projects-table.csv"

COLS = [c.name for c in projects.columns if c!=projects.c.id] #pylint: disable=not-an-iterable
PROJECT_KEYS = [ChangeCase.snake_to_camel(key) for key in COLS]
ROW = ",".join( ["{}", ]*len(PROJECT_KEYS) )

def normalize(key, value):
if key == "type":
return ProjectType.TEMPLATE.name

if value is None:
return '""'

value = str(value)
value = value.replace("'", '"')
value = value.replace('"', '""')
value = '"' + value + '"'
return value



def main():
with resources.stream(TEMPLATE_STUDIES_NAME) as fp:
data = json.load(fp)

with open(TEMPLATE_STUDIES_TABLE, 'wt') as fh:
print(",".join(COLS), file=fh)
for project in data:
values = [normalize(key, project.get(key)) for key in PROJECT_KEYS]
print(ROW.format(*values), file=fh)


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions scripts/template-projects/template-projects-table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type,uuid,name,description,thumbnail,prj_owner,creation_date,last_change_date,workbench
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}}}"
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}}}"
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}}}"
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}}}"
Loading

0 comments on commit 1257f10

Please sign in to comment.