From 2cdd07ac58c93b026845bc18089f60e531433bb5 Mon Sep 17 00:00:00 2001 From: Zeniuus Date: Tue, 1 Oct 2024 18:26:54 +0900 Subject: [PATCH] =?UTF-8?q?=ED=80=98=EC=8A=A4=ED=8A=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EB=82=A8=EB=8A=94=20=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20=EB=B2=84=EB=A6=AC=EC=A7=80=20=EB=A7=90?= =?UTF-8?q?=EA=B3=A0=20=ED=80=98=EC=8A=A4=ED=8A=B8=EC=97=90=20=EC=B1=84?= =?UTF-8?q?=EC=9B=8C=EC=A3=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/in/ClubQuestCreateAplService.kt | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/app-server/subprojects/bounded_context/quest/application/src/main/kotlin/club/staircrusher/quest/application/port/in/ClubQuestCreateAplService.kt b/app-server/subprojects/bounded_context/quest/application/src/main/kotlin/club/staircrusher/quest/application/port/in/ClubQuestCreateAplService.kt index 229f513f..7aacf984 100644 --- a/app-server/subprojects/bounded_context/quest/application/src/main/kotlin/club/staircrusher/quest/application/port/in/ClubQuestCreateAplService.kt +++ b/app-server/subprojects/bounded_context/quest/application/src/main/kotlin/club/staircrusher/quest/application/port/in/ClubQuestCreateAplService.kt @@ -90,25 +90,38 @@ class ClubQuestCreateAplService( val buildings = buildingToPlaces.keys.toList() val clusteredBuildings = clubQuestTargetBuildingClusterer.clusterBuildings(buildings, clusterCount) - val quests = clusteredBuildings.flatMap { (questCenterLocation, targetBuildings) -> - // take 2 * maxPlaceCountPerQuest places first and then cross validate them - val targets = buildingToPlaces.filter { it.key in targetBuildings } - val chunkedBuildings = chunkByMaxPlaceCountPerQuest(targets, maxPlaceCountPerQuest * 2) - chunkedBuildings.map { chunk -> questCenterLocation to chunk } - } + val questCandidates = clusteredBuildings + .flatMap { (questCenterLocation, targetBuildings) -> + val targets = buildingToPlaces.filter { it.key in targetBuildings } + val chunkedBuildings = chunkByMaxPlaceCountPerQuest(targets, maxPlaceCountPerQuest) - quests + chunkedBuildings.map { chunk -> questCenterLocation to chunk } + } .sortedByDescending { (_, targetBuildings) -> targetBuildings.values.sumOf { it.size } } - .take(clusterCount) // clusterCount 개의 퀘스트만 만든다. + + val quests = questCandidates.take(clusterCount) + val remainingPlaces = questCandidates + .subList(quests.size, questCandidates.size) + .flatMap { (_, placesByBuilding) -> placesByBuilding.values.flatten() } + .toMutableList() + val placeCountAdjustedQuests = quests.map { quest -> + val placesInQuest = quest.second.values.flatten() + if (remainingPlaces.isNotEmpty() && placesInQuest.size < maxPlaceCountPerQuest) { + val countToSupply = minOf(maxPlaceCountPerQuest - placesInQuest.size, remainingPlaces.size) + val placesToSupply = mutableListOf() + repeat(countToSupply) { + placesToSupply += remainingPlaces.removeFirst() + } + Pair(quest.first, (placesInQuest + placesToSupply).groupBy { it.building }) + } else { + quest + } + } + + placeCountAdjustedQuests .map { (location, targetBuildings) -> val b = targetBuildings - // 네이버 지도 api의 rate limit이 너무 낮아서 임시로 비활성화한다. .flatMap { it.value } -// .flatMap { (_, places) -> -// val validationResults = clubQuestTargetPlacesSearcher.crossValidatePlaces(places) -// places.filterIndexed { index, _ -> validationResults[index] } -// } - .take(maxPlaceCountPerQuest) .groupToClubQuestTargetBuildings() location to b