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 : 레이싱 게임 추첨 당첨자 수 가져오기 및 NullPointerError 수정 (CC-175) #43

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from 1 commit
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
@@ -1,13 +1,17 @@
package ai.softeer.caecae.admin.service;

import ai.softeer.caecae.admin.domain.dto.response.RacingGameWinnerResponseDto;
import ai.softeer.caecae.findinggame.domain.dto.response.FindingGameInfoResponseDto;
import ai.softeer.caecae.findinggame.repository.FindingGameAnswerDbRepository;
import ai.softeer.caecae.findinggame.repository.FindingGameDbRepository;
import ai.softeer.caecae.findinggame.service.FindingGameService;
import ai.softeer.caecae.racinggame.domain.dto.response.RacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.domain.entity.RacingGameParticipant;
import ai.softeer.caecae.racinggame.domain.entity.RacingGameWinner;
import ai.softeer.caecae.racinggame.repository.RacingGameInfoRepository;
import ai.softeer.caecae.racinggame.repository.RacingGameRepository;
import ai.softeer.caecae.racinggame.repository.RacingGameWinnerRepository;
import ai.softeer.caecae.racinggame.service.RacingGameInfoService;
import ai.softeer.caecae.user.domain.entity.User;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,6 +29,7 @@ public class AdminRacingGameService {
private final RacingGameWinnerRepository racingGameWinnerRepository;
private final FindingGameDbRepository findingGameDbRepository;
private final FindingGameAnswerDbRepository findingGameAnswerDbRepository;
private final RacingGameInfoService racingGameInfoService;

/**
* 당첨자를 뽑는 서비스 로직
Expand All @@ -48,10 +53,12 @@ public List<RacingGameWinnerResponseDto> drawRacingGameWinner() {
for (RacingGameParticipant p : participants) {
accumulatedPercent += accumulatedPercentPoint;
while (accumulatedPercent > accumulateSector[currentSector] + 0.01) currentSector++;
arr[idx++] = weight[currentSector] + (p.getSelection() != 0 ? selectionWeight : 0);
Integer selection = p.getSelection();
arr[idx++] = weight[currentSector] + (selection != null && selection > 0 ? selectionWeight : 0);
}
// N명 중에서 한 명을 선택한 후, 그 사람을 가중치 / 전체 가중치 확률로 당첨자로 만든다. 이를 당첨인원수만큼 반복
int drawNumber = Math.min(315, participants.size()), ranking = 1; // TODO: 315 Global 변수화
RacingGameInfoResponseDto racingGameInfo = racingGameInfoService.getRacingGameInfo();
int drawNumber = Math.min(racingGameInfo.numberOfWinners(), participants.size()), ranking = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int drawNumber = ~  ;
int ranking = 1;

이렇게 분리해서 선언하면 어떤가요

while (ranking <= drawNumber) {
int cur = (int) (Math.random() * n + 0.5) % n;
if (arr[cur] < 0) continue;
Expand Down
Loading