Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 대한민국을 2km단위로 나눠 해당 지역의 충전소 개수를 계산한다 #880

Merged
merged 24 commits into from
Oct 26, 2023

Conversation

kiarakim
Copy link
Collaborator

@kiarakim kiarakim commented Oct 18, 2023

📄 Summary

마커 클러스터링 기능 추가

🕰️ Actual Time of Completion

🙋🏻 More

close #819

@kiarakim kiarakim added 🌱 기능추가 새로운 기능 요청입니다 BE 백엔드 관련 이슈입니다 labels Oct 18, 2023
@kiarakim kiarakim self-assigned this Oct 18, 2023
Copy link
Collaborator

@sosow0212 sosow0212 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작업하시느라 수고하셨습니다!

다만 이런 작업을 할 때 pr 메시지로 어떤 작업을 한 건지 상세하게 적어주시면 좋을 것 같아요 ㅠㅠ

클러스터링 기능 추가인 것은 알겠지만.. 구체적으로 어떤 방식으로 진행한 건지 있으면 더 좋을 것 같아요!

몇 가지만 수정해주세요~
클러스터링 어려운 작업이었을텐데 고생 많으셨습니다~ 👍

Comment on lines 15 to 17
private Point top;
private Point bottom;
private List<Point> points;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

세 필드에 final을 붙일 수 있지 않나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final 좋네요 감사합니다~

@@ -26,7 +25,6 @@ public class StationService {
private final PeriodicCongestionCustomRepository periodicCongestionCustomRepository;
private final AtomicBoolean isRunning = new AtomicBoolean(false);

@Scheduled(cron = "0 0/10 * * * *")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스케쥴링을 제거한 이유가 있나요?


import java.util.List;

@RequiredArgsConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 클래스에서 기본 생성자가 필요하지 않아 보입니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네여. 감사합니다

grid.addCount(gridWithCount.count());
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 개행 제거해주세요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네엡!

Comment on lines +45 to +49
return gridWithCounts.stream()
.skip(lowerBound)
.limit(upperBound - lowerBound + 1)
.filter(grid -> grid.longitude().compareTo(minLongitude) >= 0 && grid.longitude().compareTo(maxLongitude) <= 0)
.toList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 어떤 행위인지 메서드 분리를 통해 명시해주는 건 어떨까요?
이해하는데 한참 걸렸네요 ㅠ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아이코.. 메서드 분리하고 이름도 적절하게 명시했습니다!

List<GridWithCount> gridWithCounts = stationGridCacheService.findGrids(request);
List<Grid> displayGrid = createDisplayGrid(request);
List<Grid> grids = stationGridService.assignStationGridsWithCount(displayGrid, gridWithCounts);
List<GridWithCount> list = grids.stream()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grids.stream().. 로직이 중복되어 보입니다 메서드로 분리해주면 더 보기 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵넵

class GridGeneratorTest {

@Test
void 좌표_2개로_구역을_나눠준다() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모든 테스트에 given - when - then이 빠져 있습니다 ㅠ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가했습니다!

assertThat(assignedGrids).map(it -> it.getPoints().size())
.isEqualTo(List.of(0, 0, 0, 1, 0, 0, 0, 0, 0));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 개행이 있습니다~

) {

public static GridWithCount createCenterPoint(Grid grid, int count) {
BigDecimal centerLatitude = grid.getTop().getLatitude().add(grid.getBottom().getLatitude()).divide(BigDecimal.valueOf(2), 4, RoundingMode.CEILING);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

체이닝이 너무 긴데, 가독성을 위해서 개행을 추가하거나 어떤 행위를 하는지 메서드로 분리해주시면 안될까요 혹은 grid안에 메서드로 뺄 순 없을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grid로 메서드를 뺐습니다!

while (size == 1000) {
log.info("page : {}", page);
List<StationPoint> stationPoint = stationQueryService.findStationPoint(page, size);
stationGridService.assignStationGrids(grids, stationPoint);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아~ 모든 충전소를 꺼내서 Grid로 구역을 나눠주는 로직이었군요!

while (size == 1000) {
int finalPage = page;
List<StationPoint> stationPoints = stationQueryService.findStationPoint(finalPage, size);
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> stationGridService.assignStationGrids(grids, stationPoints), executor);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 작업에 computablefuture를 사용한 이유가 있을까요? 무엇때문에 사용했는지 궁금합니다

저는 저 클래스에 대해 잘 모르기 때문에 사용 이유를 알고 싶어요

Comment on lines 15 to 18
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@EqualsAndHashCode
@Embeddable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필요 없는 어노테이션인 것 같아요 그리고 해당 객체를 불변으로 만들어주면 좋을 것 같아요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네에

@kiarakim kiarakim changed the title feat: 마커 클러스터링을 한다 feat: 대한민국을 2km단위로 나눠 해당 지역의 충전소 개수를 계산한다 Oct 19, 2023
Copy link
Collaborator

@sosow0212 sosow0212 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

다만 한 번에 뜻을 알기 힘든 부분이 있는데요.
사실 몇 번 보면 이해는 할 수 있지만 그래도 가급적이면 Merge 전에 해당 부분을 메서드 분리로 뜻을 명시해주시면 좋을 것 같아요.

수고하셨습니다 👍

public BigDecimal calculateCenterLatitude() {
Latitude topLatitude = top.getLatitude();
Latitude bottomLatitude = bottom.getLatitude();
return topLatitude.add(bottomLatitude).divide(BigDecimal.valueOf(2), 4, RoundingMode.CEILING);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 어떤 로직인지 한 눈에 보이지가 않아요 ㅠ
한 번 더 메서드 분리 해서 어떤 행위인지 뜻을 부여해주면 좋을 것 같아요

public BigDecimal calculateCenterLongitude() {
Longitude topLongitude = top.getLongitude();
Longitude bottomLongitude = bottom.getLongitude();
return topLongitude.add(bottomLongitude).divide(BigDecimal.valueOf(2), 4, RoundingMode.CEILING);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 마찬가지입니다!

if (lowerBound == -1 || upperBound == -1) {
int lowerBound = searchBoundaryLatitude(minLatitude, START_INDEX);
int upperBound = searchBoundaryLatitude(maxLatitude, lowerBound);
if (lowerBound == NO_LATITUDE_FOUND || upperBound == NO_LATITUDE_FOUND) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

훨씬 보기 좋아졌네요! 👍

@drunkenhw drunkenhw temporarily deployed to test October 19, 2023 10:35 — with GitHub Actions Inactive
@drunkenhw drunkenhw temporarily deployed to test October 19, 2023 10:51 — with GitHub Actions Inactive
@drunkenhw drunkenhw temporarily deployed to test October 19, 2023 11:09 — with GitHub Actions Inactive
@drunkenhw drunkenhw temporarily deployed to test October 19, 2023 11:42 — with GitHub Actions Inactive
@drunkenhw drunkenhw merged commit 4390673 into develop Oct 26, 2023
3 checks passed
@drunkenhw drunkenhw deleted the feat/819 branch October 26, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 관련 이슈입니다 🌱 기능추가 새로운 기능 요청입니다
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

마커 클러스터링을 한다
3 participants