Skip to content

Commit

Permalink
Merge pull request #108 from Boost-Coder/feature/scoreRank-#106
Browse files Browse the repository at this point in the history
순위 이름 순으로 차이나도록 수정
  • Loading branch information
koomin1227 authored Jun 12, 2024
2 parents 1704bf7 + bdc02ca commit 539f244
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/stat/service/grade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export class GradeService {
}

public calculatePoint(grade: number) {
const maxGrade = 4.5;
const maxPercentage = 100;
return (grade / maxGrade) * maxPercentage;
return grade;
}

public async getIndividualGradeRank(userId: string, options: PointFindDto) {
Expand Down
12 changes: 8 additions & 4 deletions src/stat/service/total.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TotalService {
if (user1Github == null || user2Github == null) {
return null;
}
return user1Github.score - user2Github.score;
return this.roundSecond(user1Github.score - user2Github.score);
}

private async compareGithubRank(user1: string, user2: string) {
Expand Down Expand Up @@ -180,7 +180,7 @@ export class TotalService {
if (user1Algorithm == null || user2Algorithm == null) {
return null;
}
return user1Algorithm.score - user2Algorithm.score;
return this.roundSecond(user1Algorithm.score - user2Algorithm.score);
}

private async compareAlgorithmRank(user1: string, user2: string) {
Expand Down Expand Up @@ -212,7 +212,7 @@ export class TotalService {
if (user1Grade == null || user2Grade == null) {
return null;
}
return user1Grade.score - user2Grade.score;
return this.roundSecond(user1Grade.score - user2Grade.score);
}

private async compareGradeRank(user1: string, user2: string) {
Expand Down Expand Up @@ -242,7 +242,7 @@ export class TotalService {
if (user1Total == null || user2Total == null) {
return null;
}
return user1Total.score - user2Total.score;
return this.roundSecond(user1Total.score - user2Total.score);
}

private async compareTotalRank(user1: string, user2: string) {
Expand All @@ -256,4 +256,8 @@ export class TotalService {
);
return user1Rank.rank - user2Rank.rank;
}

private roundSecond(number) {
return Math.round(number * 100) / 100;
}
}
5 changes: 4 additions & 1 deletion src/utils/stat.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class StatRepository extends Repository<any> {
.distinct(true)
.from((sub) => {
return sub
.select('RANK() OVER (ORDER BY a.score DESC)', 'rank')
.select(
'RANK() OVER (ORDER BY a.score DESC, a.user_id ASC)',
'rank',
)
.addSelect('a.user_id', 'user_id')
.addSelect('a.score', 'score')
.addSelect('u.nickname', 'nickname')
Expand Down

0 comments on commit 539f244

Please sign in to comment.