Esempio n. 1
0
        private void SetExtendedTableScoresForHomeTeam(List <ExtendedTable> results, RankTeam homeTeam, RankTeam guestTeam, char[] alpha, ref int charIndex, GamesCycle game)
        {
            var homeTeamForExtended = results.FirstOrDefault(t => t.TeamId == homeTeam.Id.Value);

            //scores
            if (homeTeamForExtended == null)
            {
                homeTeamForExtended = new ExtendedTable
                {
                    TeamId   = homeTeam.Id.Value,
                    TeamName = homeTeam.Title,
                    Letter   = alpha[charIndex],
                };

                results.Add(homeTeamForExtended);

                charIndex++;
            }

            if (!string.IsNullOrEmpty(game.GameStatus) && game.GameStatus.Trim() == GameStatus.Ended)
            {
                homeTeamForExtended.Scores.Add(new ExtendedTableScore
                {
                    OpponentTeamId = guestTeam.Id.Value,
                    OpponentScore  = game.GuestTeamScore,
                    TeamScore      = game.HomeTeamScore
                });
            }
        }
Esempio n. 2
0
        private int GetTheBestOutOfTwoTeams(RankTeam team1, RankTeam team2, Group group)
        {
            int team1Points = 0;
            int team2Points = 0;

            // Team1 = Guest Team & Team2 = Home Team
            var games = group.GamesCycles.Where(gc => gc.GuestTeamId == team1.Id && gc.HomeTeamId == team2.Id);

            foreach (var game in games)
            {
                if (game.HomeTeamScore > game.GuestTeamScore)
                {
                    team2Points++;
                }
                else if (game.HomeTeamScore < game.GuestTeamScore)
                {
                    team1Points++;
                }
            }

            // Team1 = Home Team & Team2 = Guest Team
            games = group.GamesCycles.Where(gc => gc.GuestTeamId == team2.Id && gc.HomeTeamId == team1.Id);

            foreach (var game in games)
            {
                if (game.HomeTeamScore > game.GuestTeamScore)
                {
                    team1Points++;
                }
                else if (game.HomeTeamScore < game.GuestTeamScore)
                {
                    team2Points++;
                }
            }

            List <RankTeam> result = new List <RankTeam>();

            if (team1Points > team2Points)
            {
                return(1);
            }
            else if (team1Points < team2Points)
            {
                return(-1);
            }
            else
            {
                //If the two Teams did not play together or have same score
                return(0);
            }
        }
Esempio n. 3
0
        public RankTeam AddTeamIfNotExist(int?id, List <RankTeam> teams, int points = 0, int?seasonId = null)
        {
            RankTeam t = teams.FirstOrDefault(tm => tm.Id == id);

            if (t == null)
            {
                Team team = teamsRepo.GetById(id);
                if (team != null)
                {
                    t = new RankTeam
                    {
                        Id       = id,
                        Points   = points,
                        Title    = team.Title,
                        Games    = 0,
                        Wins     = 0,
                        Loses    = 0,
                        SetsWon  = 0,
                        SetsLost = 0,
                        Logo     = team.Logo
                    };

                    if (seasonId.HasValue)
                    {
                        var teamDetails = team.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasonId.Value);
                        if (teamDetails != null)
                        {
                            t.Title = teamDetails.TeamName;
                        }
                    }

                    teams.Add(t);
                }
            }
            return(t);
        }
Esempio n. 4
0
        private List <ExtendedTable> CreateExtendedTable(Group group, List <RankTeam> rGroupsList)
        {
            var results = new List <ExtendedTable>();

            char[] alpha     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToLower().ToCharArray();
            int    charIndex = 0;

            foreach (var game in group.GamesCycles)
            {
                RankTeam homeTeam  = rGroupsList.FirstOrDefault(x => x.Id == game.HomeTeamId);
                RankTeam guestTeam = rGroupsList.FirstOrDefault(x => x.Id == game.GuestTeamId);

                if (guestTeam == null || homeTeam == null)
                {
                    continue;
                }

                SetExtendedTableScoresForHomeTeam(results, homeTeam, guestTeam, alpha, ref charIndex, game);
                SetExtendedTableScoresForGuestTeam(results, guestTeam, homeTeam, alpha, ref charIndex, game);
            }

            results = results.OrderBy(x => x.TeamName).ToList();
            return(results);
        }
Esempio n. 5
0
        private void CalculatePoints(Group group, bool flag, List <RankTeam> rGroupsList, Game setting)
        {
            foreach (var game in group.GamesCycles)
            {
                RankTeam homeTeam  = flag ? rGroupsList.FirstOrDefault(x => x.Id == game.HomeTeamId) : AddTeamIfNotExist(game.HomeTeamId, rGroupsList);
                RankTeam guestTeam = flag ? rGroupsList.FirstOrDefault(x => x.Id == game.GuestTeamId) : AddTeamIfNotExist(game.GuestTeamId, rGroupsList);
                if (guestTeam == null || homeTeam == null)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(game.GameStatus) && game.GameStatus.Trim() == GameStatus.Ended &&
                    setting != null)
                {
                    homeTeam.Games++;
                    guestTeam.Games++;

                    //Technical Win/Lost
                    if (game.TechnicalWinnnerId != null)
                    {
                        if (game.HomeTeamId == game.TechnicalWinnnerId)
                        {
                            homeTeam.Points  += setting.PointsTechWin;
                            guestTeam.Points += setting.PointsTechLoss;
                            homeTeam.Wins++;
                            guestTeam.Loses++;
                        }
                        else
                        {
                            guestTeam.Points += setting.PointsTechWin;
                            homeTeam.Points  += setting.PointsTechLoss;
                            homeTeam.Loses++;
                            guestTeam.Wins++;
                        }
                    }
                    else
                    {
                        //Normal Win/Lost
                        if (game.HomeTeamScore > game.GuestTeamScore)
                        {
                            //Home Team wins
                            homeTeam.Points  += setting.PointsWin;
                            guestTeam.Points += setting.PointsLoss;
                            homeTeam.Wins++;
                            guestTeam.Loses++;
                        }
                        else if (game.HomeTeamScore < game.GuestTeamScore)
                        {
                            //Guest Team Wins
                            homeTeam.Points  += setting.PointsLoss;
                            guestTeam.Points += setting.PointsWin;
                            homeTeam.Loses++;
                            guestTeam.Wins++;
                        }
                        else
                        {
                            //Drow
                            homeTeam.Points  += setting.PointsDraw;
                            guestTeam.Points += setting.PointsDraw;
                        }
                    }



                    homeTeam.SetsWon   += game.HomeTeamScore;
                    homeTeam.SetsLost  += game.GuestTeamScore;
                    guestTeam.SetsWon  += game.GuestTeamScore;
                    guestTeam.SetsLost += game.HomeTeamScore;

                    foreach (GameSet set in game.GameSets)
                    {
                        homeTeam.TotalPointsScored  += set.HomeTeamScore;
                        guestTeam.TotalPointsScored += set.GuestTeamScore;
                        homeTeam.TotalPointsLost    += set.GuestTeamScore;
                        guestTeam.TotalPointsLost   += set.HomeTeamScore;
                        homeTeam.HomeTeamScore      += set.HomeTeamScore;
                        guestTeam.GuestTeamScore    += set.GuestTeamScore;

                        guestTeam.TotalGuesTeamPoints += set.GuestTeamScore;
                        guestTeam.TotalHomeTeamPoints += set.HomeTeamScore;

                        homeTeam.TotalHomeTeamPoints += set.HomeTeamScore;
                        homeTeam.TotalGuesTeamPoints += set.GuestTeamScore;

                        if (set.HomeTeamScore == set.GuestTeamScore)
                        {
                            homeTeam.Draw++;
                            guestTeam.Draw++;
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private void CalculatePointsForBasketBall(Group group, Game setting, bool flag, List <RankTeam> rGroupList)
        {
            foreach (var game in group.GamesCycles.Where(g => !string.IsNullOrEmpty(g.GameStatus) && g.GameStatus.Trim() == GameStatus.Ended && setting != null))
            {
                RankTeam homeTeam  = flag ? rGroupList.FirstOrDefault(x => x.Id == game.HomeTeamId) : AddTeamIfNotExist(game.HomeTeamId, rGroupList);
                RankTeam guestTeam = flag ? rGroupList.FirstOrDefault(x => x.Id == game.GuestTeamId) : AddTeamIfNotExist(game.GuestTeamId, rGroupList);

                if (homeTeam == null || guestTeam == null)
                {
                    continue;
                }

                ////count of games
                homeTeam.Games++;
                guestTeam.Games++;

                guestTeam.HomeTeamFinalScore += game.GameSets.Sum(x => x.GuestTeamScore);
                guestTeam.GuesTeamFinalScore += game.GameSets.Sum(x => x.HomeTeamScore);

                homeTeam.HomeTeamFinalScore += game.GameSets.Sum(x => x.HomeTeamScore);
                homeTeam.GuesTeamFinalScore += game.GameSets.Sum(x => x.GuestTeamScore);

                homeTeam.SetsWon  += game.GameSets.Sum(x => x.HomeTeamScore);
                homeTeam.SetsLost += game.GameSets.Sum(x => x.GuestTeamScore);

                guestTeam.SetsWon  += game.GameSets.Sum(x => x.GuestTeamScore);
                guestTeam.SetsLost += game.GameSets.Sum(x => x.HomeTeamScore);

                //Technical Win/Lost
                if (game.TechnicalWinnnerId.HasValue)
                {
                    if (game.HomeTeamId == game.TechnicalWinnnerId.Value)
                    {
                        homeTeam.Points  += setting.PointsTechWin;
                        guestTeam.Points += setting.PointsTechLoss;
                        homeTeam.Wins++;
                        guestTeam.TechLosses++;
                    }
                    else
                    {
                        guestTeam.Points += setting.PointsTechWin;
                        homeTeam.Points  += setting.PointsTechLoss;
                        homeTeam.TechLosses++;
                        guestTeam.Wins++;
                    }
                }
                else
                {
                    //Normal Win/Lost
                    var homeTeamScore  = game.GameSets.Sum(g => g.HomeTeamScore);
                    var guestTeamScore = game.GameSets.Sum(g => g.GuestTeamScore);
                    if (homeTeamScore > guestTeamScore)
                    {
                        //Home Team wins
                        homeTeam.Wins++;
                        guestTeam.Loses++;

                        homeTeam.Points  += setting.PointsWin;
                        guestTeam.Points += setting.PointsLoss;
                    }
                    else if (homeTeamScore < guestTeamScore)
                    {
                        //Guest Team Wins
                        homeTeam.Loses++;
                        guestTeam.Wins++;

                        homeTeam.Points  += setting.PointsLoss;
                        guestTeam.Points += setting.PointsWin;
                    }
                    else
                    {
                        //Draw
                        homeTeam.Draw++;
                        guestTeam.Draw++;
                        homeTeam.Points  += setting.PointsDraw;
                        guestTeam.Points += setting.PointsDraw;
                    }
                }
            }
        }