Skip to content

Commit be119cb

Browse files
authored
Merge pull request #222 from FunD-StockProject/fix/experiment-success-rate
Fix/experiment success rate
2 parents c3362b5 + 7e7bc32 commit be119cb

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/main/java/com/fund/stockProject/experiment/repository/ExperimentRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ public interface ExperimentRepository extends JpaRepository<Experiment, Integer>
5959
+ " SELECT u.email, COUNT(e.id) AS cnt "
6060
+ " FROM experiment e "
6161
+ " JOIN users u ON e.user_id = u.id "
62+
+ " WHERE e.status = 'COMPLETE' "
6263
+ " GROUP BY u.email "
6364
+ " ) AS total "
6465
+ "LEFT JOIN "
6566
+ " ( "
6667
+ " SELECT u.email, COUNT(e.id) AS cnt "
6768
+ " FROM experiment e "
6869
+ " JOIN users u ON e.user_id = u.id "
69-
+ " WHERE e.roi > 0 "
70+
+ " WHERE e.status = 'COMPLETE' AND e.roi > 0 "
7071
+ " GROUP BY u.email "
7172
+ " ) AS profitable "
7273
+ "ON total.email = profitable.email "

src/main/java/com/fund/stockProject/experiment/service/ExperimentService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,10 @@ public ExperimentStatusResponse getExperimentStatus(final CustomUserDetails cust
198198
.average() // OptionalDouble 반환
199199
.orElse(0.0);
200200

201-
final long count = experimentsByUserId.stream().filter(p -> p.getSellPrice() != null && p.getSellPrice() - p.getBuyPrice() > 0).count(); // 모의투자에 성공한 종목 개수
202-
double successRate = experimentsByUserId.size() > 0 ? ((double) count / experimentsByUserId.size()) * 100 : 0.0;
201+
// 완료된 실험 중 ROI > 0인 실험 수 계산
202+
final long completedCount = experimentsByUserId.stream().filter(p -> "COMPLETE".equals(p.getStatus())).count();
203+
final long profitCount = experimentsByUserId.stream().filter(p -> "COMPLETE".equals(p.getStatus()) && p.getRoi() != null && p.getRoi() > 0).count();
204+
double successRate = completedCount > 0 ? ((double) profitCount / completedCount) * 100 : 0.0;
203205

204206
return ExperimentStatusResponse.builder()
205207
.progressExperiments(progressExperimentsInfo) // 진행중인 실험 정보

src/main/java/com/fund/stockProject/notification/controller/NotificationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public ResponseEntity<NotificationResponse> createTestNotification(
162162

163163
Notification testNotification = Notification.builder()
164164
.user(user)
165-
.notificationType(NotificationType.SCORE_SPIKE)
165+
.notificationType(NotificationType.TEST)
166166
.title("테스트 알림")
167167
.body("이것은 테스트 알림입니다. " + System.currentTimeMillis())
168168
.isRead(false)

src/main/java/com/fund/stockProject/notification/domain/NotificationType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
@Schema(description = "알림 타입 Enum. 시스템이 사용자에게 전달할 수 있는 알림 분류")
66
public enum NotificationType {
77
@Schema(description = "점수 급변 (스파이크) 발생 시 전달되는 알림")
8-
SCORE_SPIKE("점수 급변 알림");
8+
SCORE_SPIKE("점수 급변 알림"),
9+
10+
@Schema(description = "테스트/개발용 알림")
11+
TEST("테스트 알림");
912

1013
private final String description;
1114

0 commit comments

Comments
 (0)