Skip to content

Commit

Permalink
Merge pull request #300 from ASAP-as-soon-as-possible/feat/#299
Browse files Browse the repository at this point in the history
#299 [feat] 이미 추천한 회의 시간대를 이후 조합에서 추천하지 않는 로직 추가
  • Loading branch information
KWY0218 authored Aug 5, 2024
2 parents 46be6b5 + ae086b0 commit 870ad87
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![image](https://github.com/user-attachments/assets/5ab65502-bdc4-4ab1-955b-9b23c9c5498f)


ASAP은선호도 분석을 통해 최대 인원이 참석 가능한 회의시간을 자동으로 결정해 줌으로써, **다수가 시간을 조율하며 딜레이되는 시간을 줄여주는 서비스** 입니다.
ASAP은 선호도 분석을 통해 최대 인원이 참석 가능한 회의시간을 자동으로 결정해 줌으로써, **다수가 시간을 조율하며 딜레이되는 시간을 줄여주는 서비스** 입니다.

회의 관련 정보를 하나의 큐카드로 정리해 제공함으로써 회의 시간 외 추가 공지사항을 단톡방에 올리는 수고로움 또한 덜어주고자 합니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.asap.server.persistence.domain.enums.Duration;
import com.asap.server.persistence.repository.timeblock.dto.TimeBlockDto;
import com.asap.server.service.meeting.recommend.strategy.BestMeetingTimeStrategy;
import com.asap.server.service.meeting.recommend.strategy.MeetingTimeCasesStrategy;
import com.asap.server.service.meeting.recommend.strategy.ContinuousMeetingTimeStrategy;
import com.asap.server.service.meeting.recommend.strategy.MeetingTimeCasesStrategy;
import com.asap.server.service.vo.BestMeetingTimeVo;
import com.asap.server.service.vo.PossibleTimeCaseVo;
import java.util.ArrayList;
Expand All @@ -22,7 +22,7 @@ public class MeetingTimeRecommendService {
private final BestMeetingTimeStrategy bestMeetingTimeStrategy;

public List<BestMeetingTimeVo> getBestMeetingTime(
final List<TimeBlockDto> timeBlocks,
List<TimeBlockDto> timeBlocks,
final Duration duration,
final int userCount
) {
Expand All @@ -34,21 +34,34 @@ public List<BestMeetingTimeVo> getBestMeetingTime(
.filter(t -> t.userCount() == timeCase.memberCnt())
.toList();

List<BestMeetingTimeVo> candidateMeetingTimes = new ArrayList<>(
continuousMeetingTimeStrategy.find(timeBlocksFilteredUserCount, timeCase.duration()));
candidateMeetingTimes = bestMeetingTimeStrategy.find(candidateMeetingTimes, timeCase.duration());
bestMeetingTimes.addAll(candidateMeetingTimes);
List<BestMeetingTimeVo> candidateMeetingTimes =
continuousMeetingTimeStrategy.find(timeBlocksFilteredUserCount, timeCase.duration());

timeBlocks = timeBlocks.stream()
.filter(timeBlock -> candidateMeetingTimes
.stream()
.noneMatch(candidateMeetingTime -> isRecommendedMeetingTime(timeBlock, candidateMeetingTime))
)
.toList();

bestMeetingTimes.addAll(bestMeetingTimeStrategy.find(candidateMeetingTimes, timeCase.duration()));

if (bestMeetingTimes.size() < BEST_MEETING_TIME_SIZE) {
continue;
}

return bestMeetingTimes.stream().limit(BEST_MEETING_TIME_SIZE).collect(Collectors.toList());
return bestMeetingTimes.stream().limit(BEST_MEETING_TIME_SIZE).toList();
}

while (bestMeetingTimes.size() < BEST_MEETING_TIME_SIZE) {
bestMeetingTimes.add(null);
}
return bestMeetingTimes;
}

private boolean isRecommendedMeetingTime(TimeBlockDto timeBlock, BestMeetingTimeVo bestMeetingTime) {
return timeBlock.availableDate() == bestMeetingTime.date()
&& bestMeetingTime.startTime().getIndex() <= timeBlock.timeSlot().getIndex()
&& bestMeetingTime.endTime().getIndex() >= timeBlock.timeSlot().getIndex();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
public class ContinuousMeetingTimeStrategyImpl implements ContinuousMeetingTimeStrategy {
@Override
public List<BestMeetingTimeVo> find(List<TimeBlockDto> timeBlocks, Duration duration) {
List<BestMeetingTimeVo> response = new ArrayList<>();
if (timeBlocks.isEmpty()) {
return response;
}

int startIdx = 0;
int endIdx = 1;

List<BestMeetingTimeVo> response = new ArrayList<>();
while (endIdx < timeBlocks.size()) {
TimeBlockDto endTimeBlock = timeBlocks.get(endIdx - 1);
TimeBlockDto nextTimeBlock = timeBlocks.get(endIdx);
Expand Down Expand Up @@ -49,7 +53,7 @@ public List<BestMeetingTimeVo> find(List<TimeBlockDto> timeBlocks, Duration dura
}
return response.stream()
.sorted((t1, t2) -> t2.weight() - t1.weight())
.collect(Collectors.toList());
.toList();
}

private void validateAndAddMeetingTime(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.asap.server.service.meeting.recommend;

import static com.asap.server.persistence.domain.enums.TimeSlot.*;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_12_00;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_12_30;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_13_00;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_13_30;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_15_00;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_15_30;
import static com.asap.server.persistence.domain.enums.TimeSlot.SLOT_16_00;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import com.asap.server.common.generator.TimeBlockDtoGenerator;
Expand Down Expand Up @@ -103,15 +109,18 @@ public void getBestMeetingTime4() {
LocalDate availableDate = LocalDate.of(2023, 7, 10);
LocalDate availableDate2 = LocalDate.of(2023, 7, 11);

TimeBlockDto timeBlock = new TimeBlockDto(availableDate, SLOT_12_00, 0, 2L);
TimeBlockDto timeBlock2 = new TimeBlockDto(availableDate, SLOT_12_30, 0, 2L);
TimeBlockDto timeBlock3 = new TimeBlockDto(availableDate2, SLOT_12_30, 0, 2L);
TimeBlockDto timeBlock4 = new TimeBlockDto(availableDate2, SLOT_13_00, 0, 2L);
List<TimeBlockDto> timeBlocks = List.of(timeBlock, timeBlock2, timeBlock3, timeBlock4);
List<TimeBlockDto> tempTimeBlocks = TimeBlockDtoGenerator
.generator(availableDate, SLOT_12_00, SLOT_15_30, 0, 2L);
List<TimeBlockDto> tempTimeBlocks2 = TimeBlockDtoGenerator
.generator(availableDate2, SLOT_12_30, SLOT_13_00, 0, 2L);
List<TimeBlockDto> timeBlocks = new ArrayList<>() {{
addAll(tempTimeBlocks);
addAll(tempTimeBlocks2);
}};

BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_00, 0);
BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_30, 0);
BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_12_30, 0);
BestMeetingTimeVo e2 = new BestMeetingTimeVo(availableDate, SLOT_15_00, SLOT_16_00, 0);
BestMeetingTimeVo e3 = new BestMeetingTimeVo(availableDate2, SLOT_12_30, SLOT_13_30, 0);
List<BestMeetingTimeVo> expected = List.of(e1, e2, e3);

// when
Expand Down Expand Up @@ -196,4 +205,23 @@ public void getBestMeetingTime7() {
// then
assertThat(result).isEqualTo(expected);
}

@Test
@DisplayName("이미 추천한 시간대는 이후 조합에서 추천하지 않는다.")
public void getBestMeetingTime8() {
// given
LocalDate availableDate = LocalDate.of(2023, 7, 10);

List<TimeBlockDto> timeBlocks = TimeBlockDtoGenerator
.generator(availableDate, SLOT_12_00, SLOT_15_00, 0, 2L);

BestMeetingTimeVo e1 = new BestMeetingTimeVo(availableDate, SLOT_12_00, SLOT_13_30, 0);
List<BestMeetingTimeVo> expected = Arrays.asList(e1, null, null);

// when
List<BestMeetingTimeVo> result = meetingTimeRecommendService.getBestMeetingTime(timeBlocks, Duration.HOUR_HALF, 2);

// then
assertThat(result).isEqualTo(expected);
}
}

0 comments on commit 870ad87

Please sign in to comment.