From 80499e89f91313ff8b04b32b5ab33d6fd8e4cf76 Mon Sep 17 00:00:00 2001 From: d11210920 Date: Thu, 10 Oct 2024 12:27:38 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Category=20=EB=B6=84=EB=A5=98=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 입력받은 code들에 대한 Category를 분류해주는 로직 생성했습니다. Resolves: #34 --- .../CategoryJudge/CategoryJudgeUtils.java | 158 +++++++++++++++- .../CategoryJudge/CategoryJudgeUtilsImpl.java | 169 ------------------ 2 files changed, 156 insertions(+), 171 deletions(-) delete mode 100644 src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtilsImpl.java diff --git a/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtils.java b/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtils.java index b9264c7..a9c1281 100644 --- a/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtils.java +++ b/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtils.java @@ -1,11 +1,165 @@ package icurriculum.domain.categoryjudge; import icurriculum.domain.curriculum.Curriculum; +import icurriculum.domain.curriculum.data.AlternativeCourse; +import icurriculum.domain.curriculum.data.Core; import icurriculum.domain.take.Category; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; -public interface CategoryJudgeUtils { - Map judge(List codes, Curriculum curriculum); +import static icurriculum.domain.take.Category.*; + +public class CategoryJudgeUtils { + public static Map judge(List codes, Curriculum curriculum) { + + Map judgeCodes = new HashMap<>(); + + + + Set eMajor = curriculum.getMajorRequired().getCodeSet(); + Set cMajor = curriculum.getMajorSelect().getCodeSet(); + Set eGyo = curriculum.getGeneralRequired().getCodeSet(); + + Set creativityCodes = curriculum.getCreativity().getApprovedCodeSet(); + + Set swAiCodes = curriculum.getSwAi().getApprovedCodeSet(); + Set swAialternativeCodes = curriculum.getSwAi().getAreaAlternativeCodeSet(); + + AlternativeCourse alternativeCourse = curriculum.getAlternativeCourse(); + + for (String code : codes) { + Category category = judgeCore(code, curriculum); // 핵심교양 판단 + if (isCoreCode(category)) { + judgeCodes.put(code, category); + } else { // 핵심교양이 아닌 과목들의 다른영역 확인 + if (!creativityCodes.isEmpty() && creativityCodes.contains(code)) { + judgeCodes.put(code, Category.창의); + } else if (((!swAiCodes.isEmpty() && swAiCodes.contains(code)) || (swAialternativeCodes != null && swAialternativeCodes.contains(code)))) { + judgeCodes.put(code, Category.SW_AI); + } else if (eMajor.contains(code)) { + judgeCodes.put(code, Category.전공필수); + } else if (cMajor.contains(code)) { + judgeCodes.put(code, Category.전공선택); + } else if (eGyo.contains(code)) { + judgeCodes.put(code, Category.교양필수); + } else { + Set alternativeCodeSet = alternativeCourse.getAlternativeCodeSet(code); + if (!alternativeCodeSet.isEmpty()) { + judgeCodes.put(code, judgeAlternative(alternativeCodeSet, curriculum)); + } else { + judgeCodes.put(code, 교양선택); + } + } + } + + } + return judgeCodes; + } + + /** + * 사용자 핵심교양 판별 메서드 + * + * @return 핵심교양 영역 + **/ + public static Category judgeCore(String code, Curriculum curriculum) { + + Core core = curriculum.getCore(); + Boolean isAreaFixed = core.getIsAreaFixed(); + + Category category = 교양선택; + + if (code.startsWith("GEC") || code.startsWith("GED")) { + char coreArea = code.charAt(3); // 핵교 영역 + switch (coreArea) { + case '1' -> category = Category.핵심교양1; + case '2' -> category = 핵심교양2; + case '3' -> category = Category.핵심교양3; + case '4' -> category = Category.핵심교양4; + case '5' -> category = Category.핵심교양5; + case '6' -> category = Category.핵심교양6; + default -> category = 교양선택; + } + } + if (!isAreaFixed) { + return notAreaFixed(category,code,core); + } else { + return areaFixed(category,code,core); + } + } + + public static Boolean isCoreCode(Category category) { + return !category.equals(교양선택); + } + + + public static Category judgeAlternative(Set codes, Curriculum curriculum) { + /** + * @params codes : 해당과목의 대체가능한 과목들 + */ + + Set eMajor = curriculum.getMajorRequired().getCodeSet(); + Set cMajor = curriculum.getMajorSelect().getCodeSet(); + Set eGyo = curriculum.getGeneralRequired().getCodeSet(); + + Set creativityCodes = curriculum.getCreativity().getApprovedCodeSet(); + + Set swAiCodes = curriculum.getSwAi().getApprovedCodeSet(); + Set swAialternativeCodes = curriculum.getSwAi().getAreaAlternativeCodeSet(); + + + for (String code : codes) { + Category category = judgeCore(code, curriculum); // 핵심교양 판단 + if (isCoreCode(category)) { + return category; + } else { // 핵심교양이 아닌 과목들의 다른영역 확인 + if (creativityCodes != null && creativityCodes.contains(code)) { + return Category.창의; + } else if (((swAiCodes != null && swAiCodes.contains(code)) || (swAialternativeCodes != null && swAialternativeCodes.contains(code)))) { + return Category.SW_AI; + } else if (eMajor.contains(code)) { + return Category.전공필수; + } else if (cMajor.contains(code)) { + return Category.전공선택; + } else if (eGyo.contains(code)) { + return Category.교양필수; + } + } + } + return 교양선택; + } + + public static Category notAreaFixed(Category category, String code, Core core) { + if(category != 교양선택) return category; + return getDeterminedCategory(code, core); + } + + public static Category areaFixed(Category category, String code, Core core) { + if(category != 교양선택) { + Set requiredAreaSet = core.getRequiredAreaSet(); + if(!requiredAreaSet.contains(category)) return 교양선택; + else { + if(core.getAreaDeterminedCodeSet(category).isEmpty()) return category; + } + } + return getDeterminedCategory(code, core); + } + + public static Category getDeterminedCategory(String code, Core core) { + Set determinedArea1 = core.getAreaDeterminedCodeSet(핵심교양1); + Set determinedArea2 = core.getAreaDeterminedCodeSet(핵심교양2); + Set determinedArea3 = core.getAreaDeterminedCodeSet(핵심교양3); + Set determinedArea4 = core.getAreaDeterminedCodeSet(핵심교양4); + Set determinedArea5 = core.getAreaDeterminedCodeSet(핵심교양5); + Set determinedArea6 = core.getAreaDeterminedCodeSet(핵심교양6); + if(determinedArea1.contains(code)) return 핵심교양1; + if(determinedArea2.contains(code)) return 핵심교양2; + if(determinedArea3.contains(code)) return 핵심교양3; + if(determinedArea4.contains(code)) return 핵심교양4; + if(determinedArea5.contains(code)) return 핵심교양5; + if(determinedArea6.contains(code)) return 핵심교양6; + return 교양선택; + } } diff --git a/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtilsImpl.java b/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtilsImpl.java deleted file mode 100644 index cda2971..0000000 --- a/src/main/java/icurriculum/domain/CategoryJudge/CategoryJudgeUtilsImpl.java +++ /dev/null @@ -1,169 +0,0 @@ -package icurriculum.domain.categoryjudge; - -import icurriculum.domain.curriculum.Curriculum; -import icurriculum.domain.curriculum.json.*; -import icurriculum.domain.take.Category; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class CategoryJudgeUtilsImpl implements CategoryJudgeUtils { - @Override - public Map judge(List codes, Curriculum curriculum) { - - Map judgeCodes = new HashMap<>(); - - CurriculumCodesJson curriculumCodesJson = curriculum.getCurriculumCodesJson(); // 교과과정 - - Set eMajor = curriculumCodesJson.findCodesByCategory(Category.전공필수); - Set cMajor = curriculumCodesJson.findCodesByCategory(Category.전공선택); - Set eGyo = curriculumCodesJson.findCodesByCategory(Category.교양필수); - - Set creativityCodes = curriculum.getCreativityJson().getConfirmedCodes(); // 창의 영역 지정과목 - - Set swAiCodes = curriculum.getSwAiJson().getConfirmedCodes(); - Set swAialternativeCodes = curriculum.getSwAiJson().getAlternativeCodes(); - - Map> alternativeCourseMap = curriculum.getAlternativeCourseJson().getAlternativeCourseMap(); - - for (String code : codes) { - Category category = judgeCore(code, curriculum); // 핵심교양 판단 - if (isCoreCode(category)) { - judgeCodes.put(code, category); - } else { // 핵심교양이 아닌 과목들의 다른영역 확인 - if (creativityCodes != null && creativityCodes.contains(code)) { - judgeCodes.put(code, Category.창의); - } else if (((swAiCodes != null && swAiCodes.contains(code)) || (swAialternativeCodes != null && swAialternativeCodes.contains(code)))) { - judgeCodes.put(code, Category.SW_AI); - } else if (eMajor.contains(code)) { - judgeCodes.put(code, Category.전공필수); - } else if (cMajor.contains(code)) { - judgeCodes.put(code, Category.전공선택); - } else if (eGyo.contains(code)) { - judgeCodes.put(code, Category.교양필수); - } else { - if (alternativeCourseMap.containsKey(code)) { - judgeCodes.put(code, judgeAlternative(alternativeCourseMap.get(code), curriculum)); - } else { - judgeCodes.put(code, Category.교양선택); - } - } - } - - } - return judgeCodes; - } - - /** - * 사용자 핵심교양 판별 메서드 - * - * @return 핵심교양 영역 - **/ - public Category judgeCore(String code, Curriculum curriculum) { - - CoreJson coreJson = curriculum.getCoreJson(); // 핵심교양 - Boolean isAreaConfirmed = coreJson.getIsAreaConfirmed(); // 지정 영역이있는지 확인 - Set requiredAreas = coreJson.getRequiredAreas(); // 핵심교양 영역 리스트 - Map> confirmedCodesByArea = coreJson.getConfirmedCodesByArea(); // 지정 영역 리스트 - Map> alternativeCodesByArea = coreJson.getAlternativeCodesByArea(); //영역별 대체 리스트 - - Set alternativeCoreCodes = null; - if (alternativeCodesByArea != null) { - alternativeCoreCodes = alternativeCodesByArea.get(Category.핵심교양6); - } - Category category; - - if (code.startsWith("GEC") || code.startsWith("GED")) { - char coreArea = code.charAt(3); // 핵교 영역 - switch (coreArea) { - case '1' -> category = Category.핵심교양1; - case '2' -> category = Category.핵심교양2; - case '3' -> category = Category.핵심교양3; - case '4' -> category = Category.핵심교양4; - case '5' -> category = Category.핵심교양5; - case '6' -> category = Category.핵심교양6; - default -> category = Category.교양선택; - } - } else if (alternativeCoreCodes != null && alternativeCoreCodes.contains(code)) { - return Category.핵심교양6; - } else { - if (confirmedCodesByArea != null) { - for (Category tempCategory : confirmedCodesByArea.keySet()) { - Set strings = confirmedCodesByArea.get(tempCategory); - if (strings.contains(code)) return tempCategory; - } - } - return Category.교양선택; - } - if (!isAreaConfirmed) { - if (confirmedCodesByArea != null && confirmedCodesByArea.containsKey(category)) { - if (confirmedCodesByArea.get(category).contains(code)) { - return category; - } else { - return Category.교양선택; - } - } else { - return category; - } - } else { - if (requiredAreas.contains(category)) { - if (confirmedCodesByArea.containsKey(category)) { - if (confirmedCodesByArea.get(category).contains(code)) { - return category; - } else { - return Category.교양선택; - } - } else { - return category; - } - } - } - - return Category.교양선택; - } - - public Boolean isCoreCode(Category category) { - return !category.equals(Category.교양선택); - } - - - public Category judgeAlternative(Set codes, Curriculum curriculum) { - /** - * @params codes : 해당과목의 대체가능한 과목들 - */ - CurriculumCodesJson curriculumCodesJson = curriculum.getCurriculumCodesJson(); // 교과과정 - - Set eMajor = curriculumCodesJson.findCodesByCategory(Category.전공필수); - Set cMajor = curriculumCodesJson.findCodesByCategory(Category.전공선택); - Set eGyo = curriculumCodesJson.findCodesByCategory(Category.교양필수); - - Set creativityCodes = curriculum.getCreativityJson().getConfirmedCodes(); - - Set swAiCodes = curriculum.getSwAiJson().getConfirmedCodes(); - Set swAialternativeCodes = curriculum.getSwAiJson().getAlternativeCodes(); - - - for (String code : codes) { - Category category = judgeCore(code, curriculum); // 핵심교양 판단 - if (isCoreCode(category)) { - return category; - } else { // 핵심교양이 아닌 과목들의 다른영역 확인 - if (creativityCodes != null && creativityCodes.contains(code)) { - return Category.창의; - } else if (((swAiCodes != null && swAiCodes.contains(code)) || (swAialternativeCodes != null && swAialternativeCodes.contains(code)))) { - return Category.SW_AI; - } else if (eMajor.contains(code)) { - return Category.전공필수; - } else if (cMajor.contains(code)) { - return Category.전공선택; - } else if (eGyo.contains(code)) { - return Category.교양필수; - } - } - } - return Category.교양선택; - } - -}