private void AdjustScore(Guid agentId, CompetitorResult result) { var scriptScore = _context.Stats .SingleOrDefault(s => s.ScriptId == agentId); if (scriptScore == null) { var newStats = new ScriptStatistics() { ScriptId = agentId, Wins = result.Result == CompetitionResult.Winner ? 1 : 0, GamesPlayed = 1, CumulativeScore = result.Score }; _context.Stats.Add(newStats); scriptScore = newStats; } else { scriptScore.GamesPlayed += 1; scriptScore.CumulativeScore += result.Score; if (result.Result == CompetitionResult.Winner) { scriptScore.Wins += 1; } } _context.Commit(); }
private static LeaderboardRow MapRow(ScriptStatistics statistics) { return(new() { Alias = statistics.Script.Name , Creator = statistics.Script.User.EmailAddress , Wins = statistics.Wins , GamesPlayed = statistics.GamesPlayed , WinRate = statistics.Wins / (double)statistics.GamesPlayed , Language = statistics.Script.ScriptType , ScriptId = statistics.Script.Id , CreatorId = statistics.Script.UserId }); }