public void BuildAchievementStatistic(int batchSize)
        {
            var games = _gameRetrieverService.ListGames();

            var achievements = _statisticsService.ListAchievements();
            var position     = _statisticsService.GetStatisticsPosition("Achievements");

            if (position == null)
            {
                position = _dbContext.GetContext().StatisticsPositions.Add(new StatisticsPosition
                {
                    StatisticsName  = "Achievements",
                    StatisticsValue = "0"
                }).Entity;
            }

            var gameAchievements = _dbContext.GetContext().PlayerSavedData.Skip(int.Parse(position.StatisticsValue)).Take(batchSize).ToList();

            var dataGroups = gameAchievements.GroupBy(a => a.DataValue);

            foreach (var group in dataGroups)
            {
                var foundGame = games.FirstOrDefault(a => a.Metadata.Achievements.Any(b => b.Name == group.Key));
                if (foundGame != null)
                {
                    var countedItems = group.Count();
                    var existingDbStatisticsEntry = achievements.FirstOrDefault(a => a.AchievementName == group.Key && foundGame.GameName == a.GameName);
                    if (existingDbStatisticsEntry == null)
                    {
                        _dbContext.GetContext().StatisticsGameAchievements.Add(new StatisticsGameAchievement
                        {
                            AchievementName = group.Key,
                            GameName        = foundGame.GameName,
                            TotalPlayed     = countedItems
                        });
                    }
                    else
                    {
                        existingDbStatisticsEntry.TotalPlayed = existingDbStatisticsEntry.TotalPlayed + countedItems;
                    }
                }
            }

            position.StatisticsValue = (int.Parse(position.StatisticsValue) + gameAchievements.Count).ToString();

            Console.WriteLine("Updated: " + gameAchievements.Count);

            _dbContext.GetContext().SaveChanges();
        }
示例#2
0
        public void DailyUsageReport()
        {
            var dayBehind          = DateTime.Now.Subtract(TimeSpan.FromDays(1));
            var playerActionsToday = _databaseProvider.GetContext().PlayerActions.Where(a => a.Time > dayBehind).Include(a => a.Player);

            _reporter.ReportMessage("#### This is your daily usage report! ####");
            _reporter.ReportMessage("There were a total of: " + playerActionsToday.Count() + " actions performed today");

            var playerActionsTodayResolved = playerActionsToday.ToList();

            _reporter.ReportMessage("#### Games ####");
            foreach (var group in playerActionsTodayResolved.GroupBy(a => a.GameName))
            {
                _reporter.ReportMessage(group.Count() + " of those actions were performed on the game: " + group.First().GameName);
            }

            _reporter.ReportMessage("#### Players ####");
            playerActionsTodayResolved.GroupBy(a => a.PlayerId).ToList().ForEach(a =>
            {
                _reporter.ReportMessage(a.Count() + " of those actions were performed by the player: " + a.First().Player.Name);
            });
            _reporter.ReportMessage("#### End of report! :) ####");
        }
 public AccountController(IDatabaseContextProvider contextProvider)
 {
     _context = contextProvider.GetContext();
 }
示例#4
0
 public DatabaseDataStore(IDatabaseContextProvider contextProvider)
 {
     _databaseContext = contextProvider.GetContext();
 }
 public Dictionary <string, int> CountActionsByGame(DateTime after, DateTime before)
 {
     return(_contextProvider.GetContext().PlayerActions.Where(a => a.Time > after && a.Time < before).ToList().GroupBy(a => a.GameName).ToDictionary(a => a.Key, a => a.Count()));
 }
示例#6
0
 public AccessTokenService(IDatabaseContextProvider contextProvider, ITokenGenerator tokenGenerator)
 {
     _context        = contextProvider.GetContext();
     _tokenGenerator = tokenGenerator;
 }
 public GameSaveService(IDatabaseContextProvider contextProvider)
 {
     _context = contextProvider.GetContext();
 }
 public List <StatisticsGameAchievement> ListAchievements()
 {
     return(_databaseContext.GetContext().StatisticsGameAchievements.ToList());
 }