Skip to content

Commit

Permalink
chore: 변수명 및 메서드명 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kckc0608 committed Oct 30, 2024
1 parent 5d665a0 commit b18bea5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ public StudyStatisticsResponse getStudyStatistics(Long studyId) {
studyValidator.validateStudyMentor(currentMember, study);

long totalStudentCount = studyHistories.size();
long studyCompleteStudentCount =
long studyCompletedStudentCount =
studyHistories.stream().filter(StudyHistory::isComplete).count();

List<StudyWeekStatisticsResponse> studyWeekStatisticsResponses = studyDetails.stream()
.map((studyDetail -> calculateWeekStatistics(studyDetail, totalStudentCount)))
.toList();

long averageAttendanceRate = calculateAverageWeekAttendanceRate(studyWeekStatisticsResponses);
long averageAssignmentSubmitRate = calculateAverageWeekAssignmentSubmitRate(studyWeekStatisticsResponses);
long averageAssignmentSubmissionRate = calculateAverageWeekAssignmentSubmissionRate(studyWeekStatisticsResponses);

return StudyStatisticsResponse.of(
totalStudentCount,
studyCompleteStudentCount,
studyCompletedStudentCount,
averageAttendanceRate,
averageAssignmentSubmitRate,
averageAssignmentSubmissionRate,
studyWeekStatisticsResponses);
}

Expand All @@ -156,25 +156,25 @@ private StudyWeekStatisticsResponse calculateWeekStatistics(StudyDetail studyDet
boolean isCanceledAssignment = !studyDetail.getAssignment().isOpen() || isCanceledWeek;

if (totalStudentCount == 0) {
return StudyWeekStatisticsResponse.emptyOf(studyDetail.getWeek(), isCanceledAssignment, isCanceledWeek);
return StudyWeekStatisticsResponse.empty(studyDetail.getWeek(), isCanceledAssignment, isCanceledWeek);
}

if (isCanceledWeek) {
return StudyWeekStatisticsResponse.canceledWeekFrom(studyDetail.getWeek());
return StudyWeekStatisticsResponse.canceledWeek(studyDetail.getWeek());
}

long attendanceCount = attendanceRepository.countByStudyDetailId(studyDetail.getId());
long attendanceRate = Math.round(attendanceCount / (double) totalStudentCount * 100);

if (isCanceledAssignment) {
return StudyWeekStatisticsResponse.canceledAssignmentOf(studyDetail.getWeek(), attendanceRate);
return StudyWeekStatisticsResponse.assignmentCanceled(studyDetail.getWeek(), attendanceRate);
}

long assignmentCount =
assignmentHistoryRepository.countByStudyDetailIdAndSubmissionStatusEquals(studyDetail.getId(), SUCCESS);
long assignmentRate = Math.round(assignmentCount / (double) totalStudentCount * 100);

return StudyWeekStatisticsResponse.openedOf(studyDetail.getWeek(), attendanceRate, assignmentRate);
return StudyWeekStatisticsResponse.opened(studyDetail.getWeek(), attendanceRate, assignmentRate);
}

private long calculateAverageWeekAttendanceRate(List<StudyWeekStatisticsResponse> studyWeekStatisticsResponses) {
Expand All @@ -188,15 +188,15 @@ private long calculateAverageWeekAttendanceRate(List<StudyWeekStatisticsResponse
return Math.round(averageAttendanceRate);
}

private long calculateAverageWeekAssignmentSubmitRate(
private long calculateAverageWeekAssignmentSubmissionRate(
List<StudyWeekStatisticsResponse> studyWeekStatisticsResponses) {

double averageAssignmentSubmitRate = studyWeekStatisticsResponses.stream()
.filter(studyWeekStatistics -> !studyWeekStatistics.isCanceledAssignment())
.mapToLong(StudyWeekStatisticsResponse::assignmentSubmitRate)
double averageAssignmentSubmissionRate = studyWeekStatisticsResponses.stream()
.filter(studyWeekStatistics -> !studyWeekStatistics.isAssignmentCanceled())
.mapToLong(StudyWeekStatisticsResponse::assignmentSubmissionRate)
.average()
.orElse(0);

return Math.round(averageAssignmentSubmitRate);
return Math.round(averageAssignmentSubmissionRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ public record StudyStatisticsResponse(
@Schema(description = "스터디 전체 수강생 수") Long totalStudentCount,
@Schema(description = "스터디 수료 수강생 수") Long completeStudentCount,
@Schema(description = "평균 출석률") Long averageAttendanceRate,
@Schema(description = "평균 과제 제출률") Long averageAssignmentSubmitRate,
@Schema(description = "평균 과제 제출률") Long averageAssignmentSubmissionRate,
@Schema(description = "스터디 수료율") Long studyCompleteRate,
@Schema(description = "주차별 출석률 및 과제 제출률") List<StudyWeekStatisticsResponse> studyWeekStatisticsResponses) {

public static StudyStatisticsResponse of(
Long totalStudentCount,
Long completeStudentCount,
Long averageAttendanceRate,
Long averageAssignmentSubmitRate,
Long averageAssignmentSubmissionRate,
List<StudyWeekStatisticsResponse> studyWeekStatisticsResponses) {
return new StudyStatisticsResponse(
totalStudentCount,
completeStudentCount,
averageAttendanceRate,
averageAssignmentSubmitRate,
averageAssignmentSubmissionRate,
totalStudentCount == 0 ? 0 : Math.round(completeStudentCount / (double) totalStudentCount * 100),
studyWeekStatisticsResponses);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
public record StudyWeekStatisticsResponse(
@Schema(description = "스터디 주차") Long week,
@Schema(description = "출석률") Long attendanceRate,
@Schema(description = "과제 제출률") Long assignmentSubmitRate,
@Schema(description = "과제 휴강 여부") boolean isCanceledAssignment,
@Schema(description = "과제 제출률") Long assignmentSubmissionRate,
@Schema(description = "과제 휴강 여부") boolean isAssignmentCanceled,
@Schema(description = "스터디 휴강 여부") boolean isCanceledWeek) {

public static StudyWeekStatisticsResponse openedOf(Long week, Long attendanceRate, Long assignmentSubmitRate) {
return new StudyWeekStatisticsResponse(week, attendanceRate, assignmentSubmitRate, false, false);
public static StudyWeekStatisticsResponse opened(Long week, Long attendanceRate, Long assignmentSubmissionRate) {
return new StudyWeekStatisticsResponse(week, attendanceRate, assignmentSubmissionRate, false, false);
}

public static StudyWeekStatisticsResponse emptyOf(Long week, boolean isCanceledAssignment, boolean isCanceledWeek) {
public static StudyWeekStatisticsResponse empty(Long week, boolean isCanceledAssignment, boolean isCanceledWeek) {
return new StudyWeekStatisticsResponse(week, 0L, 0L, isCanceledAssignment, isCanceledWeek);
}

public static StudyWeekStatisticsResponse canceledWeekFrom(Long week) {
return StudyWeekStatisticsResponse.emptyOf(week, true, true);
public static StudyWeekStatisticsResponse canceledWeek(Long week) {
return StudyWeekStatisticsResponse.empty(week, true, true);
}

public static StudyWeekStatisticsResponse canceledAssignmentOf(Long week, Long attendanceRate) {
public static StudyWeekStatisticsResponse assignmentCanceled(Long week, Long attendanceRate) {
return new StudyWeekStatisticsResponse(week, attendanceRate, 0L, true, false);
}
}

0 comments on commit b18bea5

Please sign in to comment.