|
| 1 | +""" |
| 2 | +Here is where you'll find the code for the Evaluation tutorial. |
| 3 | +""" |
| 4 | + |
| 5 | +from synapseclient import Synapse |
| 6 | +from synapseclient.models import Evaluation, Project |
| 7 | + |
| 8 | +syn = Synapse() |
| 9 | +syn.login() |
| 10 | + |
| 11 | +# REQUIRED: Set this to the Synapse user ID or team ID you want to grant permissions to |
| 12 | +# Do NOT leave this as None - the script will not work properly |
| 13 | +PRINCIPAL_ID = None # Replace with actual user/team ID |
| 14 | + |
| 15 | +# Retrieve the Project where your Evaluation will be stored |
| 16 | +project = Project(name="My uniquely named project about Alzheimer's Disease").get() |
| 17 | +project_id = project.id |
| 18 | + |
| 19 | +print(f"Working within Project: {project_id}") |
| 20 | + |
| 21 | +# Create a new Evaluation object |
| 22 | +evaluation = Evaluation( |
| 23 | + name="My Challenge Evaluation for Study ABC - Round 1", |
| 24 | + description="Evaluation for my data challenge", |
| 25 | + content_source=project_id, |
| 26 | + submission_instructions_message="Submit CSV files only", |
| 27 | + submission_receipt_message="Thank you for your submission!", |
| 28 | +) |
| 29 | + |
| 30 | +# Create the Evaluation on Synapse |
| 31 | +evaluation.store() |
| 32 | + |
| 33 | +print("Evaluation has been created with the following name and description:") |
| 34 | +print(evaluation.name) |
| 35 | +print(evaluation.description) |
| 36 | + |
| 37 | +# Update the Evaluation object's name and description |
| 38 | +evaluation.name = "My Challenge Evaluation for Study XYZ - Round 1" |
| 39 | +evaluation.description = "Updated description for my evaluation" |
| 40 | + |
| 41 | +# Update the Evaluation on Synapse |
| 42 | +evaluation.store() |
| 43 | + |
| 44 | +print("Evaluation has been updated with the following name and description:") |
| 45 | +print(evaluation.name) |
| 46 | +print(evaluation.description) |
| 47 | + |
| 48 | +# Confirm what's in Synapse matches the evaluation stored |
| 49 | +from_synapse = Evaluation(id=evaluation.id).get() |
| 50 | + |
| 51 | +print("The following evaluation has been retrieved from Synapse:") |
| 52 | +print(from_synapse) |
| 53 | + |
| 54 | +# Update the Evaluation's ACL on Synapse by adding a new user |
| 55 | +assert ( |
| 56 | + PRINCIPAL_ID is not None |
| 57 | +), "PRINCIPAL_ID must be set to the Synapse user ID or team ID you want to grant permissions to." |
| 58 | + |
| 59 | +evaluation.update_acl(principal_id=PRINCIPAL_ID, access_type=["READ", "SUBMIT"]) |
| 60 | + |
| 61 | +# Get the Evaluation's ACL to confirm the update |
| 62 | +acl = evaluation.get_acl() |
| 63 | +print("The following ACL has been retrieved from Synapse:") |
| 64 | +print(acl) |
| 65 | + |
| 66 | +# Now let's remove the user we just added from the Evaluation's ACL |
| 67 | +evaluation.update_acl(principal_id=PRINCIPAL_ID, access_type=[]) |
| 68 | + |
| 69 | +# Finally let's retrieve all Evaluations stored within this project, including the one we just created |
| 70 | +evaluations_list = Evaluation.get_evaluations_by_project(project_id) |
| 71 | + |
| 72 | +# Let's delete the evaluation we created for this tutorial, and any other evaluations in this project (uncomment below to enable deletion) |
| 73 | +# for evaluation_to_delete in evaluations_list: |
| 74 | +# print(f"Deleting evaluation: {evaluation_to_delete.name}") |
| 75 | +# evaluation_to_delete.delete() |
0 commit comments