예제 #1
0
        private IEnumerable <GameAward> AllMonthlyGameAwards(AllUserActivityCache allUserActivity)
        {
            var allUserActivityByMonth = allUserActivity.AllUserActivity
                                         .GroupBy(activity => MonthOfYear.Create(activity.AssignedToDate))
                                         .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var(month, activities) in allUserActivityByMonth)
            {
                var mostPlayedGameForMonth = activities
                                             .GroupBy(x => x.GameId, x => x.TimeSpentInSeconds, (gameId, activities) => new { GameId = gameId, TimeSpentInSeconds = activities.Sum() })
                                             .OrderBy(x => x.TimeSpentInSeconds)
                                             .Last();

                yield return(new GameAward
                {
                    GameAwardId = new Id <GameAward>($"MostPlayedGameOf{month.Month}-{month.Year}"),
                    GameId = mostPlayedGameForMonth.GameId,
                    GameAwardType = "MostPlayedGameOfMonth",
                    GameAwardTypeDetails = new { month.Month, month.Year, mostPlayedGameForMonth.TimeSpentInSeconds },
                });

                var longestActivity = activities.OrderBy(x => x.TimeSpentInSeconds).Last();
                yield return(new GameAward
                {
                    GameAwardId = new Id <GameAward>($"LongestActivityOf{month.Month}-{month.Year}"),
                    GameId = longestActivity.GameId,
                    GameAwardType = "LongestActivityOfMonth",
                    GameAwardTypeDetails = new { month.Month, month.Year, longestActivity.TimeSpentInSeconds, longestActivity.AssignedToDate },
                });
            }
        }
 public GameProfileController(
     IMemoryCache memoryCache,
     GameStore gameStore = null,
     GameProfileFactory gameProfileFactory     = null,
     AllUserActivityCache allUserActivityCache = null)
 {
     _gameStore            = gameStore ?? new GameStore();
     _gameProfileFactory   = gameProfileFactory ?? new GameProfileFactory();
     _allUserActivityCache = allUserActivityCache ?? new AllUserActivityCache(memoryCache);
 }
예제 #3
0
        public IReadOnlyList <GameAward> CalculateAllGameAwards(AllUserActivityCache allUserActivity)
        {
            if (!allUserActivity.AllUserActivity.Any())
            {
                return(Array.Empty <GameAward>());
            }

            return(Array.Empty <GameAward>()
                   .Union(AllOverallGameAwards(allUserActivity))
                   .Union(AllYearlyGameAwards(allUserActivity))
                   .Union(AllMonthlyGameAwards(allUserActivity))
                   .ToList());
        }
예제 #4
0
        public GameProfile Create(IGame game, AllUserActivityCache allUserActivity)
        {
            var orderedUserActivities = allUserActivity.AllUserActivity
                                        .Where(userActivity => userActivity.GameId == game.GameId)
                                        .OrderByDescending(x => x.EndTime)
                                        .ToList();

            return(new GameProfile
            {
                Game = game,
                AllActivity = orderedUserActivities,
                ActivitiesByDate = orderedUserActivities.GroupByDate(),
                MostRecent = orderedUserActivities.FirstOrDefault(),
                TotalUserActivityCount = orderedUserActivities.Count,
                MeanUserActivityTimePlayedInSeconds = orderedUserActivities.Average(x => x.TimeSpentInSeconds),
                TotalTimePlayedInSeconds = orderedUserActivities.Sum(x => x.TimeSpentInSeconds),
                TimeSpentInSecondsByHour = _timeSpentByHourCalculator.Calculate(orderedUserActivities).ToDictionary(x => x.Key.ToString(), x => x.Value),
                GameAwards = _gameAwardStore.CalculateAllGameAwards(allUserActivity).Where(x => x.GameId == game.GameId).ToList(),
            });
        }
예제 #5
0
        private IEnumerable <GameAward> AllOverallGameAwards(AllUserActivityCache allUserActivity)
        {
            var allActivityByGameId        = allUserActivity.AllUserActivity.GroupBy((activity) => activity.GameId).ToDictionary(x => x.Key, x => x.ToList());
            var daysPlayedByGameId         = allActivityByGameId.ToDictionary(x => x.Key, activities => activities.Value.Select(x => x.AssignedToDate).Distinct().Count());
            var mostConsistentlyPlayedGame = daysPlayedByGameId.OrderBy(x => x.Value).Last();

            yield return(new GameAward
            {
                GameAwardId = new Id <GameAward>("MostConsistentOverall"),
                GameId = mostConsistentlyPlayedGame.Key,
                GameAwardType = "MostConsistentOverall",
                GameAwardTypeDetails = new { TotalDaysPlayed = mostConsistentlyPlayedGame.Value },
            });

            var longestUserActivity = allUserActivity.AllUserActivity.OrderBy(x => x.TimeSpentInSeconds).Last();

            yield return(new GameAward
            {
                GameAwardId = new Id <GameAward>("LongestActivityOverall"),
                GameId = longestUserActivity.GameId,
                GameAwardType = "LongestActivityOverall",
                GameAwardTypeDetails = new { longestUserActivity.TimeSpentInSeconds, longestUserActivity.AssignedToDate },
            });
        }