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: 버블차트 API #42

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
@AllArgsConstructor
@Builder
public class BubbleFrontRes {
private Long x;
private Long y;
private Long z;
private String name;
private int x;
private int y;
private int z;

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,33 @@ public ResponseEntity<SuccessResponse<List<BubbleFrontRes>>> getBubbleChart(@Pat
List<BubbleFrontRes> result = new ArrayList<>();
Random rand = new Random();

result.add(new BubbleFrontRes(6L, null, 0L, ""));
result.add(new BubbleFrontRes(null, 6, 0, 0));

Set<Long> usedRandomValues = new HashSet<>(); // to track used random values
Set<Integer> usedRandomValues = new HashSet<>(); // to track used random values

for (BubbleChartRes bubbleChart : bubbleChartList) {
Long x = Long.parseLong(bubbleChart.getDate());
Long y;
int x = Integer.parseInt(bubbleChart.getDate());
Integer y;

// Generate a unique random value
do {
y = (long) (rand.nextInt(10) + 1);
y = rand.nextInt(10) + 1;
} while (!usedRandomValues.add(y));

Long z = bubbleChart.getRank();
int z = Math.toIntExact(bubbleChart.getRank());
String name = bubbleChart.getKeyword();

result.add(new BubbleFrontRes(x, y, z, name));
result.add(new BubbleFrontRes(name,x, y, z));
}

// Add element at the end with values from the last index
// Add element at the end with values from the last index
if (!bubbleChartList.isEmpty()) {
BubbleChartRes lastBubbleChart = bubbleChartList.get(bubbleChartList.size() - 1);
result.add(new BubbleFrontRes(12L, null, 0L, ""));
result.add(new BubbleFrontRes("",12, 0, 0 ));
}

return ResponseEntity.ok(SuccessResponse.create(GET_CONTENTS_SUCCESS.getMessage(), result));

}


Expand Down