public void BasicCriteria3() { // Tames gameswon sorter var table = new TeamDayResult[] { new TeamDayResult(2, 1, 0, 0, 4, 0, 4, 6) { IdStage = 1, IdTeam = 1 }, new TeamDayResult(2, 3, 0, 0, 4, 0, 4, 6) { IdStage = 1, IdTeam = 2 }, new TeamDayResult(2, 2, 0, 0, 4, 0, 4, 6) { IdStage = 1, IdTeam = 3 }, }; var classification = LeagueClassification.SortClassification(table, new int[] { 0, 1, 2 }); var c = classification.ToArray(); Assert.AreEqual(2, c[0].IdTeam); Assert.AreEqual(3, c[1].IdTeam); Assert.AreEqual(1, c[2].IdTeam); }
private IEnumerable <TeamDayResult> GetLeagueClassification(IDbConnection c, IDbTransaction t, TournamentStage stage, int daySequenceNumber) { var sql = @" SELECT tg.idGroup, t.id as idTeam, -1 as idDay, COALESCE(sum(gamesplayed), 0) as gamesplayed, COALESCE(sum(gameswon), 0) as gameswon, COALESCE(sum(gamesdraw), 0) as gamesdraw, COALESCE(sum(gameslost), 0) as gameslost, COALESCE(sum(points), 0) as points, COALESCE(sum(pointsAgainst), 0) as pointsAgainst, COALESCE(sum(pointdiff), 0) as pointdiff, COALESCE(sum(sanctions), 0) as sanctions, COALESCE(sum(tournamentpoints), 0) as tournamentpoints FROM teams t JOIN teamgroups tg ON tg.idteam = t.id AND tg.idstage = @idStage LEFT JOIN teamdayresults td ON td.idteam = t.id AND td.idStage = @idStage GROUP BY tg.idGroup, t.id, t.name ORDER BY tournamentpoints DESC, pointdiff DESC, gameswon DESC; "; var result = c.Query <TeamDayResult>(sql, new { idStage = stage.Id }, t); if (!string.IsNullOrWhiteSpace(stage.ClassificationCriteria)) { MatchFilter matchFilter = null; var criteria = JsonConvert.DeserializeObject <int[]>(stage.ClassificationCriteria); result = LeagueClassification.SortClassification(result, criteria, (teamA, teamB) => { if (matchFilter == null) { var matches = c.Query <Match>("SELECT idhometeam, idvisitorteam, homescore, visitorscore FROM matches WHERE idStage = @idStage", new { idStage = stage.Id }, t); if (matches == null) { throw new Exception("Error.NoMatches"); } matchFilter = new MatchFilter(matches.ToList()); } return(matchFilter.GetMatchesForTeams(teamA, teamB)); }); } return(result); }
public void DirectConfrontation1Match() { var matches = new Match[] { new Match { IdHomeTeam = 1, IdVisitorTeam = 2, HomeScore = 30, VisitorScore = 1 }, new Match { IdHomeTeam = 3, IdVisitorTeam = 2, HomeScore = 20, VisitorScore = 0 }, new Match { IdHomeTeam = 1, IdVisitorTeam = 3, HomeScore = 1, VisitorScore = 47 }, }; var table = new TeamDayResult[] { new TeamDayResult(2, 0, 0, 0, 0, 0, 0, 6) { IdStage = 1, IdTeam = 1 }, new TeamDayResult(2, 0, 0, 0, 0, 0, 0, 6) { IdStage = 1, IdTeam = 2 }, new TeamDayResult(2, 0, 0, 0, 0, 0, 0, 6) { IdStage = 1, IdTeam = 3 }, }; var matchFilter = new MatchFilter(matches); var classification = LeagueClassification.SortClassification(table, new int[] { 0, 3 }, matchFilter.GetMatchesForTeams); var c = classification.ToArray(); Assert.AreEqual(3, c[0].IdTeam); Assert.AreEqual(1, c[1].IdTeam); Assert.AreEqual(2, c[2].IdTeam); }