I need to render a win loss chart based on player performance, I was hoping someone will have experience with similar calculations.
So here is what I have:
public class Player
{
public virtual bool IsWinner { get; set; }
}
//Sample list
var listOfPlayers = new List<Player>
{
new Player{ IsWinner = true },
new Player{ IsWinner = false },
new Player{ IsWinner = false },
new Player{ IsWinner = true },
new Player{ IsWinner = true },
new Player{ IsWinner = false },
new Player{ IsWinner = true }
};
The players list comes from Database and basically each player in the list belongs to a different match.
So I have this function where I am supplying the list of players and the respective index in the list:
So lets say for example that at index 2 I have one win and 2 losses, because I am rendering a chart I need this function to return a double that will represent the win/loss percentage so it will have (player won 25%of matches 0-3)
public double CalculateWinLossPercentage(List<Player> listOfPlayers,int index)
{
double winpercentage = null;
//calculate win percentage base on the total list of players
//and the current index in list
return winpercentage;
}
Thank you in advance for your help.
This will return the percentage as a double (number between 0 and 1).
Also, in your example, with index = 2, the correct result would be 33.3%, not 25%.