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

핵심교양 졸업 계산 기능 구현 #161

Merged
merged 15 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
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 @@ -17,19 +17,23 @@ public class DetailCategoryResult {
private final boolean isSatisfiedMandatory;
private final int totalCredits;
private int takenCredits;
private int normalLeftCredit;
private int freeElectiveLeftCredit;
private final List<Lecture> takenMandatoryLectures = new ArrayList<>();
private final List<Lecture> haveToMandatoryLectures = new ArrayList<>();
private final List<Lecture> takenElectiveLectures = new ArrayList<>();
private final List<Lecture> haveToElectiveLectures = new ArrayList<>();

@Builder
private DetailCategoryResult(String detailCategoryName, boolean isCompleted, boolean isSatisfiedMandatory,
int totalCredits, int takenCredits) {
int totalCredits, int takenCredits, int normalLeftCredit, int freeElectiveLeftCredit) {
this.detailCategoryName = detailCategoryName;
this.isCompleted = isCompleted;
this.isSatisfiedMandatory = isSatisfiedMandatory;
this.totalCredits = totalCredits;
this.takenCredits = takenCredits;
this.normalLeftCredit = normalLeftCredit;
this.freeElectiveLeftCredit = freeElectiveLeftCredit;
}

public static DetailCategoryResult create(String detailCategoryName, boolean isSatisfiedMandatory,
Expand All @@ -40,26 +44,47 @@ public static DetailCategoryResult create(String detailCategoryName, boolean isS
.isSatisfiedMandatory(isSatisfiedMandatory)
.totalCredits(totalCredits)
.takenCredits(0)
.normalLeftCredit(0)
.freeElectiveLeftCredit(0)
.build();
}

public void calculate(Set<Lecture> taken, Set<Lecture> basicAcademicalLectures) {
public void calculate(Set<Lecture> taken, Set<Lecture> graduationLectures) {
addTakenLectures(taken);
calculateLeftCredit();
if(!checkCompleted()) {
addMandatoryLectures(taken, basicAcademicalLectures);
addMandatoryLectures(taken, graduationLectures);
}
}

public void addNormalLeftCredit(int normalLeftCredit) {
this.normalLeftCredit += normalLeftCredit;
}

public void addFreeElectiveLeftCredit(int freeElectiveLeftCredit) {
this.freeElectiveLeftCredit += freeElectiveLeftCredit;
}

private void addTakenLectures(Set<Lecture> taken) {
taken.forEach(lecture -> {
takenMandatoryLectures.add(lecture);
takenCredits += lecture.getCredit();
});
}

private void addMandatoryLectures(Set<Lecture> taken, Set<Lecture> basicAcademicalLectures) {
basicAcademicalLectures.removeAll(taken);
haveToMandatoryLectures.addAll(basicAcademicalLectures);
private void calculateLeftCredit() {
int leftCredit = takenCredits - totalCredits;
if (leftCredit > 0) {
if (detailCategoryName.equals("전공")) {
freeElectiveLeftCredit = leftCredit;
}
normalLeftCredit = leftCredit;
}
}

private void addMandatoryLectures(Set<Lecture> taken, Set<Lecture> graduationLectures) {
graduationLectures.removeAll(taken);
haveToMandatoryLectures.addAll(graduationLectures);
}

private boolean checkCompleted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
Set<TakenLecture> takenLectures,
Set<BasicAcademicalCulture> graduationLectures, int basicAcademicalCredit) {
Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);
DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);

Set<TakenLecture> removedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();
Expand All @@ -52,9 +50,11 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
removedTakenLecture.add(takenLecture);
taken.add(takenLecture.getLecture());
});
takenLectures.removeAll(removedTakenLecture);

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, basicAcademicalCredit,
List.of(detailCategoryResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ public boolean isSatisfied(StudentInformation studentInformation) {
}

@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation, Set<TakenLecture> takenLectures,
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,
Set<TakenLecture> takenLectures,
Set<BasicAcademicalCulture> graduationLectures, int basicAcademicalCredit) {

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);

Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);

Set<TakenLecture> removedTakenLecture = new HashSet<>();
Expand All @@ -41,9 +39,11 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
removedTakenLecture.add(takenLecture);
taken.add(takenLecture.getLecture());
});
takenLectures.removeAll(removedTakenLecture);

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, basicAcademicalCredit,
List.of(detailCategoryResult));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SocialScienceBasicAcademicManager implements BasicAcademicalManager
Lecture.of("KMD02102", "국제정치의이해", 3, 0, null),
Lecture.of("KMD02108", "현대사회와정보", 3, 0, null),
Lecture.of("KMD02140", "경제학들어가기", 3, 0, null),
Lecture.of( "KMD02186", "직무커뮤니케이션능력개발", 3, 0, null),
Lecture.of("KMD02186", "직무커뮤니케이션능력개발", 3, 0, null),
Lecture.of("KMD02113", "인간관계와커뮤니케이션", 3, 0, null),
Lecture.of("KMD02104", "인터넷과커뮤니케이션", 3, 0, null),
Lecture.of("KMD02114", "미시경제학원론", 3, 0, null),
Expand All @@ -34,12 +34,10 @@ public boolean isSatisfied(StudentInformation studentInformation) {
}

@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation, Set<TakenLecture> takenLectures,
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,
Set<TakenLecture> takenLectures,
Set<BasicAcademicalCulture> graduationLectures, int basicAcademicalCredit) {
Set<Lecture> basicAcademicalLectures = convertToLectureSet(graduationLectures);

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);
Set<TakenLecture> removedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();

Expand All @@ -51,10 +49,13 @@ public DetailGraduationResult createDetailGraduationResult(StudentInformation st
removedTakenLecture.add(takenLecture);
taken.add(takenLecture.getLecture());
});
takenLectures.removeAll(removedTakenLecture);

DetailCategoryResult detailCategoryResult = DetailCategoryResult.create(
BASIC_ACADEMICAL_CULTURE.getName(), true, basicAcademicalCredit);
detailCategoryResult.calculate(taken, basicAcademicalLectures);
takenLectures.removeAll(removedTakenLecture);

return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, 12, List.of(detailCategoryResult));
return DetailGraduationResult.create(BASIC_ACADEMICAL_CULTURE, basicAcademicalCredit,
List.of(detailCategoryResult));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@ class CommonCultureDetailCategoryManager {

public DetailCategoryResult generate(Set<TakenLecture> takenLectures,
Set<CommonCulture> graduationLectures, CommonCultureCategory category) {
DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create(
category.getName(), checkMandatorySatisfaction(takenLectures, category), category.getTotalCredit());
Set<Lecture> taken = new HashSet<>();

Set<Lecture> graduationCommonCultureLectures = categorizeCommonCultures(
graduationLectures, category);

Set<TakenLecture> removedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();

takenLectures.stream()
.filter(takenLecture -> graduationCommonCultureLectures.contains(takenLecture.getLecture()))
.forEach(takenLecture -> taken.add(takenLecture.getLecture()));
.forEach(takenLecture -> {
removedTakenLecture.add(takenLecture);
taken.add(takenLecture.getLecture());
});

DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create(
category.getName(), checkMandatorySatisfaction(takenLectures, category), category.getTotalCredit());
commonCultureDetailCategoryResult.calculate(taken, graduationCommonCultureLectures);

takenLectures.removeAll(removedTakenLecture);

return commonCultureDetailCategoryResult;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture;

import static com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.Semester.*;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.Lecture;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentInformation;

public class CoreCultureDetailCategoryManager {

private static final List<String> ICT_DEPARTMENTS = List.of(
"응용소프트웨어학과",
"데이터테크놀로지학과",
"디지털콘텐츠디자인학과");
private static final Lecture 과학과기술_예외_과목 = Lecture.from("KMA02136");
private static final Set<Lecture> 문화와예술_예외_과목 = Set.of(
Lecture.from("KMA02155"),
Lecture.from("KMA02156"));

public DetailCategoryResult generate(StudentInformation studentInformation, Set<TakenLecture> takenLectures,
Set<CoreCulture> graduationLectures, CoreCultureCategory category) {
Set<Lecture> graduationCoreCultureLectures = categorizeCommonCultures(graduationLectures, category);
Set<TakenLecture> finishedTakenLecture = new HashSet<>();
Set<Lecture> taken = new HashSet<>();

takenLectures.stream()
.filter(takenLecture -> graduationCoreCultureLectures.contains(takenLecture.getLecture()))
.forEach(takenLecture -> {
finishedTakenLecture.add(takenLecture);
taken.add(takenLecture.getLecture());
});
takenLectures.removeAll(finishedTakenLecture);

DetailCategoryResult commonCultureDetailCategoryResult = DetailCategoryResult.create(
category.getName(), true, category.getTotalCredit());
calculateFreeElectiveLeftCredit(studentInformation, taken, commonCultureDetailCategoryResult);
calculateNormalLeftCredit(taken, finishedTakenLecture, commonCultureDetailCategoryResult);
commonCultureDetailCategoryResult.calculate(taken, graduationCoreCultureLectures);

return commonCultureDetailCategoryResult;
}

private Set<Lecture> categorizeCommonCultures(Set<CoreCulture> graduationLectures,
CoreCultureCategory category) {
return graduationLectures.stream()
.filter(coreCulture -> coreCulture.getCoreCultureCategory() == category)
.map(CoreCulture::getLecture)
.collect(Collectors.toSet());
}

private void calculateFreeElectiveLeftCredit(StudentInformation studentInformation, Set<Lecture> taken,
DetailCategoryResult commonCultureDetailCategoryResult) {
if (ICT_DEPARTMENTS.contains(studentInformation.getDepartment()) && (taken.contains(과학과기술_예외_과목))) {
taken.remove(과학과기술_예외_과목);
int exceptionLectureCredit = 3;
commonCultureDetailCategoryResult.addFreeElectiveLeftCredit(exceptionLectureCredit);
}
}

private void calculateNormalLeftCredit(Set<Lecture> taken, Set<TakenLecture> finishedTakenLecture,
DetailCategoryResult commonCultureDetailCategoryResult) {
int normalLeftCredit = finishedTakenLecture.stream()
.filter(takenLecture -> 문화와예술_예외_과목.contains(takenLecture.getLecture())
&& takenLecture.getYear() == 2022
&& takenLecture.getSemester() == FIRST)
.mapToInt(takenLecture -> takenLecture.getLecture().getCredit())
.sum();
taken.removeAll(문화와예술_예외_과목);
commonCultureDetailCategoryResult.addNormalLeftCredit(normalLeftCredit);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.plzgraduate.myongjigraduatebe.graduation.domain.service.coreculture;

import static com.plzgraduate.myongjigraduatebe.graduation.domain.model.GraduationCategory.CORE_CULTURE;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailCategoryResult;
import com.plzgraduate.myongjigraduatebe.graduation.domain.model.DetailGraduationResult;
import com.plzgraduate.myongjigraduatebe.graduation.domain.service.GraduationManager;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCulture;
import com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory;
import com.plzgraduate.myongjigraduatebe.takenlecture.domain.model.TakenLecture;
import com.plzgraduate.myongjigraduatebe.user.domain.model.StudentInformation;

public class CoreCultureGraduationManager implements GraduationManager<CoreCulture> {
@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,
Comment on lines +18 to +20
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class CoreCultureGraduationManager implements GraduationManager<CoreCulture> {
@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,
public class CoreCultureGraduationManager implements GraduationManager<CoreCulture> {
@Override
public DetailGraduationResult createDetailGraduationResult(StudentInformation studentInformation,

Set<TakenLecture> takenLectures, Set<CoreCulture> graduationLectures, int coreCultureGraduationTotalCredit) {
CoreCultureDetailCategoryManager coreCultureDetailCategoryManager = new CoreCultureDetailCategoryManager();
List<DetailCategoryResult> coreCultureDetailCategoryResults = Arrays.stream(CoreCultureCategory.values())
.map(coreCultureCategory -> coreCultureDetailCategoryManager.generate(studentInformation, takenLectures,
graduationLectures, coreCultureCategory))
.collect(Collectors.toList());

return DetailGraduationResult.create(CORE_CULTURE, coreCultureGraduationTotalCredit,
coreCultureDetailCategoryResults);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.plzgraduate.myongjigraduatebe.lecture.domain.model;

import lombok.Builder;
import lombok.Getter;

@Getter
public class CoreCulture {

private Lecture lecture;
private CoreCultureCategory coreCultureCategory;

@Builder
private CoreCulture(Lecture lecture, CoreCultureCategory coreCultureCategory) {
this.lecture = lecture;
this.coreCultureCategory = coreCultureCategory;
}

public static CoreCulture of(Lecture lecture, CoreCultureCategory category) {
return CoreCulture.builder()
.lecture(lecture)
.coreCultureCategory(category).build();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.coreCultureCategory(category).build();
.coreCultureCategory(category)
.build();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.plzgraduate.myongjigraduatebe.lecture.domain.model;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum CoreCultureCategory {

HISTORY_PHILOSOPHY("역사와철학", 3),
SOCIETY_COMMUNITY("사회와공동체", 3),
CULTURE_ART("문화와예술", 3),
SCIENCE_TECHNOLOGY("과학과기술", 3);

private final String name;
private final int totalCredit;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ private Lecture(String lectureCode, String name, int credit, int isRevoked, Stri
this.duplicateCode = duplicateCode;
}

public static Lecture from(String lectureCode) {
return Lecture.builder().
lectureCode(lectureCode)
.build();
}

public static Lecture of(String lectureCode, String name, int credit, int isRevoked, String duplicateCode) {
return Lecture.builder()
.lectureCode(lectureCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.plzgraduate.myongjigraduatebe.fixture;

import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_과학과기술;
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_문화와예술;
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_사회와공동체;
import static com.plzgraduate.myongjigraduatebe.fixture.CoreCultureFixture.핵심교양_역사와철학;
import static com.plzgraduate.myongjigraduatebe.lecture.domain.model.CoreCultureCategory.*;

import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;


public class CoreCultureCategoryFixture implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
return Stream.of(
Arguments.arguments(HISTORY_PHILOSOPHY,핵심교양_역사와철학()),
Arguments.arguments(SOCIETY_COMMUNITY, 핵심교양_사회와공동체()),
Arguments.arguments(CULTURE_ART, 핵심교양_문화와예술()),
Arguments.arguments(SCIENCE_TECHNOLOGY, 핵심교양_과학과기술())
);
}
}
Loading