public static PlayerModel From(Player player) { if (player == null) return null; var playerModel = new PlayerModel { Matricule = player.Matricule, Lastname = player.Lastname, Firstname = player.Firstname, Email = player.Email, Picture = player.Picture }; return playerModel; }
public async Task<Player> Get(string matricule) { Player joueur = await _playerStore.GetFromMatricule(matricule); if (joueur != null) return joueur; using (var activeDirectoryRepository = new ActiveDirectoryService()) { using (var user = activeDirectoryRepository.GetUser(matricule)) { if (user == null) //throw new IdentityNotMappedException(); joueur = new Player { Email = "*****@*****.**", Firstname = "Prénom", Lastname = "Nom", Matricule = matricule, Picture = null }; else { var picture = activeDirectoryRepository.GetUserPicture(matricule); joueur = new Player { Lastname = user.Surname, Firstname = user.GivenName, Email = user.EmailAddress, Matricule = matricule, Picture = picture }; } var sports = await _sportStore.Get(); joueur.Ranks = sports.Select(s => new Rank {Level = 1000, SportKey = s.Key}).ToList(); await _playerStore.Add(joueur); await _playerStore.SaveChangesAsync(); } } return joueur; }
private double CalculateElo(Player player, int level1, int level2, int score1, int score2, double poids, ResultatEnum result) { //résultat théorique double probability = VictoryProbability(level1 - level2); //résultat du match double w = 0; //poids selon le niveau du joueur et et le type de compétition double k = 10; //coeff selon la différence de but double g; //calcul du résultat switch (result) { case ResultatEnum.Defaite: w = 0; break; case ResultatEnum.Nul: w = 0.5; break; case ResultatEnum.Victoire: w = 1; break; } //calcul du poids if (player.Parties < 15) k = 25; else if (level1 < 2400) k = 15; k *= poids; //calcul du coeff int diff = Math.Abs(score1 - score2); switch (diff) { case 0: g = 1; break; case 1: g = 1; break; case 2: g = 1.5; break; case 3: g = 1.75; break; default: g = 1.75 + (diff - 3)*0.125; break; } return (k*g*(w - probability)); }
public async Task<Player> SetState(Player player, EntityState entityState) { _matchContext.Entry(player).State = entityState; return await Task.FromResult(player); }
public async Task<Player> Add(Player player) { _matchContext.Players.Add(player); return await Task.FromResult(player); }