-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#125 타임라인 내 성과 상태 판별 구현 #136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e2d3afc
:sparkles: feat: 성과 상태 지표 계산 및 비교 로직 구현
jinnieusLab 4e500bd
:recycle: refactor: TimelineService 내 기존 성과 상태 계산 라인 수정
jinnieusLab 33781e0
:recycle: refactor: TimelineService 내성과 상태 관련 중복 조회 제거
jinnieusLab f2f4036
:recycle: refactor: Timeline 생성 및 수정 시 비교하는 과거 데이터의 광고 집행 상태 지정 해제
jinnieusLab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 80 additions & 3 deletions
83
src/main/java/com/whereyouad/WhereYouAd/domains/timeline/domain/util/TimelineUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,90 @@ | ||
| package com.whereyouad.WhereYouAd.domains.timeline.domain.util; | ||
|
|
||
| import com.whereyouad.WhereYouAd.domains.advertisement.persistence.repository.projection.MetricSumProjection; | ||
| import com.whereyouad.WhereYouAd.domains.timeline.domain.constant.PerformanceStatus; | ||
| import com.whereyouad.WhereYouAd.domains.timeline.persistence.entity.Timeline; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.RoundingMode; | ||
|
|
||
| @Component | ||
| public class TimelineUtil { | ||
| // TODO: PerformanceStatus 판별 로직 추가 | ||
| public PerformanceStatus calculatePerformanceStatus(Timeline timeline) { | ||
| return null; | ||
|
|
||
| // 성과 상태 판별 로직 초안 | ||
| public PerformanceStatus calculatePerformanceStatus(Timeline timeline, MetricSumProjection currentFacts, MetricSumProjection pastFacts) { | ||
|
|
||
| // 데이터가 아예 없는 경우 방어 로직 (Projection은 SUM이 없으면 0을 반환하도록 COALESCE 되어있음) | ||
| if (currentFacts == null || pastFacts == null) { | ||
| return PerformanceStatus.ON_TRACK; | ||
| } | ||
|
|
||
| double totalRate = 0.0; | ||
| int activeMetricCount = 0; | ||
|
|
||
| // 1. 클릭수 비교 | ||
| if (timeline.isUseClick()) { | ||
| long currentClicks = currentFacts.getTotalClicks() != null ? currentFacts.getTotalClicks() : 0L; | ||
| long pastClicks = pastFacts.getTotalClicks() != null ? pastFacts.getTotalClicks() : 0L; | ||
|
|
||
| if (pastClicks > 0) { | ||
| totalRate += (double) currentClicks / pastClicks; | ||
| activeMetricCount++; | ||
| } | ||
| } | ||
|
|
||
| // 2. 전환수 비교 | ||
| if (timeline.isUseConversion()) { | ||
| long currentConv = currentFacts.getTotalConversions() != null ? currentFacts.getTotalConversions() : 0L; | ||
| long pastConv = pastFacts.getTotalConversions() != null ? pastFacts.getTotalConversions() : 0L; | ||
|
|
||
| if (pastConv > 0) { | ||
| totalRate += (double) currentConv / pastConv; | ||
| activeMetricCount++; | ||
| } | ||
| } | ||
|
|
||
| // 3. 노출수 비교 | ||
| if (timeline.isUseImpression()) { | ||
| long currentImp = currentFacts.getTotalImpressions() != null ? currentFacts.getTotalImpressions() : 0L; | ||
| long pastImp = pastFacts.getTotalImpressions() != null ? pastFacts.getTotalImpressions() : 0L; | ||
|
|
||
| if (pastImp > 0) { | ||
| totalRate += (double) currentImp / pastImp; | ||
| activeMetricCount++; | ||
| } | ||
| } | ||
|
|
||
| // 4. ROAS 비교 | ||
| if (timeline.isUseRoas()) { | ||
| BigDecimal currentSpend = currentFacts.getTotalSpend() != null ? currentFacts.getTotalSpend() : BigDecimal.ZERO; | ||
| BigDecimal currentRev = currentFacts.getTotalRevenue() != null ? currentFacts.getTotalRevenue() : BigDecimal.ZERO; | ||
| BigDecimal currentRoas = currentSpend.compareTo(BigDecimal.ZERO) > 0 ? currentRev.divide(currentSpend, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO; | ||
|
|
||
| BigDecimal pastSpend = pastFacts.getTotalSpend() != null ? pastFacts.getTotalSpend() : BigDecimal.ZERO; | ||
| BigDecimal pastRev = pastFacts.getTotalRevenue() != null ? pastFacts.getTotalRevenue() : BigDecimal.ZERO; | ||
| BigDecimal pastRoas = pastSpend.compareTo(BigDecimal.ZERO) > 0 ? pastRev.divide(pastSpend, 4, RoundingMode.HALF_UP) : BigDecimal.ZERO; | ||
|
|
||
| if (pastRoas.compareTo(BigDecimal.ZERO) > 0) { | ||
| totalRate += currentRoas.divide(pastRoas, 4, RoundingMode.HALF_UP).doubleValue(); | ||
| activeMetricCount++; | ||
| } | ||
| } | ||
|
|
||
| // 비교할 유효 지표가 없는 경우 | ||
| if (activeMetricCount == 0) { | ||
| return PerformanceStatus.ON_TRACK; | ||
| } | ||
|
|
||
| double avgRate = totalRate / activeMetricCount; | ||
|
|
||
| // 초안: 10% 이상 상승하면 ABOVE_AVG, 10% 이상 하락하면 UNDERPERFORM, 그 외 ON_TRACK | ||
| if (avgRate >= 1.1) { | ||
| return PerformanceStatus.ABOVE_AVG; | ||
| } else if (avgRate <= 0.9) { | ||
| return PerformanceStatus.UNDERPERFORM; | ||
| } else { | ||
| return PerformanceStatus.ON_TRACK; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.