Skip to content

Commit 8a219f5

Browse files
authored
Merge pull request #164 from IndicoDataSolutions/update_submission_examples
updating submission examples to be more realistic
2 parents a09d4c1 + a141eaa commit 8a219f5

2 files changed

Lines changed: 20 additions & 41 deletions

File tree

examples/submission.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from indico import IndicoClient, IndicoConfig
22
from indico.filters import SubmissionFilter, or_
33
from indico.queries import (
4-
GenerateSubmissionResult,
54
JobStatus,
65
ListSubmissions,
76
RetrieveStorageObject,
@@ -31,34 +30,26 @@
3130
submission_ids = client.call(
3231
WorkflowSubmission(workflow_id=workflow_id, files=["./path_to_doc.pdf"])
3332
)
34-
submission_id = submission_ids[0]
3533

36-
result_url = client.call(SubmissionResult(submission_id, wait=True))
37-
result = client.call(RetrieveStorageObject(result_url.result))
34+
job = client.call(SubmissionResult(submission_ids[0], wait=True))
35+
result = client.call(RetrieveStorageObject(job.result))
3836
print(result)
39-
40-
client.call(UpdateSubmission(submission_id, retrieved=True))
37+
client.call(UpdateSubmission(submission_ids[0], retrieved=True))
4138

4239
"""
4340
Example 2
4441
List all submissions that are COMPLETE or FAILED
45-
Generate submission results for these
46-
Delay gathering the results until required
42+
Retrieve submission results for all COMPLETE and check errors on any FAILED
4743
"""
4844
sub_filter = or_(SubmissionFilter(status="COMPLETE"), SubmissionFilter(status="FAILED"))
4945
submissions = client.call(ListSubmissions(filters=sub_filter))
5046

51-
result_files = {
52-
submission: client.call(GenerateSubmissionResult(submission))
53-
for submission in submissions
54-
}
55-
56-
# Do other fun things...
57-
58-
for submission, result_file_job in result_files.items():
59-
result_url = client.call(JobStatus(id=result_file_job.id, wait=True))
60-
result = client.call(RetrieveStorageObject(result_url.result))
61-
print(f"Submission {submission.id} has result:\n{result}")
47+
for submission in submissions:
48+
if submission.status == "COMPLETE":
49+
result = client.call(RetrieveStorageObject(submission.result_file))
50+
print(f"Submission {submission.id} has result:\n{result}")
51+
else:
52+
print(f"Submission {submission.id} failed:\n{submission.errors}")
6253

6354

6455
"""
@@ -90,7 +81,6 @@
9081
submissions = client.call(WaitForSubmissions(submission_ids))
9182
submission = submissions[0]
9283
raw_result = client.call(RetrieveStorageObject(submission.result_file))
93-
raw_result = client.call(RetrieveStorageObject(submission.result_file))
9484
changes = raw_result["results"]["document"]["results"]
9585
rejected = False
9686
for model, preds in changes.items():

examples/workflow.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,20 @@
4343

4444
client.call(modelgroupreq)
4545

46+
4647
# Example 2: Simple submission.
4748

48-
# Return a list of workflows for this dataset id or an empty list if there are none
49-
workflows = client.call(ListWorkflows(dataset_ids=[dataset_id]))
50-
51-
# You can run this with the newly created workflow or with an existing one.
52-
if workflows:
53-
# Send a document through the workflow
54-
# Get back one Job per file
55-
jobs = client.call(
56-
WorkflowSubmission(
57-
workflow_id=workflows[0].id,
58-
files=["./path/to/sample.pdf"],
59-
submission=False,
60-
)
49+
# Send a document through the workflow
50+
# Get back one submission ID per file (List[int])
51+
submission_id = client.call(
52+
WorkflowSubmission(
53+
workflow_id=new_workflow.id, # REPLACE with your [int] workflow ID- can also be found in the UI
54+
files=["./path/to/sample.pdf"],
6155
)
62-
job = jobs[0]
63-
64-
# Retrieve and print your result
65-
status = client.call(JobStatus(id=job.id, wait=True))
66-
wf_result = client.call(RetrieveStorageObject(status.result))
67-
print(wf_result)
56+
)
57+
job = client.call(SubmissionResult(submission_id[0], wait=True))
58+
wf_result = client.call(RetrieveStorageObject(job.result))
6859

69-
else:
70-
print("You don't have any workflows for this dataset")
7160

7261
# Example 3 - Adding additional components.
7362

0 commit comments

Comments
 (0)