Skip to content

Commit 233f2df

Browse files
authored
Merge pull request #301 from boostcampwm-2022/develop
v0.2.0 배포
2 parents 5b7a01e + 669d373 commit 233f2df

File tree

21 files changed

+227
-143
lines changed

21 files changed

+227
-143
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/> Devrank <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/>
22

3+
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fboostcampwm-2022%2Fweb21-devrank&count_bg=%23C455F9&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
4+
35
![Frame 12023](https://user-images.githubusercontent.com/79798443/206137429-5cb1d269-4bec-4aaa-85ad-053ae564c625.png)
46

57
**_Devrank_** 는 게임과 유사한 등급 시스템과 랭킹을 제공하여, Github 활동시 사용자에게 성취감을 주고 오픈소스 활동을 장려하는 서비스 입니다.

backend/src/batch/batch.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { UserService } from '../user/user.service';
88
export class BatchService {
99
constructor(private readonly userService: UserService, private readonly configService: ConfigService) {}
1010

11-
@Cron('0 0 0 * * *', { name: 'cronTask' })
11+
@Cron('0 0 0 * * *', { name: 'cronTask', timeZone: 'Asia/Seoul' })
1212
handleCron() {
1313
logger.log('Task Called');
1414
this.userService.dailyUpdateAllUsers(this.configService.get('GITHUB_PERSONAL_ACCESS_TOKEN'));

backend/src/user/user.controller.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Controller,
77
DefaultValuePipe,
88
Get,
9+
NotFoundException,
910
Param,
1011
ParseIntPipe,
1112
Patch,
@@ -74,18 +75,15 @@ export class UserController {
7475
@Param('username') username: string,
7576
): Promise<UserProfileDto> {
7677
const lowerUsername = username.toLowerCase();
77-
if (
78-
(await this.userService.findUpdateScoreTimeToLive(lowerUsername)) > 0 &&
79-
(await this.userService.findOneByFilter({ lowerUsername }))?.id !== id
80-
) {
78+
const targetUser = await this.userService.findOneByFilter({ lowerUsername });
79+
if ((await this.userService.findUpdateScoreTimeToLive(lowerUsername)) > 0 && targetUser?.id !== id) {
8180
throw new BadRequestException('user score has been updated recently.');
8281
}
82+
await this.userService.setUpdateScoreDelayTime(lowerUsername, UPDATE_DELAY_TIME);
8383
const user = await this.userService.updateUser(
8484
lowerUsername,
8585
githubToken || this.configService.get('GITHUB_PERSONAL_ACCESS_TOKEN'),
8686
);
87-
88-
await this.userService.setUpdateScoreDelayTime(lowerUsername, UPDATE_DELAY_TIME);
8987
user.updateDelayTime = UPDATE_DELAY_TIME + 3;
9088
return user;
9189
}

backend/src/user/user.service.ts

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,28 @@ export class UserService {
3232
}
3333

3434
async findOneByUsername(githubToken: string, ip: string, lowerUsername: string): Promise<UserProfileDto> {
35-
let user = null;
36-
if (await this.userRepository.isDuplicatedRequestIp(ip, lowerUsername)) {
37-
user = await this.userRepository.findOneByLowerUsername(lowerUsername);
38-
} else {
39-
user = await this.userRepository.findOneByLowerUsernameAndUpdateViews(lowerUsername);
40-
}
41-
35+
let user = await this.userRepository.findOneByLowerUsername(lowerUsername);
4236
if (!user) {
43-
user = await this.updateUser(lowerUsername, githubToken);
44-
if (!user.scoreHistory) {
45-
user.scoreHistory = [];
37+
try {
38+
user = await this.updateUser(lowerUsername, githubToken);
39+
if (!user.scoreHistory) {
40+
user.scoreHistory = [];
41+
}
42+
user.scoreHistory.push({ date: new Date(), score: user.score });
43+
user = await this.userRepository.createOrUpdate(user);
44+
} catch {
45+
throw new HttpException(`can't update this user.`, HttpStatus.NO_CONTENT);
4646
}
47-
user.scoreHistory.push({ date: new Date(), score: user.score });
48-
user = await this.userRepository.createOrUpdate(user);
4947
}
50-
await this.userRepository.createOrUpdate(user);
51-
5248
const { totalRank, tierRank } =
5349
(await this.getUserRelativeRanking(user)) || (await this.setUserRelativeRanking(user));
50+
if (!(await this.userRepository.isDuplicatedRequestIp(ip, lowerUsername)) && user.history) {
51+
user.dailyViews += 1;
52+
await this.userRepository.createOrUpdate(user);
53+
}
5454
this.userRepository.setDuplicatedRequestIp(ip, lowerUsername);
5555
user.updateDelayTime = await this.userRepository.findUpdateScoreTimeToLive(lowerUsername);
56-
user.totalRank = totalRank;
57-
user.tierRank = tierRank;
58-
user.startExp = getStartExp(user.score);
59-
user.needExp = getNeedExp(user.score);
60-
return user;
56+
return { ...user, totalRank, tierRank, startExp: getStartExp(user.score), needExp: getNeedExp(user.score) };
6157
}
6258

6359
async findAllByPrefixUsername(limit: number, lowerUsername: string): Promise<AutoCompleteDto[]> {
@@ -83,6 +79,24 @@ export class UserService {
8379
organizations,
8480
pinnedRepositories,
8581
};
82+
if (!updatedUser.scoreHistory) {
83+
updatedUser.scoreHistory = [];
84+
}
85+
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
86+
const utc = updatedUser.scoreHistory[updatedUser.scoreHistory.length - 1].date.getTime();
87+
if (new Date(utc + KR_TIME_DIFF).getDate() == new Date().getDate()) {
88+
updatedUser.scoreHistory.pop();
89+
}
90+
updatedUser.scoreHistory.push({
91+
date: new Date(),
92+
score: updatedUser.score,
93+
});
94+
if (updatedUser.scoreHistory.length > 1) {
95+
updatedUser.scoreDifference =
96+
updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score;
97+
} else {
98+
updatedUser.scoreDifference = 0;
99+
}
86100
user = await this.userRepository.createOrUpdate(updatedUser);
87101
const { totalRank, tierRank } = await this.setUserRelativeRanking(user);
88102
const userWithRank: UserProfileDto = {
@@ -102,15 +116,6 @@ export class UserService {
102116
await sleep(GITHUB_API_DELAY);
103117
try {
104118
const updateUser = await this.updateUser(user.lowerUsername, githubToken);
105-
if (!updateUser.scoreHistory) updateUser.scoreHistory = [];
106-
if (updateUser.scoreHistory.length) updateUser.scoreHistory.pop();
107-
updateUser.scoreHistory.push({ date: new Date(), score: updateUser.score });
108-
if (updateUser.scoreHistory.length > 1) {
109-
updateUser.scoreDifference =
110-
updateUser.score - updateUser.scoreHistory[updateUser.scoreHistory.length - 2].score;
111-
} else {
112-
updateUser.scoreDifference = 0;
113-
}
114119
this.userRepository.createOrUpdate(updateUser);
115120
this.userRepository.deleteCachedUserRank(updateUser.lowerUsername + '&');
116121
} catch {
@@ -126,17 +131,6 @@ export class UserService {
126131
await sleep(GITHUB_API_DELAY);
127132
try {
128133
const updatedUser = await this.updateUser(user.lowerUsername, githubToken);
129-
if (!updatedUser.scoreHistory) updatedUser.scoreHistory = [];
130-
updatedUser.scoreHistory.push({
131-
date: new Date(),
132-
score: updatedUser.score,
133-
});
134-
if (updatedUser.scoreHistory.length > 1) {
135-
updatedUser.scoreDifference =
136-
updatedUser.score - updatedUser.scoreHistory[updatedUser.scoreHistory.length - 2].score;
137-
} else {
138-
updatedUser.scoreDifference = 0;
139-
}
140134
updatedUser.dailyViews = 0;
141135
this.userRepository.createOrUpdate(updatedUser);
142136
} catch {
@@ -202,20 +196,16 @@ export class UserService {
202196
username: lowerUsername,
203197
id,
204198
});
205-
206199
const personalResponse: any = await octokit.graphql(nonForkRepositoryQuery, {
207200
username: lowerUsername,
208201
id,
209202
});
210-
211203
const followersResponse: any = await octokit.graphql(followersQuery, {
212204
username: lowerUsername,
213205
});
214-
215206
const issuesResponse: any = await octokit.graphql(issueQuery, {
216207
username: lowerUsername,
217208
});
218-
219209
let languagesScore = new Map();
220210
function getCommitScore(acc: number, repository) {
221211
if (!repository.defaultBranchRef) {

frontend/public/icons/cube-large-background.svg

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Loading

frontend/public/locales/en/profile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"user-update-delay": "You can update it in",
77
"day": "day",
88
"total": "Total",
9-
"rank": "Rank"
9+
"rank": "Rank",
10+
"invalid-user": "This user cannot get information",
11+
"invalid-rank": "Unable to get the rank"
1012
}

frontend/public/locales/ko/profile.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
"user-update-delay": "초 후 업데이트 가능합니다.",
77
"day": "",
88
"total": "전체",
9-
"rank": "등급"
9+
"rank": "등급",
10+
"invalid-user": "정보를 가져올 수 없는 유저입니다",
11+
"invalid-rank": "등수를 표시할 수 없습니다"
1012
}

frontend/src/components/Chart/LineChart/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function LineChart({ data, min, max, markers, tooltip }: LineChartProps) {
2020
margin={{ top: 60, right: 60, bottom: 60, left: 60 }}
2121
curve='monotoneX'
2222
enableArea={true}
23+
areaBaselineValue={min || 0}
2324
xScale={{
2425
type: 'time',
2526
format: '%Y-%m-%d',

frontend/src/components/Chart/theme.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"legend": {
3030
"text": {
3131
"fontSize": 14,
32-
"fontWeight": 700,
32+
"fontWeight": 400,
3333
"fill": "#FBFBFB"
3434
}
3535
},
@@ -39,7 +39,8 @@
3939
"strokeWidth": 1
4040
},
4141
"text": {
42-
"fontSize": 14,
42+
"fontSize": 12,
43+
"fontWeight": 100,
4344
"fill": "#FBFBFB"
4445
}
4546
}

0 commit comments

Comments
 (0)