Skip to content

Commit

Permalink
Merge pull request #387 from SWM-NM/feat/#385
Browse files Browse the repository at this point in the history
[FIX] 테스트 시작 관련 수정 / 테스트 타입 코드 수정
  • Loading branch information
aj4941 authored Oct 4, 2023
2 parents 523741c + c83704f commit 3b95302
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@ public void callApiPeriodically() {
testSet.forEach(testCheckDto -> {
log.info("Scheduler call testID : " + testCheckDto.getTestId());
Long testId = testCheckDto.getTestId();
Tests test = testRepository.findById(testId)
.orElseThrow(() -> new MorandiException(TestErrorCode.TEST_NOT_FOUND));
if (test.getTestStatus() == TestStatus.COMPLETED) {
log.info("Scheduler Completed testID : " + testCheckDto.getTestId());
Optional<Tests> result = testRepository.findById(testId);
if (result.isEmpty()) {
log.info("Scheduler Not Found testID : " + testCheckDto.getTestId());
deleteList.add(testCheckDto);
return;
}
Duration duration = Duration.between(test.getTestDate(), LocalDateTime.now());
Long minutes = duration.toMinutes();
if (minutes > test.getTestTime()) {
log.info("Scheduler exceed minutes testID : " + testCheckDto.getTestId());
deleteList.add(testCheckDto);
return;
else {
Tests test = result.get();
if (test.getTestStatus() == TestStatus.COMPLETED) {
log.info("Scheduler Completed testID : " + testCheckDto.getTestId());
deleteList.add(testCheckDto);
return;
}
Duration duration = Duration.between(test.getTestDate(), LocalDateTime.now());
Long minutes = duration.toMinutes();
if (minutes > test.getTestTime()) {
log.info("Scheduler exceed minutes testID : " + testCheckDto.getTestId());
deleteList.add(testCheckDto);
return;
}
checkAttemptProblemService.checkAttemptedProblemResult(test, testCheckDto.getBojId());
}
checkAttemptProblemService.checkAttemptedProblemResult(testCheckDto.getTestId(), testCheckDto.getBojId());
});

deleteList.forEach(testSet::remove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
public class DataLoader implements CommandLineRunner {

private final TestTypeRepository testTypeRepository;
int size = -1;
@Override
public void run(String... args) {
List<TestType> testTypes = testTypeRepository.findAll();
if (testTypes.size() == 0)
insertTestTypeData();
size = testTypes.size();
insertTestTypeData();
}
private void insertTestTypeData() {
// PK 1번 : 코딩테스트 대비 초급 (Small)
Expand All @@ -39,7 +40,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType1);
if (size < 1)
{
testTypeRepository.save(testType1);
size++;
}

// PK 2번 : 코딩테스트 대비 중급 (Small)
List<DifficultyRange> difficultyRanges2 = new ArrayList<>();
Expand All @@ -58,7 +63,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType2);
if (size < 2)
{
testTypeRepository.save(testType2);
size++;
}

// PK 3번 : 코딩테스트 대비 고급 (Small)
List<DifficultyRange> difficultyRanges3 = new ArrayList<>();
Expand All @@ -77,7 +86,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType3);
if (size < 3)
{
testTypeRepository.save(testType3);
size++;
}

// PK 4번 : 코딩테스트 대비 초급 (Large)
List<DifficultyRange> difficultyRanges4 = new ArrayList<>();
Expand All @@ -98,7 +111,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType4);
if (size < 4)
{
testTypeRepository.save(testType4);
size++;
}

// PK 5번 : 코딩테스트 대비 중급 (Large)
List<DifficultyRange> difficultyRanges5 = new ArrayList<>();
Expand All @@ -119,7 +136,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType5);
if (size < 5)
{
testTypeRepository.save(testType5);
size++;
}

// PK 6번 : 코딩테스트 대비 고급 (Large)
List<DifficultyRange> difficultyRanges6 = new ArrayList<>();
Expand All @@ -140,7 +161,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType6);
if (size < 6)
{
testTypeRepository.save(testType6);
size++;
}

// PK 7번 : 삼성
List<DifficultyRange> difficultyRanges7 = new ArrayList<>();
Expand All @@ -157,7 +182,12 @@ private void insertTestTypeData() {
.numberOfTestTrial(0)
.averageCorrectAnswerRate(0L)
.build();
testTypeRepository.save(testType7);

if (size < 7)
{
testTypeRepository.save(testType7);
size++;
}

// PK 8번 : 네이버
List<DifficultyRange> difficultyRanges8 = new ArrayList<>();
Expand All @@ -177,7 +207,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType8);
if (size < 8)
{
testTypeRepository.save(testType8);
size++;
}

// PK 9번 : 카카오
List<DifficultyRange> difficultyRanges9 = new ArrayList<>();
Expand All @@ -200,7 +234,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType9);
if (size < 9)
{
testTypeRepository.save(testType9);
size++;
}

// PK 10번 : 라인
List<DifficultyRange> difficultyRanges10 = new ArrayList<>();
Expand All @@ -222,7 +260,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType10);
if (size < 10)
{
testTypeRepository.save(testType10);
size++;
}

// PK 11번 : 쿠팡
List<DifficultyRange> difficultyRanges11 = new ArrayList<>();
Expand All @@ -241,7 +283,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType11);
if (size < 11)
{
testTypeRepository.save(testType11);
size++;
}

// PK 12번 : 우아한형제들
List<DifficultyRange> difficultyRanges12 = new ArrayList<>();
Expand All @@ -260,7 +306,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType12);
if (size < 12)
{
testTypeRepository.save(testType12);
size++;
}

// PK 13번 : 브론즈 랜덤 디펜스
List<DifficultyRange> difficultyRanges13 = new ArrayList<>();
Expand All @@ -280,7 +330,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType13);
if (size < 13)
{
testTypeRepository.save(testType13);
size++;
}

// PK 14번 : 실버 랜덤 디펜스
List<DifficultyRange> difficultyRanges14 = new ArrayList<>();
Expand All @@ -300,7 +354,11 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType14);
if (size < 14)
{
testTypeRepository.save(testType14);
size++;
}

// PK 15번 : 골드 랜덤 디펜스
List<DifficultyRange> difficultyRanges15 = new ArrayList<>();
Expand All @@ -320,6 +378,10 @@ private void insertTestTypeData() {
.averageCorrectAnswerRate(0L)
.build();

testTypeRepository.save(testType15);
if (size < 15)
{
testTypeRepository.save(testType15);
size++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestType extends BaseEntity {
@Enumerated(EnumType.STRING)
private DifficultyLevel endDifficulty;

@ElementCollection(fetch = FetchType.EAGER)
@ElementCollection
private List<DifficultyRange> difficultyRanges;

private Long averageCorrectAnswerRate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ public class CheckAttemptProblemService {

private final SolvedCheckService solvedCheckService;
@Transactional
public void checkAttemptedProblemResult(Long testId, String bojId) {
Tests test = testRepository.findById(testId).orElseThrow(() -> new MorandiException(TestErrorCode.TEST_NOT_FOUND));
List<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(testId);
public void checkAttemptedProblemResult(Tests test, String bojId) {
List<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(test.getTestId());

attemptProblems.stream()
.filter(attemptProblem -> !attemptProblem.getIsSolved())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public List<Long> saveAttemptProblems(Member member, Tests test, List<BojProblem
.test(test)
.problem(problem)
.build();
System.out.println("attemptProblem = " + attemptProblem);
attemptProblemRepository.save(attemptProblem);
}
return bojProblemIds;
Expand Down

0 comments on commit 3b95302

Please sign in to comment.