Skip to content

Commit da74cb9

Browse files
committed
feat(leaderboard): add leadboard for benchmark
1 parent fa8dcea commit da74cb9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/benchmarks/benchmark.controller.ts

+9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ export class BenchmarkController {
5656
return this.benchmarkService.findOne(benchmarkIdDto.id);
5757
}
5858

59+
@ApiOperation({ summary: 'Get the leaderboard for the benchmark' })
60+
@UseGuards(JwtAuthGuard)
61+
@Get(':id/leaderboard')
62+
async getLeaderboardById(
63+
@Param() benchmarkIdDto: BenchmarkIdDto,
64+
): Promise<Submission[]> {
65+
return this.submissionsService.getLeaderboardForBenchmark(benchmarkIdDto);
66+
}
67+
5968
@ApiOperation({ summary: 'Get last submission for benchmark + language' })
6069
@UseGuards(JwtAuthGuard)
6170
@Get(':id/submissions/last')

src/submissions/submissions.service.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import {
77
} from '@nestjs/common';
88
import { InjectRepository } from '@nestjs/typeorm';
99
import { TypedJSON } from 'typedjson';
10-
import { Repository } from 'typeorm';
10+
import { IsNull, Not, Repository } from 'typeorm';
1111
import { BenchmarkService } from '../benchmarks/benchmark.service';
1212
import { User } from '../users/user.entity';
1313
import { FindLastSubmissionByLanguageDTO } from './dto/find-last-submission-by-language.dto';
1414
import { FindSubmissionDTO } from './dto/find-submission.dto';
1515
import { InsertSubmissionDTO } from './dto/insert-submission-dto';
1616
import { JobStatusDTO } from './dto/job-status.dto';
1717
import { Submission } from './submission.entity';
18+
import { BenchmarkIdDto } from '../benchmarks/dto/benchmarkId.dto';
1819

1920
@Injectable()
2021
export class SubmissionsService {
@@ -138,6 +139,21 @@ export class SubmissionsService {
138139
}
139140
}
140141

142+
async getLeaderboardForBenchmark(
143+
benchmarkId: BenchmarkIdDto,
144+
): Promise<Submission[]> {
145+
const bench = await this.benchmarkService.findOne(benchmarkId.id);
146+
return this.submissionsRepository.find({
147+
where: [
148+
{
149+
benchmark: bench,
150+
qualityScore: Not(IsNull()),
151+
},
152+
],
153+
order: { qualityScore: 'DESC' },
154+
});
155+
}
156+
141157
async findLastByLanguage(
142158
filter: FindLastSubmissionByLanguageDTO,
143159
requestUser: User,

0 commit comments

Comments
 (0)