public static double CalculateCurrentRD(TeamMatchPlayer lastMatchData, DateTime currentTimestamp) { double currentRD = (double) lastMatchData.RD; TimeSpan timeSpan = currentTimestamp - lastMatchData.Timestamp; double timeInSeconds = timeSpan.TotalSeconds; return Math.Min(MAX_RD, Math.Sqrt(currentRD * currentRD + MAGIC_C_CONSTANT * MAGIC_C_CONSTANT * timeInSeconds)); }
public static double CalculateCurrentRD(TeamMatchPlayer lastMatchData, DateTime currentTimestamp) { double currentRD = (double)lastMatchData.RD; TimeSpan timeSpan = currentTimestamp - lastMatchData.Timestamp; double timeInSeconds = timeSpan.TotalSeconds; return(Math.Min(MAX_RD, Math.Sqrt(currentRD * currentRD + MAGIC_C_CONSTANT * MAGIC_C_CONSTANT * timeInSeconds))); }
private static TeamMatchPlayer CreateEmptyMatchData() { TeamMatchPlayer matchData = new TeamMatchPlayer(); matchData.Rating = INITIAL_RATING; matchData.RD = MAX_RD; matchData.Timestamp = new DateTime(2012, 08, 23); return(matchData); }
private static void FillSinglePlayerRating( ref TeamMatchPlayer newMatchData, TeamMatchPlayer oldMatchData, TeamMatchPlayer allyMatchData, TeamMatchPlayer firstOppMatchData, TeamMatchPlayer secondOppMatchData, int ourGoals, int oppGoals) { // MAGIC goes here: http://www.glicko.net/glicko/glicko.pdf double result = SinusoidifyResult(CalculateResult(ourGoals, oppGoals)); double oppRating = SanitizeRating((double)(firstOppMatchData.Rating + secondOppMatchData.Rating - allyMatchData.Rating)); double oppRD = (double)(firstOppMatchData.RD + secondOppMatchData.RD + allyMatchData.RD) / 3; double oppRatingStability = 1 / Math.Sqrt(1 + 3 * MAGIC_Q_CONSTANT_SQUARED * oppRD * oppRD / PI_SQUARED); double expectedResult = 1 / (1 + Math.Pow(10, -oppRatingStability * ((double)oldMatchData.Rating - oppRating) / 400)); double dSqaured = 1 / (MAGIC_Q_CONSTANT_SQUARED * oppRatingStability * oppRatingStability * expectedResult * (1 - expectedResult)); double rdSquared = 1 / (1 / (double)(oldMatchData.RD * oldMatchData.RD) + 1 / dSqaured); double ratingDifference = MAGIC_Q_CONSTANT * rdSquared * oppRatingStability * (result - expectedResult); newMatchData.Rating = SanitizeRating((double)oldMatchData.Rating + ratingDifference); newMatchData.RD = SanitizeRD(Math.Sqrt(rdSquared)); }
public static bool FillPlayersRating( ref TeamMatchPlayer playerA1MatchData, ref TeamMatchPlayer playerA2MatchData, ref TeamMatchPlayer playerB1MatchData, ref TeamMatchPlayer playerB2MatchData, TeamMatchPlayer playerA1LastMatchData, TeamMatchPlayer playerA2LastMatchData, TeamMatchPlayer playerB1LastMatchData, TeamMatchPlayer playerB2LastMatchData, int goalsA, int goalsB) { if (playerA1LastMatchData == null) { playerA1LastMatchData = CreateEmptyMatchData(); } if (playerA2LastMatchData == null) { playerA2LastMatchData = CreateEmptyMatchData(); } if (playerB1LastMatchData == null) { playerB1LastMatchData = CreateEmptyMatchData(); } if (playerB2LastMatchData == null) { playerB2LastMatchData = CreateEmptyMatchData(); } playerA1LastMatchData.RD = CalculateCurrentRD(playerA1LastMatchData, playerA1MatchData.Timestamp); playerA2LastMatchData.RD = CalculateCurrentRD(playerA2LastMatchData, playerA2MatchData.Timestamp); playerB1LastMatchData.RD = CalculateCurrentRD(playerB1LastMatchData, playerB1MatchData.Timestamp); playerB2LastMatchData.RD = CalculateCurrentRD(playerB2LastMatchData, playerB2MatchData.Timestamp); FillSinglePlayerRating(ref playerA1MatchData, playerA1LastMatchData, playerA2LastMatchData, playerB1LastMatchData, playerB2LastMatchData, goalsA, goalsB); FillSinglePlayerRating(ref playerA2MatchData, playerA2LastMatchData, playerA1LastMatchData, playerB1LastMatchData, playerB2LastMatchData, goalsA, goalsB); FillSinglePlayerRating(ref playerB1MatchData, playerB1LastMatchData, playerB2LastMatchData, playerA1LastMatchData, playerA2LastMatchData, goalsB, goalsA); FillSinglePlayerRating(ref playerB2MatchData, playerB2LastMatchData, playerB1LastMatchData, playerA1LastMatchData, playerA2LastMatchData, goalsB, goalsA); return(true); }
public static bool FillPlayersRating( ref TeamMatchPlayer playerA1MatchData, ref TeamMatchPlayer playerA2MatchData, ref TeamMatchPlayer playerB1MatchData, ref TeamMatchPlayer playerB2MatchData, TeamMatchPlayer playerA1LastMatchData, TeamMatchPlayer playerA2LastMatchData, TeamMatchPlayer playerB1LastMatchData, TeamMatchPlayer playerB2LastMatchData, int goalsA, int goalsB) { if (playerA1LastMatchData == null) { playerA1LastMatchData = CreateEmptyMatchData(); } if (playerA2LastMatchData == null) { playerA2LastMatchData = CreateEmptyMatchData(); } if (playerB1LastMatchData == null) { playerB1LastMatchData = CreateEmptyMatchData(); } if (playerB2LastMatchData == null) { playerB2LastMatchData = CreateEmptyMatchData(); } playerA1LastMatchData.RD = CalculateCurrentRD(playerA1LastMatchData, playerA1MatchData.Timestamp); playerA2LastMatchData.RD = CalculateCurrentRD(playerA2LastMatchData, playerA2MatchData.Timestamp); playerB1LastMatchData.RD = CalculateCurrentRD(playerB1LastMatchData, playerB1MatchData.Timestamp); playerB2LastMatchData.RD = CalculateCurrentRD(playerB2LastMatchData, playerB2MatchData.Timestamp); FillSinglePlayerRating(ref playerA1MatchData, playerA1LastMatchData, playerA2LastMatchData, playerB1LastMatchData, playerB2LastMatchData, goalsA, goalsB); FillSinglePlayerRating(ref playerA2MatchData, playerA2LastMatchData, playerA1LastMatchData, playerB1LastMatchData, playerB2LastMatchData, goalsA, goalsB); FillSinglePlayerRating(ref playerB1MatchData, playerB1LastMatchData, playerB2LastMatchData, playerA1LastMatchData, playerA2LastMatchData, goalsB, goalsA); FillSinglePlayerRating(ref playerB2MatchData, playerB2LastMatchData, playerB1LastMatchData, playerA1LastMatchData, playerA2LastMatchData, goalsB, goalsA); return true; }
private void BindPartnersStats() { pnlPartnerStats.Controls.Clear(); Player player = ((Player)Session["UserBasicStatsPlayer"]); if (player == null) { return; } using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext()) { List <TeamMatch> playerMatches = context.TeamMatches.Where(p => p.TeamMatchPlayers.Any(x => x.PlayerId == player.Id)).ToList(); StringBuilder sb = new StringBuilder(); List <TeamMatch> lastGames = playerMatches.OrderByDescending(p => p.Timestamp).ToList(); if (lastGames.Any()) { TeamMatchPlayer playerData = lastGames.First().TeamMatchPlayers.First(p => p.PlayerId == player.Id); var partnerGames = playerMatches .GroupBy(p => new { Partner = p.TeamMatchPlayers.First(x => x.PlayerId != playerData.PlayerId).Player }) .Select(x => new { //Partner = x.Key.Partner, Name = PlayerHelper.GetPlayerNameLink(x.Key.Partner), Games = x.Count(), Won = x.Count(z => z.Result == (byte)Common.EResult.Win), Drawn = x.Count(z => z.Result == (byte)Common.EResult.Draw), Lost = x.Count(z => z.Result == (byte)Common.EResult.Loose), Aggregate = x.Count(z => z.Result == (byte)Common.EResult.Win) - x.Count(z => z.Result == (byte)Common.EResult.Loose), AvgAggregatePerc = 100 * (x.Count(z => z.Result == (byte)Common.EResult.Win)) / (x.Count() == 0 ? 1 : x.Count()), AvgGoalsScored = x.Average(z => z.GoalsScored), AvgGoalsLost = x.Average(z => z.GoalsLost) }) .OrderByDescending(p => p.AvgAggregatePerc); gvPartners.DataSource = partnerGames; gvPartners.DataBind(); sb.AppendLine(string.Format("Najczęstrzy partner: {0} ({1})", partnerGames.OrderByDescending(p => p.Games).First().Name, partnerGames.OrderByDescending(p => p.Games).First().Games)); sb.AppendLine(string.Format("Najlepszy bilans: {0} ({1})", partnerGames.OrderByDescending(p => p.Aggregate).First().Name, partnerGames.OrderByDescending(p => p.Aggregate).First().Aggregate < 0 ? (partnerGames.OrderByDescending(p => p.Aggregate).First().Aggregate).ToString() : ("+" + partnerGames.OrderByDescending(p => p.Aggregate).First().Aggregate))); sb.AppendLine(string.Format("Najgorszy bilans: {0} ({1})", partnerGames.OrderBy(p => p.Aggregate).First().Name, partnerGames.OrderBy(p => p.Aggregate).First().Aggregate < 0 ? (partnerGames.OrderBy(p => p.Aggregate).First().Aggregate).ToString() : ("+" + partnerGames.OrderBy(p => p.Aggregate).First().Aggregate))); sb.AppendLine(string.Format("Największy % wygranych: {0} ({1}%)", partnerGames.OrderByDescending(p => p.AvgAggregatePerc).First().Name, partnerGames.OrderByDescending(p => p.AvgAggregatePerc).First().AvgAggregatePerc)); sb.AppendLine(string.Format("Najmniejszy % wygranych: {0} ({1}%)", partnerGames.OrderBy(p => p.AvgAggregatePerc).First().Name, partnerGames.OrderBy(p => p.AvgAggregatePerc).First().AvgAggregatePerc)); sb.AppendLine(string.Format("Najwięcej goli zdobytych/mecz: {0} ({1})", partnerGames.OrderByDescending(p => p.AvgGoalsScored).First().Name, partnerGames.OrderByDescending(p => p.AvgGoalsScored).First().AvgGoalsScored.ToString("N2"))); sb.AppendLine(string.Format("Najmniej goli zdobytych/mecz: {0} ({1})", partnerGames.OrderBy(p => p.AvgGoalsScored).First().Name, partnerGames.OrderBy(p => p.AvgGoalsScored).First().AvgGoalsScored.ToString("N2"))); sb.AppendLine(string.Format("Najwięcej goli straconych/mecz: {0} ({1})", partnerGames.OrderByDescending(p => p.AvgGoalsLost).First().Name, partnerGames.OrderByDescending(p => p.AvgGoalsLost).First().AvgGoalsLost.ToString("N2"))); sb.AppendLine(string.Format("Najmniej goli straconych/mecz: {0} ({1})", partnerGames.OrderBy(p => p.AvgGoalsLost).First().Name, partnerGames.OrderBy(p => p.AvgGoalsLost).First().AvgGoalsLost.ToString("N2"))); } sb = sb.Replace(Environment.NewLine, "<br/>"); pnlPartnerStats.Controls.Add(new LiteralControl(sb.ToString())); } }
protected void btnSubmit_Click(object sender, EventArgs e) { litAchievements.Text = ""; List<Player> players = DataAccess.GetPlayers(); int g1 = int.Parse(tbxScoreA.Text); int g2 = int.Parse(tbxScoreB.Text); Common.EResult t1Result = Common.GetResult(g1, g2); Common.EResult t2Result = Common.GetResult(g2, g1); Match match = new Match() { Id = Guid.NewGuid(), Timestamp = DateTime.Now }; TeamMatch tm1 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id, Result = (byte)t1Result, GoalsScored = g1, GoalsLost = g2, Timestamp = DateTime.Now }; TeamMatch tm2 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id, Result = (byte)t2Result, GoalsScored = g2, GoalsLost = g1, Timestamp = DateTime.Now }; Player p1Off = DataAccess.GetPlayer(tbxPlayer1Off.Text); Player p1Def = DataAccess.GetPlayer(tbxPlayer1Deff.Text); Player p2Off = DataAccess.GetPlayer(tbxPlayer2Off.Text); Player p2Def = DataAccess.GetPlayer(tbxPlayer2Deff.Text); List<Player> playersInThisGame = new List<Player>() { p1Off, p1Def, p2Off, p2Def }; TeamMatchPlayer tmp1Off = new TeamMatchPlayer() { PlayerId = p1Off.Id, Position = (int)Common.EPosition.Offence, Timestamp = DateTime.Now, TeamMatchId = tm1.Id }; TeamMatchPlayer tmp1Def = new TeamMatchPlayer() { PlayerId = p1Def.Id, Position = (int)Common.EPosition.Defence, Timestamp = DateTime.Now, TeamMatchId = tm1.Id }; TeamMatchPlayer tmp2Off = new TeamMatchPlayer() { PlayerId = p2Off.Id, Position = (int)Common.EPosition.Offence, Timestamp = DateTime.Now, TeamMatchId = tm2.Id }; TeamMatchPlayer tmp2Def = new TeamMatchPlayer() { PlayerId = p2Def.Id, Position = (int)Common.EPosition.Defence, Timestamp = DateTime.Now, TeamMatchId = tm2.Id }; double? player1OffPreRating, player1DefPreRating, player2OffPreRating, player2DefPreRating; double? player1OffPreRankPosition = null; double? player1DefPreRankPosition = null; double? player2OffPreRankPosition = null; double? player2DefPreRankPosition = null; int? player1OffPostRankPosition, player1DefPostRankPosition, player2OffPostRankPosition, player2DefPostRankPosition; using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext()) { var player1Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Off.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player1Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Def.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player2Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Off.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player2Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Def.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); if (player1Off != null) { player1OffPreRating = player1Off.Rating; player1OffPreRankPosition = context.GetPlayerRankPosition(player1Off.PlayerId); } else { player1OffPreRating = PlayerHelper.INITIAL_RATING; player1OffPreRankPosition = null; } if (player1Def != null) { player1DefPreRating = player1Def.Rating; player1DefPreRankPosition = context.GetPlayerRankPosition(player1Def.PlayerId); } else { player1DefPreRating = PlayerHelper.INITIAL_RATING; player1DefPreRankPosition = null; } if (player2Off != null) { player2OffPreRating = player2Off.Rating; player2OffPreRankPosition = context.GetPlayerRankPosition(player2Off.PlayerId); } else { player2OffPreRating = PlayerHelper.INITIAL_RATING; player2OffPreRankPosition = null; } if (player2Def != null) { player2DefPreRating = player2Def.Rating; player2DefPreRankPosition = context.GetPlayerRankPosition(player2Def.PlayerId); } else { player2DefPreRating = PlayerHelper.INITIAL_RATING; player2DefPreRankPosition = null; } PlayerHelper.FillPlayersRating(ref tmp1Off, ref tmp1Def, ref tmp2Off, ref tmp2Def, player1Off, player1Def, player2Off, player2Def, g1, g2); context.Matches.InsertOnSubmit(match); context.TeamMatches.InsertOnSubmit(tm1); context.TeamMatches.InsertOnSubmit(tm2); context.TeamMatchPlayers.InsertOnSubmit(tmp1Def); context.TeamMatchPlayers.InsertOnSubmit(tmp2Def); context.TeamMatchPlayers.InsertOnSubmit(tmp1Off); context.TeamMatchPlayers.InsertOnSubmit(tmp2Off); context.SubmitChanges(); player1OffPostRankPosition = context.GetPlayerRankPosition(tmp1Off.PlayerId); player1DefPostRankPosition = context.GetPlayerRankPosition(tmp1Def.PlayerId); player2OffPostRankPosition = context.GetPlayerRankPosition(tmp2Off.PlayerId); player2DefPostRankPosition = context.GetPlayerRankPosition(tmp2Def.PlayerId); } double player1OffRatingChange = Math.Round((double)(tmp1Off.Rating - player1OffPreRating),0); double player1DefRatingChange = Math.Round((double)(tmp1Def.Rating - player1DefPreRating),0); double player2OffRatingChange = Math.Round((double)(tmp2Off.Rating - player2OffPreRating),0); double player2DefRatingChange = Math.Round((double)(tmp2Def.Rating - player2DefPreRating),0); int player1OffRankPositionChange = player1OffPreRankPosition.HasValue ? (int)(player1OffPreRankPosition - player1OffPostRankPosition) : -1; int player1DefRankPositionChange = player1DefPreRankPosition.HasValue ? (int)(player1DefPreRankPosition - player1DefPostRankPosition) : -1; int player2OffRankPositionChange = player2OffPreRankPosition.HasValue ? (int)(player2OffPreRankPosition - player2OffPostRankPosition) : -1; int player2DefRankPositionChange = player2DefPreRankPosition.HasValue ? (int)(player2DefPreRankPosition - player2DefPostRankPosition) : -1; litTbxPlayer1OffStats.Text = string.Format(PostSubmittedStats, player1OffPostRankPosition, GetColouredRankPosition(player1OffRankPositionChange), Math.Round((double)tmp1Off.Rating, 0), GetColouredRating(player1OffRatingChange)); litTbxPlayer1DeffStats.Text = string.Format(PostSubmittedStats, player1DefPostRankPosition, GetColouredRankPosition(player1DefRankPositionChange), Math.Round((double)tmp1Def.Rating, 0), GetColouredRating(player1DefRatingChange)); litTbxPlayer2OffStats.Text = string.Format(PostSubmittedStats, player2OffPostRankPosition, GetColouredRankPosition(player2OffRankPositionChange), Math.Round((double)tmp2Off.Rating, 0), GetColouredRating(player2OffRatingChange)); litTbxPlayer2DeffStats.Text = string.Format(PostSubmittedStats, player2DefPostRankPosition, GetColouredRankPosition(player2DefRankPositionChange), Math.Round((double)tmp2Def.Rating, 0), GetColouredRating(player2DefRatingChange)); pnlInfo.Controls.Add(new LiteralControl("Mecz został zapisany")); tbxScoreA.Text = tbxScoreB.Text = ""; tbxPlayer1Off.Focus(); CalculateAchievements(playersInThisGame); Cache.Remove(DataAccess.OverallStatsCacheName); }
private void detach_TeamMatchPlayers(TeamMatchPlayer entity) { this.SendPropertyChanging(); entity.Player = null; }
partial void DeleteTeamMatchPlayer(TeamMatchPlayer instance);
private static void FillSinglePlayerRating( ref TeamMatchPlayer newMatchData, TeamMatchPlayer oldMatchData, TeamMatchPlayer allyMatchData, TeamMatchPlayer firstOppMatchData, TeamMatchPlayer secondOppMatchData, int ourGoals, int oppGoals) { // MAGIC goes here: http://www.glicko.net/glicko/glicko.pdf double result = SinusoidifyResult(CalculateResult(ourGoals, oppGoals)); double oppRating = SanitizeRating((double) (firstOppMatchData.Rating + secondOppMatchData.Rating - allyMatchData.Rating)); double oppRD = (double) (firstOppMatchData.RD + secondOppMatchData.RD + allyMatchData.RD) / 3; double oppRatingStability = 1 / Math.Sqrt(1 + 3 * MAGIC_Q_CONSTANT_SQUARED * oppRD * oppRD / PI_SQUARED); double expectedResult = 1 / (1 + Math.Pow(10, -oppRatingStability * ((double) oldMatchData.Rating - oppRating) / 400)); double dSqaured = 1 / (MAGIC_Q_CONSTANT_SQUARED * oppRatingStability * oppRatingStability * expectedResult * (1 - expectedResult)); double rdSquared = 1 / (1 / (double) (oldMatchData.RD * oldMatchData.RD) + 1 / dSqaured); double ratingDifference = MAGIC_Q_CONSTANT * rdSquared * oppRatingStability * (result - expectedResult); newMatchData.Rating = SanitizeRating((double) oldMatchData.Rating + ratingDifference); newMatchData.RD = SanitizeRD(Math.Sqrt(rdSquared)); }
partial void InsertTeamMatchPlayer(TeamMatchPlayer instance);
protected void btnSubmit_Click(object sender, EventArgs e) { litAchievements.Text = ""; List <Player> players = DataAccess.GetPlayers(); int g1 = int.Parse(tbxScoreA.Text); int g2 = int.Parse(tbxScoreB.Text); Common.EResult t1Result = Common.GetResult(g1, g2); Common.EResult t2Result = Common.GetResult(g2, g1); Match match = new Match() { Id = Guid.NewGuid(), Timestamp = DateTime.Now }; TeamMatch tm1 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id, Result = (byte)t1Result, GoalsScored = g1, GoalsLost = g2, Timestamp = DateTime.Now }; TeamMatch tm2 = new TeamMatch() { Id = Guid.NewGuid(), MatchId = match.Id, Result = (byte)t2Result, GoalsScored = g2, GoalsLost = g1, Timestamp = DateTime.Now }; Player p1Off = DataAccess.GetPlayer(tbxPlayer1Off.Text); Player p1Def = DataAccess.GetPlayer(tbxPlayer1Deff.Text); Player p2Off = DataAccess.GetPlayer(tbxPlayer2Off.Text); Player p2Def = DataAccess.GetPlayer(tbxPlayer2Deff.Text); List <Player> playersInThisGame = new List <Player>() { p1Off, p1Def, p2Off, p2Def }; TeamMatchPlayer tmp1Off = new TeamMatchPlayer() { PlayerId = p1Off.Id, Position = (int)Common.EPosition.Offence, Timestamp = DateTime.Now, TeamMatchId = tm1.Id }; TeamMatchPlayer tmp1Def = new TeamMatchPlayer() { PlayerId = p1Def.Id, Position = (int)Common.EPosition.Defence, Timestamp = DateTime.Now, TeamMatchId = tm1.Id }; TeamMatchPlayer tmp2Off = new TeamMatchPlayer() { PlayerId = p2Off.Id, Position = (int)Common.EPosition.Offence, Timestamp = DateTime.Now, TeamMatchId = tm2.Id }; TeamMatchPlayer tmp2Def = new TeamMatchPlayer() { PlayerId = p2Def.Id, Position = (int)Common.EPosition.Defence, Timestamp = DateTime.Now, TeamMatchId = tm2.Id }; double?player1OffPreRating, player1DefPreRating, player2OffPreRating, player2DefPreRating; double?player1OffPreRankPosition = null; double?player1DefPreRankPosition = null; double?player2OffPreRankPosition = null; double?player2DefPreRankPosition = null; int? player1OffPostRankPosition, player1DefPostRankPosition, player2OffPostRankPosition, player2DefPostRankPosition; using (TrambambuleDBContextDataContext context = new TrambambuleDBContextDataContext()) { var player1Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Off.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player1Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp1Def.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player2Off = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Off.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); var player2Def = context.TeamMatchPlayers.Where(p => p.PlayerId == tmp2Def.PlayerId) .OrderByDescending(p => p.Timestamp).FirstOrDefault(); if (player1Off != null) { player1OffPreRating = player1Off.Rating; player1OffPreRankPosition = context.GetPlayerRankPosition(player1Off.PlayerId); } else { player1OffPreRating = PlayerHelper.INITIAL_RATING; player1OffPreRankPosition = null; } if (player1Def != null) { player1DefPreRating = player1Def.Rating; player1DefPreRankPosition = context.GetPlayerRankPosition(player1Def.PlayerId); } else { player1DefPreRating = PlayerHelper.INITIAL_RATING; player1DefPreRankPosition = null; } if (player2Off != null) { player2OffPreRating = player2Off.Rating; player2OffPreRankPosition = context.GetPlayerRankPosition(player2Off.PlayerId); } else { player2OffPreRating = PlayerHelper.INITIAL_RATING; player2OffPreRankPosition = null; } if (player2Def != null) { player2DefPreRating = player2Def.Rating; player2DefPreRankPosition = context.GetPlayerRankPosition(player2Def.PlayerId); } else { player2DefPreRating = PlayerHelper.INITIAL_RATING; player2DefPreRankPosition = null; } PlayerHelper.FillPlayersRating(ref tmp1Off, ref tmp1Def, ref tmp2Off, ref tmp2Def, player1Off, player1Def, player2Off, player2Def, g1, g2); context.Matches.InsertOnSubmit(match); context.TeamMatches.InsertOnSubmit(tm1); context.TeamMatches.InsertOnSubmit(tm2); context.TeamMatchPlayers.InsertOnSubmit(tmp1Def); context.TeamMatchPlayers.InsertOnSubmit(tmp2Def); context.TeamMatchPlayers.InsertOnSubmit(tmp1Off); context.TeamMatchPlayers.InsertOnSubmit(tmp2Off); context.SubmitChanges(); player1OffPostRankPosition = context.GetPlayerRankPosition(tmp1Off.PlayerId); player1DefPostRankPosition = context.GetPlayerRankPosition(tmp1Def.PlayerId); player2OffPostRankPosition = context.GetPlayerRankPosition(tmp2Off.PlayerId); player2DefPostRankPosition = context.GetPlayerRankPosition(tmp2Def.PlayerId); } double player1OffRatingChange = Math.Round((double)(tmp1Off.Rating - player1OffPreRating), 0); double player1DefRatingChange = Math.Round((double)(tmp1Def.Rating - player1DefPreRating), 0); double player2OffRatingChange = Math.Round((double)(tmp2Off.Rating - player2OffPreRating), 0); double player2DefRatingChange = Math.Round((double)(tmp2Def.Rating - player2DefPreRating), 0); int player1OffRankPositionChange = player1OffPreRankPosition.HasValue ? (int)(player1OffPreRankPosition - player1OffPostRankPosition) : -1; int player1DefRankPositionChange = player1DefPreRankPosition.HasValue ? (int)(player1DefPreRankPosition - player1DefPostRankPosition) : -1; int player2OffRankPositionChange = player2OffPreRankPosition.HasValue ? (int)(player2OffPreRankPosition - player2OffPostRankPosition) : -1; int player2DefRankPositionChange = player2DefPreRankPosition.HasValue ? (int)(player2DefPreRankPosition - player2DefPostRankPosition) : -1; litTbxPlayer1OffStats.Text = string.Format(PostSubmittedStats, player1OffPostRankPosition, GetColouredRankPosition(player1OffRankPositionChange), Math.Round((double)tmp1Off.Rating, 0), GetColouredRating(player1OffRatingChange)); litTbxPlayer1DeffStats.Text = string.Format(PostSubmittedStats, player1DefPostRankPosition, GetColouredRankPosition(player1DefRankPositionChange), Math.Round((double)tmp1Def.Rating, 0), GetColouredRating(player1DefRatingChange)); litTbxPlayer2OffStats.Text = string.Format(PostSubmittedStats, player2OffPostRankPosition, GetColouredRankPosition(player2OffRankPositionChange), Math.Round((double)tmp2Off.Rating, 0), GetColouredRating(player2OffRatingChange)); litTbxPlayer2DeffStats.Text = string.Format(PostSubmittedStats, player2DefPostRankPosition, GetColouredRankPosition(player2DefRankPositionChange), Math.Round((double)tmp2Def.Rating, 0), GetColouredRating(player2DefRatingChange)); pnlInfo.Controls.Add(new LiteralControl("Mecz został zapisany")); tbxScoreA.Text = tbxScoreB.Text = ""; tbxPlayer1Off.Focus(); CalculateAchievements(playersInThisGame); Cache.Remove(DataAccess.OverallStatsCacheName); }
private void attach_TeamMatchPlayers(TeamMatchPlayer entity) { this.SendPropertyChanging(); entity.TeamMatch = this; }
partial void UpdateTeamMatchPlayer(TeamMatchPlayer instance);
private static TeamMatchPlayer CreateEmptyMatchData() { TeamMatchPlayer matchData = new TeamMatchPlayer(); matchData.Rating = INITIAL_RATING; matchData.RD = MAX_RD; matchData.Timestamp = new DateTime(2012, 08, 23); return matchData; }