Skip to content

Commit 0cbc65b

Browse files
authored
Upgrade/2.0.0 rc1 (#4)
* Regenerate API with 2.0.0-RC1 and fix compile errors * Implement draft of API V2 submission * Implement evaluation ID management * Update to 2.0.0-RC2 * Bump version
1 parent bbf1b70 commit 0cbc65b

File tree

7 files changed

+5953
-945
lines changed

7 files changed

+5953
-945
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# DresUnityInterface
22

3-
---
4-
** ATTENTION **
5-
** The unity interface points to version 1.3 of DRES, which is behind the current version v2.0.0-RC1""
6-
---
7-
83
An interface for [DRES](https://github.com/dres-dev/DRES), meant to be used in [Unity](https://unity.com/).
94

105
## Usage / Installation
155 KB
Binary file not shown.

Runtime/Libs/Dev.Dres.ClientApi.xml

Lines changed: 5799 additions & 904 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Dres/UnityClient/DresClient.cs

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using Dev.Dres.ClientApi.Model;
4-
using UnityEditor;
5+
using JetBrains.Annotations;
56

67
namespace Dres.Unityclient
78
{
@@ -15,7 +16,18 @@ public class DresClient
1516
/// <summary>
1617
/// The user state, available after <see cref="Login"/>.
1718
/// </summary>
18-
public UserDetails UserDetails;
19+
public ApiUser UserDetails { get; private set; }
20+
21+
/// <summary>
22+
/// List of the available evaluations for the current user.
23+
/// Must be updated manually with <see cref="UpdateEvaluations"/> before use.
24+
/// </summary>
25+
public List<ApiClientEvaluationInfo> EvaluationInfo { get; private set; }
26+
27+
/// <summary>
28+
/// The currently selected evaluation. Used for submissions.
29+
/// </summary>
30+
public ApiClientEvaluationInfo CurrentEvaluation { get; private set; }
1931

2032
/// <summary>
2133
/// Login to DRES with the currently loaded credentials.
@@ -27,27 +39,77 @@ public async Task Login()
2739
UserDetails = await DresWrapper.Login(config.user, config.password);
2840
}
2941

30-
42+
/// <summary>
43+
/// Updates the list of available evaluations for the current user.
44+
/// </summary>
45+
/// <returns>List of available evaluations</returns>
46+
public async Task<List<ApiClientEvaluationInfo>> UpdateEvaluations()
47+
{
48+
EvaluationInfo = await DresWrapper.ListClientEvaluations(UserDetails.SessionId);
49+
return EvaluationInfo;
50+
}
51+
52+
/// <summary>
53+
/// Sets the current evaluation to the one with the given id.
54+
/// </summary>
55+
/// <param name="evaluationId">The id of the evaluation to set as current</param>
56+
/// <returns>True if the evaluation was found and set, false otherwise</returns>
57+
public bool SetCurrentEvaluation(string evaluationId)
58+
{
59+
CurrentEvaluation = EvaluationInfo.Find(evaluation => evaluation.Id == evaluationId);
60+
return CurrentEvaluation != null;
61+
}
62+
63+
/// <summary>
64+
/// Submits the given item (and optionally start & end information) to the DRES instance as current user.
65+
/// </summary>
66+
/// <param name="item">The item name or identifier to submit</param>
67+
/// <param name="start">Optional, the item's start time</param>
68+
/// <param name="end">Optional, the item's end time</param>
69+
/// <param name="evaluationId">Manual override of the evaluation ID of the currently set evaluation.</param>
70+
/// <returns>The success / failure state of the operation</returns>
71+
public Task<SuccessfulSubmissionsStatus> SubmitResultV2(string item, long? start = null, long? end = null,
72+
[CanBeNull] string evaluationId = null)
73+
{
74+
evaluationId ??= CurrentEvaluation.Id;
75+
return DresWrapper.SubmitV2(UserDetails.SessionId, evaluationId, item, start, end);
76+
}
77+
78+
/// <summary>
79+
/// Submits the given text to the DRES instance as current user
80+
/// </summary>
81+
/// <param name="text">The text to submit (this can be anything).</param>
82+
/// <param name="evaluationId">Manual override of the evaluation ID of the currently set evaluation.</param>
83+
/// <returns>The success / failure state of the operation</returns>
84+
public Task<SuccessfulSubmissionsStatus> SubmitTextualResultV2(string text, [CanBeNull] string evaluationId = null)
85+
{
86+
evaluationId ??= CurrentEvaluation.Id;
87+
return DresWrapper.SubmitTextV2(UserDetails.SessionId, evaluationId, text);
88+
}
89+
90+
3191
/// <summary>
3292
/// Submits the given item (and optionally frame informaiton) to the DRES instance as current user.
3393
/// </summary>
3494
/// <param name="item">The item name or identifier to submit</param>
3595
/// <param name="frame">Optional, the item's frame number. This can likely be omitted, if there is no such
3696
/// concept as frames for the given item (e.g. for videos, a frame is reasonable while for images it isn't.</param>
3797
/// <returns>The success / failure state of the operation</returns>
38-
public async Task<SuccessfulSubmissionsStatus> SubmitResult(string item, int? frame = null)
98+
[Obsolete("Obsolete")]
99+
public Task<SuccessfulSubmissionsStatus> SubmitResult(string item, int? frame = null)
39100
{
40-
return await DresWrapper.Submit(item, UserDetails.SessionId, frame);
101+
return DresWrapper.Submit(item, UserDetails.SessionId, frame);
41102
}
42103

43104
/// <summary>
44105
/// Submits the given text to the DRES instance as current user
45106
/// </summary>
46107
/// <param name="text">The text to submit (this can be anything).</param>
47108
/// <returns>The success / failure state of the operation</returns>
48-
public async Task<SuccessfulSubmissionsStatus> SubmitTextualResult(string text)
109+
[Obsolete("Obsolete")]
110+
public Task<SuccessfulSubmissionsStatus> SubmitTextualResult(string text)
49111
{
50-
return await DresWrapper.SubmitText(text, UserDetails.SessionId);
112+
return DresWrapper.SubmitText(text, UserDetails.SessionId);
51113
}
52114

53115
/// <summary>
@@ -61,10 +123,10 @@ public async Task<SuccessfulSubmissionsStatus> SubmitTextualResult(string text)
61123
/// <param name="results">The results to log</param>
62124
/// <param name="events">The events associated with these results</param>
63125
/// <returns>The success / failure state of the operation</returns>
64-
public async Task<SuccessStatus> LogResults(long timestamp, string sortType, string resultSetAvailability,
126+
public Task<SuccessStatus> LogResults(long timestamp, string sortType, string resultSetAvailability,
65127
List<QueryResult> results, List<QueryEvent> events)
66128
{
67-
return await DresWrapper.LogResults(timestamp, sortType, resultSetAvailability, results, events,
129+
return DresWrapper.LogResults(timestamp, sortType, resultSetAvailability, results, events,
68130
UserDetails.SessionId);
69131
}
70132

@@ -76,9 +138,9 @@ public async Task<SuccessStatus> LogResults(long timestamp, string sortType, str
76138
/// <param name="timestamp">The client side timestamp of this log</param>
77139
/// <param name="events">The events to log</param>
78140
/// <returns>The success / failure state of the operation</returns>
79-
public async Task<SuccessStatus> LogQueryEvents(long timestamp, List<QueryEvent> events)
141+
public Task<SuccessStatus> LogQueryEvents(long timestamp, List<QueryEvent> events)
80142
{
81-
return await DresWrapper.LogQueryEvents(timestamp, events, UserDetails.SessionId);
143+
return DresWrapper.LogQueryEvents(timestamp, events, UserDetails.SessionId);
82144
}
83145
}
84146
}

Runtime/Scripts/Dres/UnityClient/DresWrapper.cs

Lines changed: 74 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using Dev.Dres.ClientApi.Api;
45
using Dev.Dres.ClientApi.Client;
@@ -14,39 +15,92 @@ namespace Dres.Unityclient
1415
/// </summary>
1516
internal static class DresWrapper
1617
{
17-
18+
internal static readonly EvaluationClientApi EvaluationClientApi = new(DresConfigManager.Instance.ApiConfiguration);
19+
1820
/// <summary>
1921
/// The deliberately single Logging Api instance of DRES. Used to send logs to DRES
2022
/// </summary>
21-
internal static readonly LogApi LogApi = new LogApi(DresConfigManager.Instance.ApiConfiguration);
23+
internal static readonly LogApi LogApi = new(DresConfigManager.Instance.ApiConfiguration);
24+
2225
/// <summary>
2326
/// The deliberately single Status Api instance of DRES. Used to get the status of DRES
2427
/// </summary>
25-
internal static readonly StatusApi StatusApi = new StatusApi(DresConfigManager.Instance.ApiConfiguration);
28+
internal static readonly StatusApi StatusApi = new(DresConfigManager.Instance.ApiConfiguration);
29+
2630
/// <summary>
2731
/// The deliberately single Submission Api instance of DRES. Used to submit media items during competitions to DRES:
2832
/// </summary>
29-
internal static readonly SubmissionApi SubmissionApi = new SubmissionApi(DresConfigManager.Instance.ApiConfiguration);
33+
internal static readonly SubmissionApi SubmissionApi = new(DresConfigManager.Instance.ApiConfiguration);
34+
3035
/// <summary>
3136
/// The deliberately single User Api instance of DRES. Used to log into DRES and retrieve the session id of the user.
3237
/// </summary>
33-
internal static readonly UserApi UserApi = new UserApi(DresConfigManager.Instance.ApiConfiguration);
38+
internal static readonly UserApi UserApi = new(DresConfigManager.Instance.ApiConfiguration);
3439

3540
/// <summary>
3641
/// Login to DRES with given username and password.
37-
/// The login state (i.e. the <see cref="Dev.Dres.ClientApi.Model.UserDetails"/>) are not kept
42+
/// The login state (i.e. the <see cref="Dev.Dres.ClientApi.Model.ApiUser"/>) are not kept
3843
/// and have to be managed by the caller.
3944
/// </summary>
4045
/// <param name="user">The DRES username</param>
4146
/// <param name="password">The DRES password</param>
4247
/// <returns>The login state on success.</returns>
4348
/// <exception cref="ApiException">If the config has no credentials set and no credentials file exists</exception>
44-
internal static async Task<UserDetails> Login(string user, string password)
49+
internal static Task<ApiUser> Login(string user, string password)
4550
{
4651
var loginRequest = new LoginRequest(user, password);
47-
return await UserApi.PostApiV1LoginAsync(loginRequest);
52+
return UserApi.PostApiV2LoginAsync(loginRequest);
53+
}
54+
55+
internal static Task<List<ApiClientEvaluationInfo>> ListClientEvaluations(string session)
56+
{
57+
return EvaluationClientApi.GetApiV2ClientEvaluationListAsync(session);
58+
}
59+
60+
internal static Task<ApiTaskTemplateInfo> GetTaskInfo(string evaluationId, string session)
61+
{
62+
return EvaluationClientApi.GetApiV2ClientEvaluationCurrentTaskByEvaluationIdAsync(evaluationId, session);
4863
}
4964

65+
/// <summary>
66+
/// Submits an item to the DRES endpoint using the DRES API v2.
67+
/// </summary>
68+
/// <param name="session">The session ID to which this submission belongs</param>
69+
/// <param name="evaluationId">The evaluation ID to which this submission belongs</param>
70+
/// <param name="item">The name of the item (or identifier) to submit</param>
71+
/// <param name="start">The optional start (in milliseconds) of the submitted item</param>
72+
/// <param name="end">The optional end (in milliseconds) of the submitted item</param>
73+
/// <returns>The submission state on success / failure.</returns>
74+
internal static Task<SuccessfulSubmissionsStatus> SubmitV2(string session, string evaluationId, string item, long? start = null,
75+
long? end = null)
76+
{
77+
var answerSets = new List<ApiClientAnswerSet>
78+
{
79+
new(answers: new List<ApiClientAnswer>
80+
{
81+
new(mediaItemName: item, start: start.GetValueOrDefault(), end: end.GetValueOrDefault())
82+
})
83+
};
84+
var apiClientSubmission = new ApiClientSubmission(answerSets);
85+
return SubmissionApi.PostApiV2SubmitByEvaluationIdAsync(evaluationId, apiClientSubmission, session);
86+
}
87+
88+
/// <summary>
89+
/// Submits text to the DRES endpoint using the DRES API v2.
90+
/// </summary>
91+
/// <param name="session">The session ID to which this submission belongs</param>
92+
/// <param name="evaluationId">The evaluation ID to which this submission belongs</param>
93+
/// <param name="text">The text to submit</param>
94+
/// <returns>The submission state on success / failure.</returns>
95+
internal static Task<SuccessfulSubmissionsStatus> SubmitTextV2(string session, string evaluationId, string text)
96+
{
97+
var answerSets = new List<ApiClientAnswerSet> { new(answers: new List<ApiClientAnswer> { new(text: text) }) };
98+
var apiClientSubmission = new ApiClientSubmission(answerSets);
99+
return SubmissionApi.PostApiV2SubmitByEvaluationIdAsync(evaluationId, apiClientSubmission, session);
100+
}
101+
102+
// TODO: Once the functionality of the new API is confirmed, implement bulk submission
103+
50104
/// <summary>
51105
/// Submits an item to the DRES endpoint.
52106
/// Submissions are only allowed during active competitions (inferred from the given sesssion id)
@@ -57,11 +111,12 @@ internal static async Task<UserDetails> Login(string user, string password)
57111
/// If no notion of frames exist for the item, this can likely be omitted.</param>
58112
/// <returns>The submission state on success / failure.</returns>
59113
/// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
60-
internal static async Task<SuccessfulSubmissionsStatus> Submit(string item, string session, int? frame = null)
114+
[Obsolete("Obsolete")]
115+
internal static Task<SuccessfulSubmissionsStatus> Submit(string item, string session, int? frame = null)
61116
{
62-
return await SubmissionApi.GetApiV1SubmitAsync(item: item, frame: frame, session: session);
117+
return SubmissionApi.GetApiV1SubmitAsync(item: item, frame: frame, session: session);
63118
}
64-
119+
65120
/// <summary>
66121
/// Submits given TEXT to the DRES endpoint.
67122
/// Submissions are only allowed during active competitions (inferred from the given sesssion id)
@@ -70,9 +125,10 @@ internal static async Task<SuccessfulSubmissionsStatus> Submit(string item, stri
70125
/// <param name="session">The session id to which this submission belongs</param>
71126
/// <returns>The submission state on success / failure.</returns>
72127
/// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
73-
internal static async Task<SuccessfulSubmissionsStatus> SubmitText(string text, string session)
128+
[Obsolete("Obsolete")]
129+
internal static Task<SuccessfulSubmissionsStatus> SubmitText(string text, string session)
74130
{
75-
return await SubmissionApi.GetApiV1SubmitAsync(text: text, session: session);
131+
return SubmissionApi.GetApiV1SubmitAsync(text: text, session: session);
76132
}
77133

78134

@@ -89,11 +145,11 @@ internal static async Task<SuccessfulSubmissionsStatus> SubmitText(string text,
89145
/// <param name="session">The session id to which this log belongs</param>
90146
/// <returns>The state of success / failure of the log sending.</returns>
91147
/// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
92-
internal static async Task<SuccessStatus> LogResults(long timestamp, string sortType, string resultSetAvailability,
148+
internal static Task<SuccessStatus> LogResults(long timestamp, string sortType, string resultSetAvailability,
93149
List<QueryResult> results, List<QueryEvent> events, string session)
94150
{
95151
var resultLog = new QueryResultLog(timestamp, sortType, resultSetAvailability, results, events);
96-
return await LogApi.PostApiV1LogResultAsync(session, resultLog);
152+
return LogApi.PostApiV2LogResultAsync(session, resultLog);
97153
}
98154

99155
/// <summary>
@@ -106,10 +162,10 @@ internal static async Task<SuccessStatus> LogResults(long timestamp, string sort
106162
/// <param name="session">The session id to which this log belongs</param>
107163
/// <returns>The state of success / failure of the log sending.</returns>
108164
/// <exception cref="ApiException">A 404 if there is no ongoing competition for this session, a 403 if there is no such user</exception>
109-
internal static async Task<SuccessStatus> LogQueryEvents(long timestamp, List<QueryEvent> events, string session)
165+
internal static Task<SuccessStatus> LogQueryEvents(long timestamp, List<QueryEvent> events, string session)
110166
{
111167
var queryEventLog = new QueryEventLog(timestamp, events);
112-
return await LogApi.PostApiV1LogQueryAsync(session, queryEventLog);
168+
return LogApi.PostApiV2LogQueryAsync(session, queryEventLog);
113169
}
114170
}
115171
}

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import org.apache.tools.ant.taskdefs.condition.Os
33

44
/* Get the openapi generator plugin */
55
plugins {
6-
id "org.openapi.generator" version "4.3.1"
6+
id "org.openapi.generator" version "6.4.0"
77
}
88

99
/* Setup OpenApi Specs (OAS): Defaults to default.*/
1010
/* Additional, sensible settings:
1111
+ http://localhost:8080/client-oas.json // Local DRES
1212
+ https://raw.githubusercontent.com/dres-dev/DRES/master/doc/oas-client.json // When oas-client is released
1313
*/
14-
def dresOAS = "https://raw.githubusercontent.com/dres-dev/DRES/1.0/doc/oas-client.json"
14+
def dresOAS = "https://raw.githubusercontent.com/dres-dev/DRES/2.0.0-RC1/doc/oas-client.json"
1515
/* If gradle gets 'oas' argument (with -Poas="path/to/OAS"), take these */
1616
if(project.hasProperty('oas')){
1717
dresOAS = oas
@@ -68,9 +68,9 @@ task modex(type: Exec){
6868
task deployLibs(type: Copy){
6969
from(file("$rootDir/Generated/bin"))
7070
into(file("$rootDir/Runtime/Libs"))
71-
rename("RestSharp.dll", "RestSharp.Dres.dll")
72-
rename("Newtonsoft.Json.dll", "Newtonsoft.Json.Dres.dll")
73-
rename("JsonSubTypes.dll", "JsonSubTypes.Dres.dll")
71+
rename("RestSharp.dll", "RestSharp." + dllName + ".dll")
72+
rename("Newtonsoft.Json.dll", "Newtonsoft.Json." + dllName + ".dll")
73+
rename("JsonSubTypes.dll", "JsonSubTypes." + dllName + ".dll")
7474
}
7575

7676
/* Copy the mandatory link.xml */

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dev.dres.unityclient",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"displayName": "DRES Unity Client",
55
"description": "An all-unity client for [DRES](https://github.com/dres-dev/DRES)",
66
"unity": "2020.3",

0 commit comments

Comments
 (0)