Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 눈사람 확률 계산 수정 #41

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TownSnowmanResponse getLetter(Long id) {
townSnowmanRepository.save(townSnowman);

// town_snowman에 같은 눈사람이 몇개인지 percent 계산
Integer percent = calculatePercent(townSnowman.getTown().getId(), townSnowman.getSnowman().getId(), 0);
Integer percent = calculatePercent(townSnowman.getTown().getId(), townSnowman.getSnowman().getId());

// dto 생성 및 반환
return TownSnowmanResponse.toResponse(townSnowman, percent);
Expand Down Expand Up @@ -102,7 +102,7 @@ public ResultResponse makeSnowman(String url, SubmitAnswerRequest submitAnswerRe
townSnowmanRepository.save(townSnowman);

// town_snowman에 같은 눈사람이 몇개인지 percent 계산
Integer percent = calculatePercent(town.getId(), snowman.getId(), 1);
Integer percent = calculatePercent(town.getId(), snowman.getId());

// dto 생성 및 반환
return ResultResponse.toResponse(town.getUser(), percent, townSnowman);
Expand All @@ -114,11 +114,11 @@ public ResultResponse makeSnowman(String url, SubmitAnswerRequest submitAnswerRe
* @param snowmanId
* @return percent
*/
private Integer calculatePercent(Long townId, Long snowmanId, Integer plus) {
private Integer calculatePercent(Long townId, Long snowmanId) {

Integer totalSize = townSnowmanRepository.countByTownId(townId);
Integer typeSize = townSnowmanRepository.countByTownIdAndSnowmanId(townId, snowmanId);

return (int) Math.round((double)(typeSize + plus) / (double)(totalSize + plus) * 100);
return (int) Math.round((double)(typeSize) / (double)(totalSize) * 100);
}
}