Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
98 lines (71 loc) · 2.69 KB
/
Copy pathclient.py
File metadata and controls
98 lines (71 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import sys
import time
sys.path.append("../../../generated/openapi_client")
import generated.openapi_client as dres
USER = "MyUserName"
PASS = "MySuperS3cu23P4ssw0rd"
BASE_PATH = "http://localhost:8080"
configuration = dres.Configuration(
host = BASE_PATH
)
client = dres.ApiClient(configuration)
#initialize user api client
user_api = dres.UserApi(client)
#initialize evaluation run info client
run_info_api = dres.EvaluationClientApi(client)
#initialize submission api client
submission_api = dres.SubmissionApi(client)
#initialize logging api client
log_api = dres.LogApi(client)
#login request
print("Trying to log in to ", BASE_PATH, " with user ", USER)
login = user_api.post_api_v2_login(dres.LoginRequest(username = USER, password = PASS))
print("login successful")
print("user:", login.username)
print("role:", login.role)
print("session:", login.session_id)
#store session token for future requests
session = login.session_id
current_runs = run_info_api.get_api_v2_client_evaluation_list(session = session)
print("found", len(current_runs), "ongoing evaluation runs")
for run in current_runs:
print(run.name, run.id, run.status)
print(run.template_description)
print()
#find active evaluation run
evaluation_id = list(filter(lambda evaluation: evaluation.status == dres.ApiEvaluationStatus.ACTIVE , current_runs))[0]
#submit item
submission_response = submission_api.post_api_v2_submit_by_evaluation_id(
evaluation_id = evaluation_id,
api_client_submission = dres.ApiClientSubmission(
answer_sets = [
dres.ApiClientAnswerSet(
answers = [
dres.ApiClientAnswer(
media_item_name = "some_item_name",
start = 10_000,
end = 10_000
)
]
)
]
),
session = session)
if submission_response.status:
print("The submission was successfully sent to the server.")
#send log
log_api.post_api_v2_log_result_by_evaluation_id(
evaluation_id = evaluation_id,
session = session,
query_result_log = dres.QueryResultLog(
timestamp = round(time.time() * 1000),
sort_type = "list",
results = [
dres.RankedAnswer(rank = 1, answer = dres.ApiClientAnswer(media_item_name = "some_item_name", start = 1000, end = 1000)),
dres.RankedAnswer(rank = 2, answer = dres.ApiClientAnswer(media_item_name = "some_item_name", start = 5000, end = 5000)),
dres.RankedAnswer(rank = 3, answer = dres.ApiClientAnswer(media_item_name = "some_other_item_name", start = 12000, end = 12000)),
]
)
)
#logout
logout = user_api.get_api_v2_logout(session = session)