Пример #1
0
 public static string MakeHeader()
 {
     return(string.Format("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13};{14};{15};{16};{17};{18};{19};{20};{21}",
                          "season",
                          "division",
                          "home_team",
                          "away_team",
                          "match_day",
                          TeamAccumulator.MakeStreakHeader("total", "all_matches", "h"),
                          TeamAccumulator.MakeStreakHeader("total", "home", "h"),
                          TeamAccumulator.MakeNoStreakHeader("3", "all_matches", "h"),
                          TeamAccumulator.MakeNoStreakHeader("3", "home", "h"),
                          TeamAccumulator.MakeNoStreakHeader("5", "all_matches", "h"),
                          TeamAccumulator.MakeNoStreakHeader("5", "home", "h"),
                          TeamAccumulator.MakeNoStreakHeader("10", "all_matches", "h"),
                          TeamAccumulator.MakeNoStreakHeader("10", "home", "h"),
                          TeamAccumulator.MakeStreakHeader("total", "all_matches", "a"),
                          TeamAccumulator.MakeStreakHeader("total", "away", "a"),
                          TeamAccumulator.MakeNoStreakHeader("3", "all_matches", "a"),
                          TeamAccumulator.MakeNoStreakHeader("3", "away", "a"),
                          TeamAccumulator.MakeNoStreakHeader("5", "all_matches", "a"),
                          TeamAccumulator.MakeNoStreakHeader("5", "away", "a"),
                          TeamAccumulator.MakeNoStreakHeader("10", "all_matches", "a"),
                          TeamAccumulator.MakeNoStreakHeader("10", "away", "a"),
                          "result"
                          ));
 }
Пример #2
0
        //Recorre la tabla de clasificaciones parcialmente ordenada "classif" de manera secuencial, resolviendo los empates que va encontrando. Pueden ser necesarias varias invocaciones hasta que la tabla esté finalmente ordenada.
        private List <TeamAccumulator> TieBreak(List <TeamAccumulator> classif)
        {
            List <TeamAccumulator> result   = new List <TeamAccumulator>();
            TeamAccumulator        previous = classif.First();
            TeamAccumulator        current  = new TeamAccumulator();

            foreach (TeamAccumulator item in classif.Skip(1))
            {
                current = item;
                if (OrderOk(previous, current))
                {
                    result.Add(previous);
                    previous = current;
                }
                else
                {
                    result.Add(current);
                }
            }
            if (result.Last() == current)
            {
                result.Add(previous);
            }
            else
            {
                result.Add(current);
            }
            return(result);
        }
Пример #3
0
        //Si dos equipos tienen los mismos puntos y han jugado ya dos veces entre ellos, la diferencia de goles en esos dos partidos sirve para desempatar. No se aplica la regla de que valen más los goles anotados como visitante en caso de empate. Ej (1-1), (3-3): el que marcó 3 como visitante no queda por delante. Si no se puede desempatar se devuelve null.
        private bool?GenerateParticularRecordTieBreak(TeamAccumulator previous, TeamAccumulator current)
        {
            QuinixDbContext context          = new QuinixDbContext();
            List <Match>    ParticularRecord = Utils.GetMatches(Season, Division, 1, LastMatchDay).Where(m => m.HomeTeamId == previous.Team.Id && m.AwayTeamId == current.Team.Id || m.AwayTeamId == previous.Team.Id && m.HomeTeamId == current.Team.Id).ToList();

            if (ParticularRecord.Count() == 2)
            {
                Match firstMatch  = ParticularRecord.First();
                Match secondMatch = ParticularRecord.Last();
                bool  previousAsHomeFirstMatch = firstMatch.HomeTeamId == previous.Team.Id;
                if (previousAsHomeFirstMatch)
                {
                    if (firstMatch.HomeTeamGoals + secondMatch.AwayTeamGoals > firstMatch.AwayTeamGoals + secondMatch.HomeTeamGoals)
                    {
                        return(true);
                    }
                    else if (firstMatch.HomeTeamGoals + secondMatch.AwayTeamGoals < firstMatch.AwayTeamGoals + secondMatch.HomeTeamGoals)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (firstMatch.HomeTeamGoals + secondMatch.AwayTeamGoals > firstMatch.AwayTeamGoals + secondMatch.HomeTeamGoals)
                    {
                        return(false);
                    }
                    else if (firstMatch.HomeTeamGoals + secondMatch.AwayTeamGoals < firstMatch.AwayTeamGoals + secondMatch.HomeTeamGoals)
                    {
                        return(true);
                    }
                }
            }
            return(null);
        }
Пример #4
0
 private void TeamLost(TeamAccumulator accumulator, int goalsScored)
 {
     accumulator.GamesLost++;
     accumulator.WinningStreak = 0;
     accumulator.TieingStreak  = 0;
     accumulator.LosingStreak++;
     accumulator.UndefeatedStreak = 0;
     accumulator.NonWinningStreak++;
     if (goalsScored > 0)
     {
         TeamScored(accumulator);
     }
     else
     {
         TeamDidNotScore(accumulator);
     }
     TeamConceded(accumulator);
 }
Пример #5
0
 private void TeamWon(TeamAccumulator accumulator, int goalsConceded)
 {
     accumulator.GamesWon++;
     accumulator.WinningStreak++;
     accumulator.TieingStreak = 0;
     accumulator.LosingStreak = 0;
     accumulator.UndefeatedStreak++;
     accumulator.NonWinningStreak = 0;
     TeamScored(accumulator);
     accumulator.Points += 3;
     if (goalsConceded > 0)
     {
         TeamConceded(accumulator);
     }
     else
     {
         CleanSheet(accumulator);
     }
 }
Пример #6
0
 public TeamAccumulator(TeamAccumulator accumulator)
 {
     Team             = accumulator.Team;
     GamesPlayed      = accumulator.GamesPlayed;
     Points           = accumulator.Points;
     GamesWon         = accumulator.GamesWon;
     GamesTied        = accumulator.GamesTied;
     GamesLost        = accumulator.GamesLost;
     GoalsInFavour    = accumulator.GoalsInFavour;
     GoalsAgainst     = accumulator.GoalsAgainst;
     WinningStreak    = accumulator.WinningStreak;
     TieingStreak     = accumulator.TieingStreak;
     LosingStreak     = accumulator.LosingStreak;
     UndefeatedStreak = accumulator.UndefeatedStreak;
     NonWinningStreak = accumulator.NonWinningStreak;
     ScoringStreak    = accumulator.ScoringStreak;
     NonScoringStreak = accumulator.NonScoringStreak;
     CleanSheetStreak = accumulator.CleanSheetStreak;
     ConcedingStreak  = accumulator.ConcedingStreak;
 }
Пример #7
0
 private void TeamTied(TeamAccumulator accumulator, int goalsScored)
 {
     accumulator.GamesTied++;
     accumulator.WinningStreak = 0;
     accumulator.TieingStreak++;
     accumulator.LosingStreak = 0;
     accumulator.Points++;
     accumulator.UndefeatedStreak++;
     accumulator.NonWinningStreak++;
     if (goalsScored > 0)
     {
         TeamScored(accumulator);
         TeamConceded(accumulator);
     }
     else
     {
         TeamDidNotScore(accumulator);
         CleanSheet(accumulator);
     }
 }
Пример #8
0
        //Devuelve "true" si es correcto que el equipo del acumulador "previous" esté por delante en la tabla que el equipo del acumulador "current".
        private bool OrderOk(TeamAccumulator previous, TeamAccumulator current)
        {
            //Puntos
            if (previous.Points > current.Points)
            {
                return(true);
            }

            //Enfrentamientos directos
            bool?particularRecordTieBreak = GenerateParticularRecordTieBreak(previous, current);

            if (particularRecordTieBreak.HasValue)
            {
                return(particularRecordTieBreak.Value);
            }

            //Goal Average
            if (previous.GoalsInFavour - previous.GoalsAgainst > current.GoalsInFavour - current.GoalsAgainst)
            {
                return(true);
            }
            else if (previous.GoalsInFavour - previous.GoalsAgainst < current.GoalsInFavour - current.GoalsAgainst)
            {
                return(false);
            }

            //Goles a favor
            if (previous.GoalsInFavour > current.GoalsInFavour)
            {
                return(true);
            }
            else if (previous.GoalsInFavour < current.GoalsInFavour)
            {
                return(false);
            }

            //Empate total
            return(true);
        }
Пример #9
0
 private void CleanSheet(TeamAccumulator accumulator)
 {
     accumulator.CleanSheetStreak++;
     accumulator.ConcedingStreak = 0;
 }
Пример #10
0
 private void TeamDidNotScore(TeamAccumulator accumulator)
 {
     accumulator.ScoringStreak = 0;
     accumulator.NonScoringStreak++;
 }
Пример #11
0
 private void TeamScored(TeamAccumulator accumulator)
 {
     accumulator.ScoringStreak++;
     accumulator.NonScoringStreak = 0;
 }