@ -270,16 +270,38 @@ public class RankingBiz {
}
} ) ;
computeScore ( rankingList , currentTask , competition , baseRatio ) ;
if ( competition . getTeamMaxCount ( ) = = null ) {
computeRanking ( rankingList , currentTask , 1 , now ) ;
} else {
computeRanking ( rankingList , currentTask , competition . getTeamMaxCount ( ) , now ) ;
}
// if(competition.getTeamMaxCount() == null){
// computeRanking(rankingList,currentTask,1,now);
// }else{
// computeRanking(rankingList,currentTask,competition.getTeamMaxCount(),now);
// }
computeRanking ( rankingList , currentTask , competition . getTeamMaxCount ( ) , now ) ;
computeMemberRank ( currentTask . getCompetitionId ( ) , currentTask . getStageId ( ) , competition . getTeamMaxCount ( ) ) ;
competition . setUpdateRankDate ( now ) ;
competitionDao . save ( competition ) ;
}
public void computeMemberRank ( Long compId , Integer stageId , Integer memberCount ) {
List < CompetitionMember > memberList = memberDao . findAllByCompetitionIdAndStageId ( compId , stageId ) ;
CompetitionTask task = taskDao . getByCompetitionIdAndStageId ( compId , stageId ) ;
if ( memberList = = null | | task = = null | | memberList . size ( ) = = 0 ) {
return ;
}
memberList . forEach ( member - > {
Double combineScore = computeCombineScore ( task , member . getExamScore ( ) , member . getFinanceScore ( ) ) ;
member . setCombineScore ( combineScore ) ;
memberDao . updateComineScore ( combineScore , member . getId ( ) ) ;
} ) ;
memberList . sort ( Comparator . comparing ( CompetitionMember : : getCombineScore ) . reversed ( ) ) ;
for ( int i = 0 ; i < memberList . size ( ) ; i + + ) {
int rank = i + 1 ;
CompetitionMember member = memberList . get ( i ) ;
member . setPersonalRank ( rank ) ;
memberDao . updatePersonalRank ( member . getUserId ( ) , stageId , compId , rank ) ;
}
memberDao . updateTeamRank ( task . getStageId ( ) , task . getCompetitionId ( ) , memberCount ) ;
}
private void computeScore ( List < Ranking > rankingList , CompetitionTask currentTask , Competition competition , Double baseRatio ) {
Double maxPnlRaito = rankingList . stream ( ) . mapToDouble ( rank - > { return rank . getPnlRatio ( ) = = null ? 0d : rank . getPnlRatio ( ) ; } ) . max ( ) . orElse ( 0D ) ;
@ -302,7 +324,7 @@ public class RankingBiz {
}
}
}
memberDao . updateRankingMemberData ( ranking . getReportId ( ) , financeScore, combineScore , baseRatio , ranking . getAvailable ( ) ,
memberDao . updateRankingMemberData ( ranking . getReportId ( ) , maxPnlRaito, financeScore, combineScore , baseRatio , ranking . getAvailable ( ) ,
ranking . getNav ( ) , ranking . getCloseCount ( ) , ranking . getOpenCount ( ) , ranking . getCumCommission ( ) , ranking . getPnlRatio ( ) ,
ranking . getCalmarRatio ( ) , ranking . getSharpRatio ( ) , ranking . getPnlRatioAnnual ( ) , ranking . getProfitLoss ( ) , ranking . getMaxDrawdown ( ) ,
ranking . getMarketValue ( ) , ranking . getUserNo ( ) , ranking . getCompId ( ) , ranking . getStageId ( ) ) ;
@ -412,12 +434,12 @@ public class RankingBiz {
} ) ;
} ) ;
rankingList . sort ( Comparator . comparing ( Ranking : : get Financ eScore) . reversed ( ) ) ;
rankingList . sort ( Comparator . comparing ( Ranking : : get Combin eScore) . reversed ( ) ) ;
for ( int i = 0 ; i < rankingList . size ( ) ; i + + ) {
int rank = i + 1 ;
Ranking ranking = rankingList . get ( i ) ;
ranking . setPersonalRank ( rank ) ;
memberDao . updatePersonalRank ( ranking . getUserNo ( ) , ranking . getStageId ( ) , ranking . getCompId ( ) , rank ) ;
// memberDao.updatePersonalRank(ranking.getUserNo(),ranking.getStageId(),ranking.getCompId(),rank);
}
// try {
// Map<Integer, Double> tcrMap = sortMapByValues(teamCombineRank);
@ -433,7 +455,7 @@ public class RankingBiz {
//
// }
rankingDao . saveAll ( rankingList ) ;
memberDao . updateTeamRank ( task . getStageId ( ) , task . getCompetitionId ( ) , memberCount ) ;
// memberDao.updateTeamRank(task.getStageId(),task.getCompetitionId(),memberCount);
memberDao . updateTeamRank2 ( now ) ;
}
@ -458,10 +480,13 @@ public class RankingBiz {
* @param financeScore
* @return
* /
private double computeCombineScore ( CompetitionTask task , Double examScore , d ouble financeScore ) {
private double computeCombineScore ( CompetitionTask task , Double examScore , D ouble financeScore ) {
if ( examScore = = null ) {
examScore = 0d ;
}
if ( financeScore = = null ) {
financeScore = 0d ;
}
Long power = task . getExamPower ( ) ;
if ( power = = null ) {
power = 0 L ;
@ -479,7 +504,17 @@ public class RankingBiz {
* @return
* /
private double computeFinaceScore ( CompetitionTask task , double userRatio , double baseRatio , double maxUserRatio ) {
double score = task . getFinanceBasePower ( ) + ( ( userRatio - baseRatio ) / ( maxUserRatio - baseRatio ) ) * task . getFinanceProfitPower ( ) ;
// double score = task.getFinanceBasePower() + ((userRatio - baseRatio) /(maxUserRatio -baseRatio))* task.getFinanceProfitPower();
// double score = task.getFinanceProfitPower() + ((userRatio - baseRatio) /(maxUserRatio -baseRatio))* task.getFinanceBasePower();
double score = 0d ;
if ( maxUserRatio > = 0 ) {
score = task . getFinanceProfitPower ( ) + ( userRatio / maxUserRatio ) * task . getFinanceBasePower ( ) ;
} else {
if ( userRatio = = 0 ) {
return task . getFinanceProfitPower ( ) ;
}
score = task . getFinanceProfitPower ( ) + ( maxUserRatio / userRatio ) * task . getFinanceBasePower ( ) ;
}
return score ;
}
}