Projektdateien hinzufügen.
This commit is contained in:
parent
72ecb03642
commit
76fbb232a7
48 changed files with 3779 additions and 0 deletions
96
BusinessLogic/Table.cs
Normal file
96
BusinessLogic/Table.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
|
||||
namespace WebEMSim
|
||||
{
|
||||
public class Table
|
||||
{
|
||||
private List<Team> _teams;
|
||||
private Sorter _sorter = new Sorter();
|
||||
|
||||
public Dictionary<int, Team> Rankings { get => GetTable().Select((team, index) => new {team, index}).ToDictionary(x => x.index, x => x.team); }
|
||||
|
||||
public Table(List<Team> teams) {
|
||||
_teams = new(teams);
|
||||
}
|
||||
|
||||
public void AddTeam(Team team)
|
||||
{
|
||||
_teams.Add(team);
|
||||
}
|
||||
|
||||
public List<Team> GetTable()
|
||||
{
|
||||
_teams.Sort(_sorter);
|
||||
|
||||
return _teams;
|
||||
}
|
||||
|
||||
public List<Team> GetTruncatedTable(int cutoff)
|
||||
{
|
||||
List<Team> sortedTeams = new(GetTable());
|
||||
|
||||
sortedTeams.RemoveRange(cutoff, sortedTeams.Count - cutoff);
|
||||
|
||||
return sortedTeams;
|
||||
}
|
||||
|
||||
/*public DataTable AsDataTable()
|
||||
{
|
||||
DataTable dataTable = new DataTable();
|
||||
|
||||
dataTable.Clear();
|
||||
|
||||
dataTable.Columns.Add("Name");
|
||||
dataTable.Columns.Add("Wins");
|
||||
dataTable.Columns.Add("Losses");
|
||||
dataTable.Columns.Add("Draws");
|
||||
dataTable.Columns.Add("For");
|
||||
dataTable.Columns.Add("Against");
|
||||
dataTable.Columns.Add("Goal Diff");
|
||||
dataTable.Columns.Add("World Rank");
|
||||
dataTable.Columns.Add("Points");
|
||||
dataTable.Columns.Add("Group");
|
||||
|
||||
List<Team> teams = GetTable();
|
||||
|
||||
foreach (Team team in teams)
|
||||
{
|
||||
dataTable.Rows.Add([
|
||||
team.Name,
|
||||
team.Wins,
|
||||
team.Losses,
|
||||
team.Draws,
|
||||
team.For,
|
||||
team.Against,
|
||||
team.GoalDelta,
|
||||
team.WorldRank,
|
||||
team.Points,
|
||||
Helpers.NumberToLetter(team.Group)
|
||||
]);
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
private class Sorter : IComparer<Team>
|
||||
{
|
||||
public int Compare(Team? a, Team? b)
|
||||
{
|
||||
int rank = b.Points - a.Points;
|
||||
|
||||
if(rank == 0)
|
||||
{
|
||||
rank = b.GoalDelta - a.GoalDelta;
|
||||
}
|
||||
|
||||
if(rank == 0)
|
||||
{
|
||||
rank = b.For - a.For;
|
||||
}
|
||||
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue