Skip to content

Commit

Permalink
퀘스트 생성 시 남는 장소들을 버리지 말고 퀘스트에 채워주기
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeniuus committed Oct 1, 2024
1 parent 8bcb07e commit 2cdd07a
Showing 1 changed file with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Place>()
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
Expand Down

0 comments on commit 2cdd07a

Please sign in to comment.