/// <summary> /// Creates the table with the basic information. /// </summary> /// <returns>The created table.</returns> public PdfPTable CreateBasicInfoTable() { PdfPTable table = new PdfPTable(12); float[] widths = new float[] { 2.3f, 2.0f, 0.6f, 0.6f, 0.6f, 0.6f, 0.6f, 1.3f, 2.2f, 2.0f, 2.0f, 2.0f }; Rectangle rect = new Rectangle(17, 1); table.SetWidthPercentage(widths, rect); BasicInformation playerAInfo = this.report.BasicInformations.First(); BasicInformation playerBInfo = this.report.BasicInformations.Last(); //// Hdeaer row. PdfPCell cell1 = GetCell("Player", 1, 1, 1); cell1.MinimumHeight = 30.0f; table.AddCell(cell1); table.AddCell(GetCell("Ranking", 1, 1, 2)); table.AddCell(GetCell("Result\n(" + Convert.ToString(playerAInfo.WinningSets) + ":" + Convert.ToString(playerBInfo.WinningSets) + ")", 5, 1, 2)); table.AddCell(GetCell("Total\nPoints", 1, 1, 2)); table.AddCell(GetCell("Comp.\nPerf.", 1, 1, 2)); table.AddCell(GetCell("Win.\nProb.", 1, 1, 2)); table.AddCell(GetCell("Service\nFrequency", 1, 1, 2)); table.AddCell(GetCell("Service\nWin.Prob.", 1, 1, 3)); List <int> resultsA = playerAInfo.Results; //// Inner middle row. PdfPCell cell2 = GetCell(playerAInfo.Name, 4); cell2.MinimumHeight = 20.0f; table.AddCell(cell2); table.AddCell(GetCell("Nan", 5)); //// results cells foreach (int res in resultsA) { table.AddCell(GetCell(Convert.ToString(res), 5)); } for (int i = resultsA.Count; i < 5; i++) { table.AddCell(GetCell(string.Empty, 5)); } table.AddCell(GetCell(Convert.ToString(playerAInfo.TotalPoints), 5)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerAInfo.CompetitionPerformance, 1)), 5)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerAInfo.WinningProbability * 100, 1)), 5)); table.AddCell(GetCell(Convert.ToString(playerAInfo.ServingFrequency), 5)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerAInfo.ServingWinningProbability * 100, 1)), 6)); List <int> resultsB = playerBInfo.Results; //// Inner middle row. PdfPCell cell3 = GetCell(playerBInfo.Name, 7); cell3.MinimumHeight = 20.0f; table.AddCell(cell3); table.AddCell(GetCell("Nan", 8)); //// results cells foreach (int res in resultsB) { table.AddCell(GetCell(Convert.ToString(res), 8)); } for (int i = resultsB.Count; i < 5; i++) { table.AddCell(GetCell(string.Empty, 8)); } table.AddCell(GetCell(Convert.ToString(playerBInfo.TotalPoints), 8)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerBInfo.CompetitionPerformance, 1)), 8)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerBInfo.WinningProbability * 100, 1)), 8)); table.AddCell(GetCell(Convert.ToString(playerAInfo.ServingFrequency), 8)); table.AddCell(GetCell(Convert.ToString(Math.Round(playerBInfo.ServingWinningProbability * 100, 1)), 9)); return(table); }
/// <summary> /// Creates the basic information of the match. /// </summary> /// <returns>The list of <see cref="BasicInformation"/>.</returns> private List <BasicInformation> CreateBasicInformations() { BasicInformation playerAInfo = new BasicInformation(); BasicInformation playerBInfo = new BasicInformation(); List <BasicInformation> infos = new List <BasicInformation>(); infos.Add(playerAInfo); infos.Add(playerBInfo); //// add the name playerAInfo.Name = this.Match.FirstPlayer.Name; playerBInfo.Name = this.Match.SecondPlayer.Name; int playerAServing = 0; int playerBServing = 0; int playerAWinningService = 0; int playerBWinningService = 0; foreach (Rally rally in this.match.Rallies) { if (rally.IsEndOfSet) { //// add the final score of each set to the results playerAInfo.Results.Add(rally.FinalRallyScore.First); playerBInfo.Results.Add(rally.FinalRallyScore.Second); //// add the points of each set to the total points. playerAInfo.TotalPoints += rally.FinalRallyScore.First; playerBInfo.TotalPoints += rally.FinalRallyScore.Second; //// increase the number of winning sets playerAInfo.WinningSets += rally.FinalRallyScore.First > rally.FinalRallyScore.Second ? 1 : 0; playerBInfo.WinningSets += rally.FinalRallyScore.First < rally.FinalRallyScore.Second ? 1 : 0; } playerAServing += rally.Server == MatchPlayer.First ? 1 : 0; playerBServing += rally.Server == MatchPlayer.Second ? 1 : 0; playerAWinningService += rally.Server == MatchPlayer.First && rally.Winner == MatchPlayer.First ? 1 : 0; playerBWinningService += rally.Server == MatchPlayer.Second && rally.Winner == MatchPlayer.Second ? 1 : 0; } //// if the last rally is not the end of a set, add all missing information. if (!this.match.Rallies.Last().IsEndOfSet) { int finalScoreFirst = this.match.Rallies.Last().FinalRallyScore.First; int finalScoreSecond = this.match.Rallies.Last().FinalRallyScore.Second; playerAInfo.Results.Add(finalScoreFirst); playerBInfo.Results.Add(finalScoreSecond); playerAInfo.TotalPoints += this.match.Rallies.Last().FinalRallyScore.First; playerBInfo.TotalPoints += this.match.Rallies.Last().FinalRallyScore.Second; } //// compute the winning probability int totalPoints = playerAInfo.TotalPoints + playerBInfo.TotalPoints; playerAInfo.WinningProbability = (double)playerAInfo.TotalPoints / totalPoints; playerBInfo.WinningProbability = (double)playerBInfo.TotalPoints / totalPoints; //// compute the winning probability when the player is the serving player playerAInfo.ServingWinningProbability = playerAServing == 0 ? 0 : (double)playerAWinningService / (double)playerAServing; playerBInfo.ServingWinningProbability = playerBServing == 0 ? 0 : (double)playerBWinningService / (double)playerBServing; //// compute the competition performance //// =WENN(D2>E2;WENN(D2=11;D2-E2-11;-11+1/(D2-11));WENN(E2=11;D2-E2-11;-11-1/(E2-11))) //// valueA += WENN(pointsA>PointsB; //// WENN(PointsA=11; //// PointsA-PointsB-11; //// -11+1/(PointsA-11)); //// WENN(PointsB=11; //// PointsA-PointsB-11; //// -11-1/(PointsB-11))) //// //// =WENN(D2>E2;WENN(D2=11;E2-D2-11;-11-1/(D2-11));WENN(E2=11;E2-D2-11;-11+1/(E2-11))) //// valueB += WENN(PointsA>PointsB; //// WENN(PointsA=11; //// PointsB-PointsA-11; //// -11-1/(PointsA-11)); //// WENN(PointsB=11; //// PointsB-PointsA-11; //// -11+1/(PointsB-11))) double valueA = 0; double valueB = 0; for (var i = 0; i < playerAInfo.Results.Count(); i++) { var pointsA = playerAInfo.Results[i]; var pointsB = playerBInfo.Results[i]; if (pointsA > pointsB) { valueA += Math.Pow(pointsA == 11 ? pointsA - pointsB - 11 : -11 + (1 / (pointsA - 11)), 2); valueB += Math.Pow(pointsA == 11 ? pointsB - pointsA - 11 : -11 - (1 / (pointsA - 11)), 2); } else { valueA += Math.Pow(pointsB == 11 ? pointsA - pointsB - 11 : -11 - (1 / (pointsB - 11)), 2); valueB += Math.Pow(pointsB == 11 ? pointsB - pointsA - 11 : -11 + (1 / (pointsB - 11)), 2); } } playerAInfo.CompetitionPerformance = 22 - Math.Sqrt(valueA / playerAInfo.Results.Count()); playerBInfo.CompetitionPerformance = 22 - Math.Sqrt(valueB / playerBInfo.Results.Count()); return(infos); }