티스토리 뷰
https://github.com/ghrnwjd/graduation-plan-plus/tree/main
1. 시작 페이지
2. 로그인 페이지
2-1 회원가입
Controller
@PostMapping("/student/add/{department}")
public ResponseDto addStudent(@RequestBody Student student, @PathVariable String department) {
return studentService.addStudent(student, department);
}
Service
public ResponseDto addStudent(Student student, String department) {
if(department.equals("정보통신공학과")) {
student.setStudentDepartment(Department.정보통신공학과);
}
else if(department.equals("컴퓨터공학부")) {
student.setStudentDepartment(Department.컴퓨터공학부);
}
else {
return ResponseDto.builder()
.responseStatus(ResponseStatus.NO)
.build();
}
studentRepository.save(student);
return ResponseDto.builder()
.responseStatus(ResponseStatus.OK)
.build();
}
2-2. 로그인
로그인이 중요한 기능이 아니기에 폼과 다르게 학번만 받아도 로그인이 될 수 있도록 구현했다.
Controller
@PostMapping("/student/login")
public ResponseDto login(@RequestBody Student student) {
return studentService.login(student.getStudentNum());
}
Service
public ResponseDto login(String studentNum) {
Student student = studentRepository.findByStudentNum(studentNum).orElseGet(()-> {
return null;
});
if(student != null) {
return ResponseDto.builder()
.responseStatus(ResponseStatus.OK)
.build();
}
return ResponseDto.builder()
.responseStatus(ResponseStatus.NO)
.build();
}
2-2. 수강 과목 입력
따로 폼을 구현해놓지 않았지만 학생이 들은 수업 정보를 DB에 기입하기 위한 API를 만들었다.
@PostMapping("/student/learned/{studentNum}")
public ResponseDto learnedSubject(@RequestBody LearnedSubject learnedSubject, @PathVariable String studentNum) {
return studentService.learnedSubject(learnedSubject, studentNum);
}
public ResponseDto learnedSubject(LearnedSubject learnedSubject, String studentNum) {
Student student = findStudent(studentNum);
if(student == null) {
return ResponseDto.builder()
.responseStatus(ResponseStatus.NO)
.build();
}
learnedSubject.setStudent(student);
learnedSubjectRepository.save(learnedSubject);
return ResponseDto.builder()
.responseStatus(ResponseStatus.OK)
.build();
}
3. 메인페이지
3-1 내가 들은 학점 확인하기
Controller
@GetMapping("/student/creditInfo/{studentNum}")
public HashMap<String, Integer> getRemainedCredit(@PathVariable String studentNum) {
return studentService.calculateCreditInfo(studentNum);
}
Service
public HashMap<String, Integer> calculateCreditInfo(String studentNum) {
Student student = findStudent(studentNum);
HashMap<String, Integer> needsCredit = needsCreditInfo(student.getStudentDepartmentType());
List<LearnedSubject> learnedSubjectList = learnedSubjectRepository.findAllByStudent(student).orElseGet(()-> {
return null;
});
List<Integer> studentCreditList = subjectService.getSubjectCreditInfo(learnedSubjectList, student.getStudentDepartment());
int studentMajorCredit = studentCreditList.get(0), studentMinorCredit = studentCreditList.get(1);
if(learnedSubjectList == null) {
return null;
}
HashMap<String, Integer> postCreditList = new HashMap<String, Integer>();
postCreditList.put("전공필요학점", needsCredit.get("전공"));
postCreditList.put("전공들은학점", studentMajorCredit);
postCreditList.put("전공남은학점", (needsCredit.get("전공") - studentMajorCredit ));
postCreditList.put("교양필요학점", needsCredit.get("교양"));
postCreditList.put("교양들은학점", studentMinorCredit);
postCreditList.put("교양남은학점", (needsCredit.get("교양") - studentMinorCredit ));
return postCreditList;
}
3-2 학기별 성적 확인하기
Controller
@GetMapping("/student/learnedSubject/semesterGrade/{studentNum}")
public HashMap<String, Double> getSemesterGrade(@PathVariable String studentNum){
return subjectService.calculateSemesterGrade(studentNum);
}
Service
public HashMap<String, Double> calculateSemesterGrade(String studentNum) {
Student student = studentRepository.findByStudentNum(studentNum).orElseGet(()-> {
return null;
});
HashMap<String, Double> correspondGrade = new HashMap<>();
List<LearnedSubject> learnedSubjectList_21_1 = learnedSubjectRepository.findAllByStudentAndLearnedSubjectSemester(student, "21년 1학기")
.orElseGet(() -> {
return null;
});
SubjectCredit subjectCredit1 = calculateCorresponed(learnedSubjectList_21_1, student);
if(learnedSubjectList_21_1!= null) {
correspondGrade.put("21년 1학기", Math.round((subjectCredit1.grade / subjectCredit1.credit) * 10) / 10.0);
}
List<LearnedSubject> learnedSubjectList_21_2 = learnedSubjectRepository.findAllByStudentAndLearnedSubjectSemester(student, "21년 2학기")
.orElseGet(() -> {
return null;
});
SubjectCredit subjectCredit2 = calculateCorresponed(learnedSubjectList_21_2, student);
if(learnedSubjectList_21_2!= null) {
correspondGrade.put("21년 2학기", Math.round((subjectCredit2.grade / subjectCredit2.credit) * 10) / 10.0);
}
List<LearnedSubject> learnedSubjectList_22_1 = learnedSubjectRepository.findAllByStudentAndLearnedSubjectSemester(student, "22년 1학기")
.orElseGet(() -> {
return null;
});
SubjectCredit subjectCredit3 = calculateCorresponed(learnedSubjectList_22_1, student);
if(learnedSubjectList_22_1!= null) {
correspondGrade.put("22년 1학기", Math.round((subjectCredit3.grade / subjectCredit3.credit) * 10) / 10.0);
}
List<LearnedSubject> learnedSubjectList_22_2 = learnedSubjectRepository.findAllByStudentAndLearnedSubjectSemester(student, "22년 2학기")
.orElseGet(() -> {
return null;
});
SubjectCredit subjectCredit4 = calculateCorresponed(learnedSubjectList_22_2, student);
if(learnedSubjectList_22_2!= null) {
correspondGrade.put("22년 2학기", Math.round((subjectCredit4.grade / subjectCredit4.credit) * 10) / 10.0);
}
return correspondGrade;
}
3-3 학생 정보 확인하기
Controller
@GetMapping("/student/info/{studentNum}")
public Student getStudentInfo(@PathVariable String studentNum) {
return studentService.findStudent(studentNum);
}
Service
public Student findStudent(String studentNum) {
return studentRepository.findByStudentNum(studentNum).orElseGet(()-> {
return null;
});
}
4. 상세페이지
4-1 남은 전공과목 확인하기
Controller
@GetMapping("/student/remainedMajor/{studentNum}")
public HashMap<String, String> getRemainedMajor(@PathVariable String studentNum) {
return studentService.getRemainEssentialSubject(studentNum);
}
Service
public List<String> getRemainEssentialSubject(List<LearnedSubject> learnedSubjectList, Student student) {
List<String> remainedMajor = getEssentialSubject(student.getStudentDepartment());
for (LearnedSubject subjectTemp : learnedSubjectList) {
List<Subject> subjectList = subjectRepository.findAllBySubjectNameAndSubjectSemester(
subjectTemp.getLearnedSubjectName(), subjectTemp.getLearnedSubjectSemester()
).orElseGet(() -> {
return null;
});
// 과목명이 겹치는 수업이 존재...
if (subjectList == null) {
System.out.println("과목리스트가 존재하지 않아요");
return null;
}
Subject subject = null;
for (int i = 0; i < subjectList.size(); i++) {
if (subjectList.get(i).getSubjectDepartment().equals(student.getStudentDepartment().toString())) {
subject = subjectList.get(i);
}
}
if (subject == null) {
System.out.println("과목이 존재하지 않아요");
return null;
}
if (subject.getSubjectType() == SubjectType.MAJOR && subject.getSubjectEssential() == Essential.TRUE) {
int subjectIndex = remainedMajor.indexOf(subject.getSubjectName());
remainedMajor.remove(subjectIndex);
}
}
return remainedMajor;
}
5. 시간표 생성
5-1 키워드로 시간표 추천
Controller
@PostMapping("/student/recommend/{studentNum}")
public HashMap<String, String> KeywordRecommend(@RequestBody KeywordDto keywordDto, @PathVariable String studentNum) {
return subjectService.recommendSubject6(keywordDto, studentNum);
}
Service
public HashMap<String, String> recommendSubject6 (KeywordDto keywordDto, String studentNum) {
List<Subject> recommendSubjectList = recommendSubject(keywordDto, studentNum);
HashMap<String, String> recommendSubjectWithIndex = new HashMap<String, String>();
for(int i = 0; i < 6; i++){
if (i >= recommendSubjectList.size()){
break;
}
recommendSubjectWithIndex.put("추천과목"+(i+1), recommendSubjectList.get(i).getSubjectName());
}
return recommendSubjectWithIndex;
}
5-2 추천과목 기반 시간표 정보 받기
Controller
@PostMapping("/student/recommend/allSubjectInfo/{studentNum}")
public HashMap<String, String[]> recommendAllSubjectInfo(@RequestBody KeywordDto keywordDto, @PathVariable String studentNum) {
return subjectService.recommedAllSubjectInfo(keywordDto, studentNum);
}
Service
public HashMap<String, String[]> recommedAllSubjectInfo(KeywordDto keywordDto, String studentNum) {
HashMap<String, String[]> allSubjectInfo = new HashMap<>();
allSubjectInfo.put("월", new String[10]);
allSubjectInfo.put("화", new String[10]);
allSubjectInfo.put("수", new String[10]);
allSubjectInfo.put("목", new String[10]);
allSubjectInfo.put("금", new String[10]);
List<Subject> subjectList = recommendSubject(keywordDto, studentNum);
int max_length = Math.min(subjectList.size(), 6);
for(int i = 0; i < max_length; i++) {
Subject subject = subjectList.get(i);
String subjectTime = subject.getSubjectTime().trim();
String firstDay = null, secondDay = null;
// 여러 요일이면 "-"으로 일단 나눠주고, 요일-교시로 나눠 줌.
if (subjectTime.contains("-")) {
String temp0 = subjectTime.replaceAll(" ", "");
String temp1 = temp0.split("-")[0]; // 시작시간 월12
String temp2 = temp0.split("-")[1]; // 끝시간 화1
String[] temp1Array = temp1.split(""); // 월, 1, 2
String[] temp2Array = temp2.split("");
firstDay = temp1Array[0];
secondDay = temp2Array[0];
String [] tempFirstDayArray = allSubjectInfo.get(firstDay);
String [] tempSecondDayArray = allSubjectInfo.get(secondDay);
for (int j = 1; j < temp1Array.length; j++) {
if (temp1Array[j] != " ") {
tempFirstDayArray[j] = subject.getSubjectName();
}
}
for (int j = 1; j < temp2Array.length; j++) {
if (temp2Array[j] != " ") {
tempSecondDayArray[j]=subject.getSubjectName();
}
}
allSubjectInfo.put(firstDay, tempFirstDayArray);
allSubjectInfo.put(secondDay, tempSecondDayArray);
} else {
String[] tempArray = subjectTime.split("");
firstDay = tempArray[0];
String [] tempFirstDayArray = allSubjectInfo.get(firstDay);
for (int j = 1; j < tempArray.length; j++) {
if (tempArray[j] != " ") {
tempFirstDayArray[j]=subject.getSubjectName();
}
}
allSubjectInfo.put(firstDay, tempFirstDayArray);
}
}
return allSubjectInfo;
}
6. 채팅 기반 시간표 생성
6-1 채팅 기반 시간표 추천
Controller
@PostMapping("/student/recommend/input/{studentNum}")
public HashMap<String, String> userInputRecommend(@RequestBody UserInputDto userInputDto, @PathVariable String studentNum) {
return subjectService.getKeywordsFromUserInput(studentNum, userInputDto);
}
Service
public HashMap<String, String> getKeywordsFromUserInput(String studentNum, UserInputDto userInputDto) {
String data = userInputDto.getUserInput();
String sentence = data.replace("은", "").replace("는", "").replace("이", "").replace("가", "").replace("을", "").replace("이고", "").replace("에서", "");
List<String> keywords = new ArrayList<>();
keywords.add("시험 많다");
keywords.add("오픈북 이다");
keywords.add("성적 잘 준다");
keywords.add("팀프로젝트 많다");
keywords.add("과제 많다");
keywords.add("일찍 마쳐준다");
HashMap<Integer, Double> keywordsWeight = new HashMap<>();
double sum = 0;
for (int i = 0; i < keywords.size(); i++) {
sum += similarity(sentence, keywords.get(i));
}
for (int i = 0; i < keywords.size(); i++) {
keywordsWeight.put(i + 1, similarity(sentence, keywords.get(i)) / (keywords.get(i)).length());
}
List<Integer> sortKeywordIndex = new ArrayList<>(keywordsWeight.keySet());
Collections.sort(sortKeywordIndex, ((o1, o2) ->
(keywordsWeight.get(o2).compareTo(keywordsWeight.get(o1)))));
HashMap<Integer, String> keywordHashMap = new HashMap<>();
keywordHashMap.put(0, "GOODLECTURE");
keywordHashMap.put(1, "MANYEXAM");
keywordHashMap.put(2, "OPENBOOK");
keywordHashMap.put(3, "HIGHGRADE");
keywordHashMap.put(4, "TEAMPROJECT");
keywordHashMap.put(5, "MANYASSIGNMENT");
keywordHashMap.put(6, "EARLYSTOPPING");
KeywordDto keywordDto = KeywordDto.builder()
.keyword1(keywordHashMap.get(sortKeywordIndex.get(0)))
.keyword2(keywordHashMap.get(sortKeywordIndex.get(1)))
.keyword3(keywordHashMap.get(sortKeywordIndex.get(2)))
.build();
return recommendSubject6(keywordDto, studentNum);
}
6-2 해당과목 시간 받기
Controller
@PostMapping("/student/recommend/subjectInfo")
public HashMap<String, String> recommendsubjectInfo(@RequestBody UserInputDto userInputDto) throws Exception {
return subjectService.subjectInfo(userInputDto);
}
Service
public HashMap<String, String> subjectInfo(UserInputDto userInputDto) throws Exception {
Professor professor = professorRepository.findByProfessorName(userInputDto.getProfessorName()).orElseGet(()-> {
return null;
});
Subject subject = subjectRepository.findByProfessorAndSubjectNameAndSubjectSemester(
professor, userInputDto.getSubjectName(), "23년 1학기").orElseGet(()-> {
return null;
});
if(subject == null) {
throw new Exception();
}
String subjectTime = subject.getSubjectTime();
List<String> subjectInfo = new ArrayList<>();
String firstDay = null, secondDay = null;
if (subjectTime.contains("-")) {
String temp0 = subjectTime.replaceAll(" ", "");
String temp1 = temp0.split("-")[0]; // 시작시간 월12
String temp2 = temp0.split("-")[1]; // 끝시간 화1
String[] temp1Array = temp1.split(""); // 월, 1, 2
String[] temp2Array = temp2.split("");
firstDay = temp1Array[0];
for (int j = 1; j < temp1Array.length; j++) {
if (temp1Array[j] != " ") {
subjectInfo.add(firstDay + temp1Array[j]);
}
}
secondDay = temp2Array[0];
for (int j = 1; j < temp2Array.length; j++) {
if (temp2Array[j] != " ") {
subjectInfo.add(secondDay + temp2Array[j]);
}
}
} else {
String[] tempArray = subjectTime.split("");
firstDay = tempArray[0];
for (int j = 1; j < tempArray.length; j++) {
if (tempArray[j] != " ") {
subjectInfo.add(firstDay + tempArray[j]);
}
}
}
HashMap<String, String> subjectInfoWithIndex = new HashMap<String, String>();
for(int i = 0; i < 4; i++){
if (i >= subjectInfo.size()){
break;
}
subjectInfoWithIndex.put("강의시간"+(i+1), subjectInfo.get(i));
}
return subjectInfoWithIndex;
}
7. 시간표 상세설정 1
8. 시간표 상세설정 2
수상
'🔧 etc' 카테고리의 다른 글
[ERROR] BFS중 메모리초과 (0) | 2023.07.31 |
---|