-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
769 additions
and
580 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...p/application/service/AppServiceInfo.java → ...plication/app_service/AppServiceInfo.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...pplication/service/AppServiceService.java → ...cation/app_service/AppServiceService.java
This file contains 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 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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/sopt/app/application/rank/SoptampPartRankCalculator.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.sopt.app.application.rank; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.PartPoint; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.PartRank; | ||
|
||
|
||
@RequiredArgsConstructor | ||
public class SoptampPartRankCalculator { | ||
|
||
private final List<PartPoint> partPoints; | ||
|
||
public List<PartRank> findAllPartRanks() { | ||
|
||
return partPoints.stream().map(this::createPartRank).toList(); | ||
} | ||
|
||
private PartRank createPartRank(PartPoint targetPartPoint) { | ||
|
||
return PartRank.builder() | ||
.part(targetPartPoint.part().getPartName()) | ||
.rank(getTargetPartRank(targetPartPoint)) | ||
.points(targetPartPoint.points()) | ||
.build(); | ||
} | ||
|
||
private int getTargetPartRank(PartPoint targetPartPoint) { | ||
int rankPoint = 1; | ||
|
||
for (PartPoint comparisonPartPoint : partPoints) { | ||
if (targetPartPoint.points() < comparisonPartPoint.points()) { | ||
rankPoint++; | ||
} | ||
} | ||
return rankPoint; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/sopt/app/application/rank/SoptampUserRankCalculator.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.sopt.app.application.rank; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.app.application.slack.SlackService; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.Main; | ||
import org.sopt.app.application.soptamp.SoptampPointInfo.Point; | ||
import org.sopt.app.application.soptamp.SoptampUserInfo; | ||
|
||
@RequiredArgsConstructor | ||
public class SoptampUserRankCalculator { | ||
|
||
private final List<SoptampUserInfo> soptampUsers; | ||
private final List<Main> ranking = new ArrayList<>(); | ||
private int rankPoint = 1; | ||
|
||
public List<Main> calculateRanking(List<Point> soptampPointList) { | ||
soptampPointList.stream() | ||
.sorted(Comparator.comparing(Point::getPoints).reversed()) | ||
.forEach(point -> | ||
findSoptampUserInfo(point.getSoptampUserId()) | ||
.ifPresentOrElse( | ||
user -> addUserToRanking(user, point.getPoints()), | ||
() -> SlackService.sendSlackMessage( | ||
"Warning", | ||
"soptamp_point에 해당하지 않는 soptamp_user가 확인되었습니다.\n" | ||
+ "soptampPointId: " + point.getId() + "\n" | ||
+ "soptampUserId: " + point.getSoptampUserId() | ||
) | ||
)); | ||
return ranking; | ||
} | ||
|
||
private void addUserToRanking(SoptampUserInfo user, Long userPoint) { | ||
ranking.add(Main.builder() | ||
.rank(getCurrentRankPointAndIncrement()) | ||
.nickname(user.getNickname()) | ||
.profileMessage(user.getProfileMessage()) | ||
.point(userPoint) | ||
.build()); | ||
} | ||
|
||
private Optional<SoptampUserInfo> findSoptampUserInfo(Long soptampUserId) { | ||
return soptampUsers.stream() | ||
.filter(user -> user.getId().equals(soptampUserId)) | ||
.findAny(); | ||
} | ||
|
||
private int getCurrentRankPointAndIncrement() { | ||
return rankPoint++; | ||
} | ||
|
||
@Deprecated | ||
public List<Main> calculateRank() { | ||
return soptampUsers.stream().sorted( | ||
Comparator.comparing(SoptampUserInfo::getTotalPoints).reversed()) | ||
.map(user -> Main.of(getCurrentRankPointAndIncrement(), user)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.