@@ -441,46 +441,49 @@ private function determineRarestAchievement(array &$recapData, User $user, array
441441
442442 private function getRarestAchievement (array $ gameIds , User $ user , Carbon $ startDate , Carbon $ endDate ): array
443443 {
444- $ result = [
445- 'rarestHardcoreAchievement ' => null ,
446- 'rarestHardcoreAchievementEarnRate ' => 0.0 ,
447- 'rarestSoftcoreAchievement ' => null ,
448- 'rarestSoftcoreAchievementEarnRate ' => 0.0 ,
449- ];
450-
451- $ rarestHardcoreAchievement = PlayerAchievement::where (DB ::raw ('player_achievements.user_id ' ), $ user ->id )
452- ->where ('unlocked_hardcore_at ' , '>= ' , $ startDate )
453- ->where ('unlocked_hardcore_at ' , '< ' , $ endDate )
454- ->join ('achievements ' , 'achievements.id ' , '= ' , 'player_achievements.achievement_id ' )
455- ->join ('games ' , 'games.id ' , '= ' , 'achievements.game_id ' )
456- ->whereIn ('achievements.game_id ' , $ gameIds )
457- ->where (DB ::raw ('achievements.is_promoted ' ), true )
458- ->select ('achievements.id ' , DB ::raw ('achievements.unlocks_hardcore/games.players_total as EarnRate ' ))
459- ->orderBy ('EarnRate ' )
460- ->first ();
461- if ($ rarestHardcoreAchievement ) {
462- $ result ['rarestHardcoreAchievement ' ] = Achievement::find ($ rarestHardcoreAchievement ->id );
463- $ result ['rarestHardcoreAchievementEarnRate ' ] = sprintf ("%01.2f " , $ rarestHardcoreAchievement ->EarnRate * 100 );
444+ $ rarestHardcoreAchievement = null ;
445+ if ($ user ->points_hardcore > 0 ) {
446+ $ rarestHardcoreAchievement = PlayerAchievement::where (DB ::raw ('player_achievements.user_id ' ), $ user ->id )
447+ ->where ('unlocked_hardcore_at ' , '>= ' , $ startDate )
448+ ->where ('unlocked_hardcore_at ' , '< ' , $ endDate )
449+ ->join ('achievements ' , 'achievements.id ' , '= ' , 'player_achievements.achievement_id ' )
450+ ->join ('games ' , 'games.id ' , '= ' , 'achievements.game_id ' )
451+ ->whereIn ('achievements.game_id ' , $ gameIds )
452+ ->where (DB ::raw ('achievements.is_promoted ' ), true )
453+ ->select ('achievements.id ' , DB ::raw ('achievements.unlocks_hardcore/games.players_total as EarnRate ' ))
454+ ->orderBy ('EarnRate ' )
455+ ->first ();
456+ }
464457
465- return $ result ; // only report rarest hardcore achievement if one was found
458+ $ rarestSoftcoreAchievement = null ;
459+ if ($ user ->points > 0 ) {
460+ $ rarestSoftcoreAchievement = PlayerAchievement::where (DB ::raw ('player_achievements.user_id ' ), $ user ->id )
461+ ->where ('unlocked_at ' , '>= ' , $ startDate )
462+ ->where ('unlocked_at ' , '< ' , $ endDate )
463+ ->join ('achievements ' , 'achievements.id ' , '= ' , 'player_achievements.achievement_id ' )
464+ ->join ('games ' , 'games.id ' , '= ' , 'achievements.game_id ' )
465+ ->whereIn ('achievements.game_id ' , $ gameIds )
466+ ->where (DB ::raw ('achievements.is_promoted ' ), true )
467+ ->select ('achievements.id ' , DB ::raw ('achievements.unlocks_total/games.players_total as EarnRate ' ))
468+ ->orderBy ('EarnRate ' )
469+ ->first ();
466470 }
467471
468- $ rarestSoftcoreAchievement = PlayerAchievement::where (DB ::raw ('player_achievements.user_id ' ), $ user ->id )
469- ->where ('unlocked_at ' , '>= ' , $ startDate )
470- ->where ('unlocked_at ' , '< ' , $ endDate )
471- ->join ('achievements ' , 'achievements.id ' , '= ' , 'player_achievements.achievement_id ' )
472- ->join ('games ' , 'games.id ' , '= ' , 'achievements.game_id ' )
473- ->whereIn ('achievements.game_id ' , $ gameIds )
474- ->where (DB ::raw ('achievements.is_promoted ' ), true )
475- ->select ('achievements.id ' , DB ::raw ('achievements.unlocks_total/games.players_total as EarnRate ' ))
476- ->orderBy ('EarnRate ' )
477- ->first ();
478- if ($ rarestSoftcoreAchievement ) {
479- $ result ['rarestSoftcoreAchievement ' ] = Achievement::find ($ rarestSoftcoreAchievement ->id );
480- $ result ['rarestSoftcoreAchievementEarnRate ' ] = sprintf ("%01.2f " , $ rarestSoftcoreAchievement ->EarnRate * 100 );
472+ // only keep the most rare achievement (regardless of softcore vs hardcore)
473+ if ($ rarestHardcoreAchievement && $ rarestSoftcoreAchievement ) {
474+ if ($ rarestHardcoreAchievement ->EarnRate < $ rarestSoftcoreAchievement ->EarnRate ) {
475+ $ rarestSoftcoreAchievement = null ;
476+ } else {
477+ $ rarestHardcoreAchievement = null ;
478+ }
481479 }
482480
483- return $ result ;
481+ return [
482+ 'rarestHardcoreAchievement ' => $ rarestHardcoreAchievement ? Achievement::find ($ rarestHardcoreAchievement ->id ) : null ,
483+ 'rarestHardcoreAchievementEarnRate ' => $ rarestHardcoreAchievement ? sprintf ("%01.2f " , $ rarestHardcoreAchievement ->EarnRate * 100 ) : 0.0 ,
484+ 'rarestSoftcoreAchievement ' => $ rarestSoftcoreAchievement ? Achievement::find ($ rarestSoftcoreAchievement ->id ) : null ,
485+ 'rarestSoftcoreAchievementEarnRate ' => $ rarestSoftcoreAchievement ? sprintf ("%01.2f " , $ rarestSoftcoreAchievement ->EarnRate * 100 ) : 0.0 ,
486+ ];
484487 }
485488
486489 private function determineRarestSubsetAchievement (array &$ recapData , User $ user , array $ subsetGameIds , Carbon $ startDate , Carbon $ endDate ): void
0 commit comments