Skip to content

Commit

Permalink
ベンチマーク周りの OpenAPI を改善 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 authored Jan 10, 2025
1 parent 8e67121 commit 6840f5d
Show file tree
Hide file tree
Showing 7 changed files with 3,574 additions and 1,179 deletions.
96 changes: 58 additions & 38 deletions client/src/api/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export interface paths {
}
/**
* チーム一覧取得
* @description チーム一覧を取得します
* @description チーム一覧を取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getTeams']
put?: never
Expand Down Expand Up @@ -162,7 +162,7 @@ export interface paths {
}
/**
* インスタンス一覧取得
* @description チームに所属しているインスタンス一覧を取得します
* @description チームに所属しているインスタンス一覧を取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getTeamInstances']
put?: never
Expand Down Expand Up @@ -210,7 +210,7 @@ export interface paths {
}
/**
* インスタンス一覧取得
* @description 全インスタンス一覧を取得します
* @description 全インスタンス一覧を取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getInstances']
put?: never
Expand All @@ -230,7 +230,7 @@ export interface paths {
}
/**
* ベンチマーク一覧取得
* @description 全チームのベンチマーク一覧を取得します
* @description 全チームのベンチマーク一覧を取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getBenchmarks']
put?: never
Expand All @@ -256,6 +256,7 @@ export interface paths {
* ベンチマーク待ち行列取得
* @description ベンチマーク待ちのキューを取得します。
* createdAtの昇順になっており、現在実行中のベンチマークと、実行待ちのベンチマークが含まれます。
* 0件の場合も200で空配列が返ります。
*
*/
get: operations['getBenchmarkQueue']
Expand All @@ -276,7 +277,7 @@ export interface paths {
}
/**
* チームのベンチマーク一覧取得
* @description チームのベンチマーク一覧を取得します
* @description チームのベンチマーク一覧を取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getTeamBenchmarks']
put?: never
Expand Down Expand Up @@ -338,7 +339,7 @@ export interface paths {
}
/**
* 全てのスコア取得
* @description 全てのベンチマークのスコアをチームごとに取得します
* @description 全てのベンチマークのスコアをチームごとに取得します (0件の場合も200で空配列が返ります)
*/
get: operations['getScores']
put?: never
Expand All @@ -360,6 +361,7 @@ export interface paths {
* ランキング取得
* @description ベンチマークのスコアランキングを取得します。1位から順に並んでいます。
* 同じスコアの場合は、ベンチマーク実行日時(createdAt)が早い順に並べます。
* 0件の場合も200で空配列が返ります
*
*/
get: operations['getRanking']
Expand Down Expand Up @@ -542,41 +544,28 @@ export interface components {
*/
Score: number
/** @description ベンチマーク */
Benchmark: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
status: components['schemas']['BenchmarkStatus']
score?: components['schemas']['Score']
createdAt: components['schemas']['CreatedAt']
startedAt?: components['schemas']['StartedAt']
finishedAt?: components['schemas']['FinishedAt']
}
BenchmarkListItem:
| components['schemas']['WaitingBenchmark']
| components['schemas']['RunningBenchmark']
| components['schemas']['FinishedBenchmark']
/** @description ベンチマーク結果 */
BenchmarkResult: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
status: components['schemas']['BenchmarkStatus']
Benchmark: (
| components['schemas']['WaitingBenchmark']
| components['schemas']['RunningBenchmark']
| components['schemas']['FinishedBenchmark']
) & {
/**
* @description ベンチマークの競技者用ログ(標準出力)
* @example log
*/
log: string
score: components['schemas']['Score']
createdAt: components['schemas']['CreatedAt']
startedAt: components['schemas']['StartedAt']
finishedAt: components['schemas']['FinishedAt']
}
/** @description Adminが見ることができるベンチマーク結果 */
BenchmarkAdminResult: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
status: components['schemas']['BenchmarkStatus']
BenchmarkAdminResult: (
| components['schemas']['WaitingBenchmark']
| components['schemas']['RunningBenchmark']
| components['schemas']['FinishedBenchmark']
) & {
/**
* @description ベンチマークの競技者用ログ(標準出力)
* @example log
Expand All @@ -587,6 +576,37 @@ export interface components {
* @example admin log
*/
adminLog: string
}
/** @description status=waiting のベンチマーク結果 */
WaitingBenchmark: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
/** @enum {string} */
status: 'waiting'
createdAt: components['schemas']['CreatedAt']
}
/** @description status=running のベンチマーク結果 */
RunningBenchmark: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
/** @enum {string} */
status: 'running'
score: components['schemas']['Score']
createdAt: components['schemas']['CreatedAt']
startedAt: components['schemas']['StartedAt']
}
/** @description status=finished のベンチマーク結果 */
FinishedBenchmark: {
id: components['schemas']['BenchmarkId']
instanceId: components['schemas']['InstanceId']
teamId: components['schemas']['TeamId']
userId: components['schemas']['UserId']
/** @enum {string} */
status: 'finished'
score: components['schemas']['Score']
createdAt: components['schemas']['CreatedAt']
startedAt: components['schemas']['StartedAt']
Expand Down Expand Up @@ -1138,7 +1158,7 @@ export interface operations {
[name: string]: unknown
}
content: {
'application/json': components['schemas']['Benchmark'][]
'application/json': components['schemas']['BenchmarkListItem'][]
}
}
401: components['responses']['Unauthorized']
Expand All @@ -1161,7 +1181,7 @@ export interface operations {
[name: string]: unknown
}
content: {
'application/json': components['schemas']['Benchmark']
'application/json': components['schemas']['BenchmarkListItem']
}
}
/** @description インスタンスが存在しない、チームに所属していない、すでにそのチームのベンチマークがキューに入っているなど */
Expand Down Expand Up @@ -1193,7 +1213,7 @@ export interface operations {
[name: string]: unknown
}
content: {
'application/json': components['schemas']['Benchmark'][]
'application/json': components['schemas']['BenchmarkListItem'][]
}
}
401: components['responses']['Unauthorized']
Expand Down Expand Up @@ -1221,7 +1241,7 @@ export interface operations {
[name: string]: unknown
}
content: {
'application/json': components['schemas']['Benchmark'][]
'application/json': components['schemas']['BenchmarkListItem'][]
}
}
401: components['responses']['Unauthorized']
Expand Down Expand Up @@ -1250,7 +1270,7 @@ export interface operations {
[name: string]: unknown
}
content: {
'application/json': components['schemas']['BenchmarkResult']
'application/json': components['schemas']['Benchmark']
}
}
401: components['responses']['Unauthorized']
Expand Down
15 changes: 9 additions & 6 deletions client/src/mock/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const benchmarks: paths['/benchmarks']['get']['responses']['200']['content']['ap
status: 'running',
createdAt: '2025-01-01T02:00:00Z',
startedAt: '2025-01-01T02:00:01Z',
score: 0,
},
{
id: '01943f69-3aec-7702-8d1e-8642d9c5b47b',
Expand Down Expand Up @@ -224,11 +225,12 @@ export const handlers = [
teams.map((team) => ({
teamId: team.id,
scores: benchmarks
.filter((b) => b.teamId === team.id && b.status === 'finished')
.filter((b) => b.teamId === team.id)
.filter((b) => b.status === 'finished')
.map((b) => ({
benchmarkId: b.id,
teamId: team.id,
score: b.score!,
score: b.score,
createdAt: b.createdAt,
})),
}))
Expand All @@ -237,8 +239,8 @@ export const handlers = [
}),
http.get(`${apiBaseUrl}/scores/ranking`, () => {
const sortFn = (
a: components['schemas']['Benchmark'],
b: components['schemas']['Benchmark'],
a: components['schemas']['FinishedBenchmark'],
b: components['schemas']['FinishedBenchmark'],
) => {
// スコアの降順
if (a.score! < b.score!) return 1
Expand All @@ -252,14 +254,15 @@ export const handlers = [
.map(
(team) =>
benchmarks
.filter((b) => b.teamId === team.id && b.status === 'finished')
.filter((b) => b.teamId === team.id)
.filter((b) => b.status === 'finished')
.sort(sortFn)[0],
)
.sort(sortFn)
.map((b, i) => ({
rank: i + 1,
teamId: b.teamId,
score: b.score!,
score: b.score,
createdAt: b.createdAt,
}))

Expand Down
Loading

0 comments on commit 6840f5d

Please sign in to comment.