Skip to content

Commit 4bf4bfc

Browse files
committed
expose api services for submission object
1 parent f98bf93 commit 4bf4bfc

File tree

1 file changed

+228
-0
lines changed

1 file changed

+228
-0
lines changed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# TODO: The functions here should be moved into the `evaluation_services.py` file, once this branch is rebased onto those changes.
2+
3+
import json
4+
from typing import TYPE_CHECKING, List, Optional
5+
6+
if TYPE_CHECKING:
7+
from synapseclient import Synapse
8+
9+
10+
async def create_submission(request_body: dict, synapse_client: Optional["Synapse"] = None) -> dict:
11+
"""
12+
Creates a Submission and sends a submission notification email to the submitter's team members.
13+
14+
<https://rest-docs.synapse.org/rest/POST/evaluation/submission.html>
15+
16+
Arguments:
17+
request_body: The request body to send to the server.
18+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)` this will use the last created
19+
instance from the Synapse class constructor.
20+
"""
21+
from synapseclient import Synapse
22+
23+
client = Synapse.get_client(synapse_client=synapse_client)
24+
25+
uri = "/evaluation/submission"
26+
27+
response = await client.rest_post_async(uri, body=json.dumps(request_body))
28+
29+
return response
30+
31+
32+
async def get_submission(submission_id: str, synapse_client: Optional["Synapse"] = None) -> dict:
33+
"""
34+
Retrieves a Submission by its ID.
35+
36+
<https://rest-docs.synapse.org/rest/GET/evaluation/submission/subId.html>
37+
38+
Arguments:
39+
submission_id: The ID of the submission to fetch.
40+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)` this will use the last created
41+
instance from the Synapse class constructor.
42+
43+
Returns:
44+
The requested Submission.
45+
"""
46+
from synapseclient import Synapse
47+
48+
client = Synapse.get_client(synapse_client=synapse_client)
49+
50+
uri = f"/evaluation/submission/{submission_id}"
51+
52+
response = await client.rest_get_async(uri)
53+
54+
return response
55+
56+
57+
async def get_evaluation_submissions(
58+
evaluation_id: str,
59+
status: Optional[str] = None,
60+
limit: int = 20,
61+
offset: int = 0,
62+
synapse_client: Optional["Synapse"] = None
63+
) -> dict:
64+
"""
65+
Retrieves all Submissions for a specified Evaluation queue.
66+
67+
<https://rest-docs.synapse.org/rest/GET/evaluation/evalId/submission/all.html>
68+
69+
Arguments:
70+
evaluation_id: The ID of the evaluation queue.
71+
status: Optionally filter submissions by a submission status, such as SCORED, VALID,
72+
INVALID, OPEN, CLOSED or EVALUATION_IN_PROGRESS.
73+
limit: Limits the number of submissions in a single response. Default to 20.
74+
offset: The offset index determines where this page will start from.
75+
An index of 0 is the first submission. Default to 0.
76+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)`
77+
this will use the last created instance from the Synapse class constructor.
78+
79+
Returns:
80+
# TODO: Support pagination in the return type.
81+
A response JSON containing a paginated list of submissions for the evaluation queue.
82+
"""
83+
from synapseclient import Synapse
84+
85+
client = Synapse.get_client(synapse_client=synapse_client)
86+
87+
uri = f"/evaluation/{evaluation_id}/submission/all"
88+
query_params = {
89+
"limit": limit,
90+
"offset": offset
91+
}
92+
93+
if status:
94+
query_params["status"] = status
95+
96+
response = await client.rest_get_async(uri, **query_params)
97+
98+
return response
99+
100+
101+
async def get_user_submissions(
102+
evaluation_id: str,
103+
user_id: Optional[str] = None,
104+
limit: int = 20,
105+
offset: int = 0,
106+
synapse_client: Optional["Synapse"] = None
107+
) -> dict:
108+
"""
109+
Retrieves Submissions for a specified Evaluation queue and user.
110+
If user_id is omitted, this returns the submissions of the caller.
111+
112+
<https://rest-docs.synapse.org/rest/GET/evaluation/evalId/submission.html>
113+
114+
Arguments:
115+
evaluation_id: The ID of the evaluation queue.
116+
user_id: Optionally specify the ID of the user whose submissions will be returned.
117+
If omitted, this returns the submissions of the caller.
118+
limit: Limits the number of submissions in a single response. Default to 20.
119+
offset: The offset index determines where this page will start from.
120+
An index of 0 is the first submission. Default to 0.
121+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)`
122+
this will use the last created instance from the Synapse class constructor.
123+
124+
Returns:
125+
A response JSON containing a paginated list of user submissions for the evaluation queue.
126+
"""
127+
from synapseclient import Synapse
128+
129+
client = Synapse.get_client(synapse_client=synapse_client)
130+
131+
uri = f"/evaluation/{evaluation_id}/submission"
132+
query_params = {
133+
"limit": limit,
134+
"offset": offset
135+
}
136+
137+
if user_id:
138+
query_params["userId"] = user_id
139+
140+
response = await client.rest_get_async(uri, **query_params)
141+
142+
return response
143+
144+
145+
async def get_submission_count(
146+
evaluation_id: str,
147+
status: Optional[str] = None,
148+
synapse_client: Optional["Synapse"] = None
149+
) -> dict:
150+
"""
151+
Gets the number of Submissions for a specified Evaluation queue, optionally filtered by submission status.
152+
153+
<https://rest-docs.synapse.org/rest/GET/evaluation/evalId/submission/count.html>
154+
155+
Arguments:
156+
evaluation_id: The ID of the evaluation queue.
157+
status: Optionally filter submissions by a submission status, such as SCORED, VALID,
158+
INVALID, OPEN, CLOSED or EVALUATION_IN_PROGRESS.
159+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)`
160+
this will use the last created instance from the Synapse class constructor.
161+
162+
Returns:
163+
A response JSON containing the submission count.
164+
"""
165+
from synapseclient import Synapse
166+
167+
client = Synapse.get_client(synapse_client=synapse_client)
168+
169+
uri = f"/evaluation/{evaluation_id}/submission/count"
170+
query_params = {}
171+
172+
if status:
173+
query_params["status"] = status
174+
175+
response = await client.rest_get_async(uri, **query_params)
176+
177+
return response
178+
179+
180+
async def delete_submission(
181+
submission_id: str,
182+
synapse_client: Optional["Synapse"] = None
183+
) -> None:
184+
"""
185+
Deletes a Submission and its SubmissionStatus.
186+
187+
<https://rest-docs.synapse.org/rest/DELETE/evaluation/submission/subId.html>
188+
189+
Arguments:
190+
submission_id: The ID of the submission to delete.
191+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)`
192+
this will use the last created instance from the Synapse class constructor.
193+
"""
194+
from synapseclient import Synapse
195+
196+
client = Synapse.get_client(synapse_client=synapse_client)
197+
198+
uri = f"/evaluation/submission/{submission_id}"
199+
200+
await client.rest_delete_async(uri)
201+
202+
203+
async def cancel_submission(
204+
submission_id: str,
205+
synapse_client: Optional["Synapse"] = None
206+
) -> dict:
207+
"""
208+
Cancels a Submission. Only the user who created the Submission may cancel it.
209+
210+
<https://rest-docs.synapse.org/rest/PUT/evaluation/submission/subId/cancellation.html>
211+
212+
Arguments:
213+
submission_id: The ID of the submission to cancel.
214+
synapse_client: If not passed in and caching was not disabled by `Synapse.allow_client_caching(False)`
215+
this will use the last created instance from the Synapse class constructor.
216+
217+
Returns:
218+
The canceled Submission.
219+
"""
220+
from synapseclient import Synapse
221+
222+
client = Synapse.get_client(synapse_client=synapse_client)
223+
224+
uri = f"/evaluation/submission/{submission_id}/cancellation"
225+
226+
response = await client.rest_put_async(uri)
227+
228+
return response

0 commit comments

Comments
 (0)