Skip to content

Commit

Permalink
feat: grid의 마커 위치 정확도 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkenhw committed Oct 19, 2023
1 parent 3b77a70 commit a57f511
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public BigDecimal calculateCenterLongitude() {
return topLongitude.add(bottomLongitude).divide(BigDecimal.valueOf(2), 4, RoundingMode.CEILING);
}

public Point randomPoint() {
int size = points.size();
int randomIndex = (int) (Math.random() * size);
return points.get(randomIndex);
}

public void addPoint(Point point) {
points.add(point);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@ public class StationGridFacadeService {
private final StationGridCacheService stationGridCacheService;
private final ExecutorService executor = Executors.newFixedThreadPool(5);

private static List<GridWithCount> createCenterPointWhereHasStation(List<Grid> grids) {
return grids.stream()
.filter(Grid::hasStation)
.map(it -> GridWithCount.createCenterPoint(it, it.stationSize()))
.toList();
}

public List<GridWithCount> createGridWithCounts() {
GridGenerator gridGenerator = new GridGenerator();
List<Grid> grids = gridGenerator.createKorea();
List<CompletableFuture<Void>> futures = new ArrayList<>();

int loopSize = stationQueryService.findStationCount().intValue() / BATCH_SIZE;
long loopSize = stationQueryService.findStationCount() / BATCH_SIZE + 1;

int page = 0;
for (int i = 0; i < loopSize; i++) {
Expand All @@ -58,17 +51,24 @@ public List<GridWithCount> createGridWithCounts() {
futures.forEach(CompletableFuture::join);
executor.shutdown();

List<GridWithCount> list = createCenterPointWhereHasStation(grids);
List<GridWithCount> list = createRandomPointWhereHasStation(grids);
return new ArrayList<>(list);
}

private List<GridWithCount> createRandomPointWhereHasStation(List<Grid> grids) {
return grids.stream()
.filter(Grid::hasStation)
.map(it -> GridWithCount.createRandom(it, it.stationSize(), it.randomPoint()))
.toList();
}

public List<GridWithCount> counts(ClusterRequest request) {
List<GridWithCount> gridWithCounts = stationGridCacheService.findGrids(request);
List<Grid> displayGrid = createDisplayGrid(request);
List<Grid> grids = stationGridService.assignStationGridsWithCount(displayGrid, gridWithCounts);
List<GridWithCount> list = grids.stream()
.filter(Grid::existsCount)
.map(it -> GridWithCount.createCenterPoint(it, it.getCount()))
.map(it -> GridWithCount.createRandom(it, it.getCount(), it.randomPoint()))
.toList();
return new ArrayList<>(list);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.carffeine.carffeine.station.service.station.dto;

import com.carffeine.carffeine.station.domain.station.Grid;
import com.carffeine.carffeine.station.domain.station.Point;

import java.math.BigDecimal;

Expand All @@ -16,4 +17,8 @@ public static GridWithCount createCenterPoint(Grid grid, int count) {
BigDecimal centerLongitude = grid.calculateCenterLongitude();
return new GridWithCount(grid.getId(), centerLatitude, centerLongitude, count);
}

public static GridWithCount createRandom(Grid grid, int count, Point point) {
return new GridWithCount(grid.getId(), point.getLatitude().getValue(), point.getLongitude().getValue(), count);
}
}

0 comments on commit a57f511

Please sign in to comment.