Skip to content

Commit

Permalink
[#23] refactor: 요금 차트를 위한 요금 카운트 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hsik0225 committed May 28, 2020
1 parent 529d124 commit dcb25e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class Statistics {
private int averagePrice;

private List<Integer> prices;

private int[] counts;
}
13 changes: 12 additions & 1 deletion BE/src/main/java/com/codesquad/airbnb/infra/dao/ViewDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
averagePrice = calculateAverage(prices);
}

return new Statistics(lowestPrice, highestPrice, averagePrice, prices);
int endPrice = 1000000;
int divide = 20000;
int[] counts = new int[endPrice/divide];

for (int price : prices) {
if((price/divide) >= (endPrice/divide)) {
counts[(endPrice/divide)-1]++;
}
counts[price/divide] ++;
}

return new Statistics(lowestPrice, highestPrice, averagePrice, prices, counts);
}

private Integer calculateAverage(List<Integer> prices) {
Expand Down

0 comments on commit dcb25e9

Please sign in to comment.