Пример #1
0
    private static TeamStatistic GetTeamStatisticFor(Dictionary <string, TeamStatistic> teamStatistics, string teamName)
    {
        TeamStatistic teamStat1;

        if (teamStatistics.ContainsKey(teamName))
        {
            teamStat1 = teamStatistics[teamName];
        }
        else
        {
            teamStat1 = new TeamStatistic {
                Name = teamName
            };
            teamStatistics.Add(teamStat1.Name, teamStat1);
        }

        return(teamStat1);
    }
Пример #2
0
        private void AddTeamStatistic(EventOfMatch matchEvent, TeamStatistic teamStatistic)
        {
            switch (matchEvent?.EventName?.ToLower())
            {
            case "goal":
            case "penaltyscored":
                teamStatistic.Goal     += 1;
                teamStatistic.OnTarget += 1;
                break;

            case "owngoal":
                teamStatistic.Goal += 1;
                break;

            case "yellow":
                teamStatistic.YellowCard += 1;
                break;

            case "red":
                teamStatistic.RedCard += 1;
                break;

            case "corner":
                teamStatistic.Corner += 1;
                break;

            case "ontarget":
                teamStatistic.OnTarget += 1;
                break;

            case "offtarget":
                teamStatistic.OffTarget += 1;
                break;

            case "blockedshot":
                teamStatistic.BlockedShot += 1;
                break;

            case "bigchance":
                teamStatistic.BigChance += 1;
                break;
            }
        }
Пример #3
0
    private static void TallyMatch(string matchResult, TeamStatistic team1, TeamStatistic team2)
    {
        switch (matchResult)
        {
        case "win":
            team1.AddWin();
            team2.AddLoss();
            break;

        case "loss":
            team1.AddLoss();
            team2.AddWin();
            break;

        default:
            team1.AddDraw();
            team2.AddDraw();
            break;
        }
    }
Пример #4
0
 public void Update(TeamStatistic teamStatistic)
 {
     _teamStatisticDal.Update(teamStatistic);
 }
Пример #5
0
 public void Delete(TeamStatistic teamStatistic)
 {
     _teamStatisticDal.Delete(teamStatistic);
 }
Пример #6
0
 public void Add(TeamStatistic teamStatistic)
 {
     _teamStatisticDal.Add(teamStatistic);
 }
        internal CompetitionStatistic GetStatistics(ObservableCollection <Matches> allMatches, string competititionName, ObservableCollection <PlayersOfMatches> playersList)
        {
            CompetitionStatistic competitionStatistic = new CompetitionStatistic();

            try
            {
                competitionStatistic.CompetitionName = competititionName;
                competitionStatistic.TeamStatistics  = new List <TeamStatistic>();
                var matches = allMatches?.Where(x => x.MatchTypeName == competititionName && (x.RoundID < 1000));
                //&& (string.Equals(x.HomeTeam, team.TeamName, StringComparison.OrdinalIgnoreCase)
                //|| string.Equals(x.AwayTeam, team.TeamName, StringComparison.OrdinalIgnoreCase)));
                foreach (Matches match in matches)
                {
                    var players = playersList?.Where(p => p.MatchId == match.MatchID);
                    //HOME TEAM STATISTICS
                    bool          isNewHomeTeamStatistics = false;
                    TeamStatistic homeTeamFullStatistic   = new TeamStatistic();
                    if (competitionStatistic.TeamStatistics.Any(x => x.TeamName == match.HomeTeam))
                    {
                        homeTeamFullStatistic = competitionStatistic.TeamStatistics.FirstOrDefault(x => x.TeamName == match.HomeTeam);
                    }
                    else
                    {
                        isNewHomeTeamStatistics        = true;
                        homeTeamFullStatistic.TeamName = match.HomeTeam;
                    }
                    homeTeamFullStatistic.Goal     += match.HomeTeamScore ?? 0;
                    homeTeamFullStatistic.Corner   += match.HomeTeamCorner ?? 0;
                    homeTeamFullStatistic.OnTarget += match.HomeTeamOnTarget ?? 0 + match.HomeTeamScore ?? 0;
                    competitionStatistic.GoalPlayers.AddRange(players.Where(p => p.TeamName == match.HomeTeam && p.Goal > 0));
                    competitionStatistic.AssistPlayers.AddRange(players.Where(p => p.TeamName == match.HomeTeam && p.Assist > 0));
                    if (isNewHomeTeamStatistics)
                    {
                        competitionStatistic.TeamStatistics.Add(homeTeamFullStatistic);
                    }

                    //AWAY TEAM STATISTICS
                    bool          isNewAwayTeamStatistics = false;
                    TeamStatistic awayTeamFullStatistic   = new TeamStatistic();
                    if (competitionStatistic.TeamStatistics.Any(x => x.TeamName == match.AwayTeam))
                    {
                        awayTeamFullStatistic = competitionStatistic.TeamStatistics.FirstOrDefault(x => x.TeamName == match.AwayTeam);
                    }
                    else
                    {
                        isNewAwayTeamStatistics        = true;
                        awayTeamFullStatistic.TeamName = match.AwayTeam;
                    }
                    awayTeamFullStatistic.Goal     += match.AwayTeamScore ?? 0;
                    awayTeamFullStatistic.Corner   += match.AwayTeamCorner ?? 0;
                    awayTeamFullStatistic.OnTarget += match.AwayTeamOnTarget ?? 0 + match.AwayTeamScore ?? 0;
                    competitionStatistic.GoalPlayers.AddRange(players.Where(p => p.TeamName == match.AwayTeam && p.Goal > 0));
                    competitionStatistic.AssistPlayers.AddRange(players.Where(p => p.TeamName == match.AwayTeam && p.Assist > 0));
                    if (isNewAwayTeamStatistics)
                    {
                        competitionStatistic.TeamStatistics.Add(awayTeamFullStatistic);
                    }
                }

                var playersGoalGroup = competitionStatistic.GoalPlayers.GroupBy(x => x.FirstName);
                competitionStatistic.GoalPlayers = new List <PlayersOfMatches>();
                foreach (var playerGroup in playersGoalGroup)
                {
                    PlayersOfMatches newPlayers = new PlayersOfMatches()
                    {
                        FirstName = playerGroup.FirstOrDefault().FirstName,
                        TeamName  = playerGroup.LastOrDefault().TeamName,
                        Goal      = 0
                    };

                    foreach (PlayersOfMatches playerOfMatch in playerGroup)
                    {
                        newPlayers.Goal += playerOfMatch.Goal;
                    }
                    competitionStatistic.GoalPlayers.Add(newPlayers);
                }
                competitionStatistic.GoalPlayers = competitionStatistic.GoalPlayers.OrderByDescending(x => x.Goal).ThenBy(x => x.TeamName).ThenBy(x => x.FirstName).ToList();

                var playersAssistGroup = competitionStatistic.AssistPlayers.GroupBy(x => x.FirstName);
                competitionStatistic.AssistPlayers = new List <PlayersOfMatches>();
                foreach (var playerGroup in playersAssistGroup)
                {
                    PlayersOfMatches newPlayers = new PlayersOfMatches()
                    {
                        FirstName = playerGroup.FirstOrDefault().FirstName,
                        TeamName  = playerGroup.LastOrDefault().TeamName,
                        Assist    = 0
                    };
                    foreach (PlayersOfMatches playerOfMatch in playerGroup)
                    {
                        newPlayers.Assist += playerOfMatch.Assist;
                    }
                    competitionStatistic.AssistPlayers.Add(newPlayers);
                }
                competitionStatistic.AssistPlayers = competitionStatistic.AssistPlayers.OrderByDescending(x => x.Assist).ThenBy(x => x.TeamName).ThenBy(x => x.FirstName).ToList();
            }
            catch (Exception ex)
            {
                var exception = ex.Message;
            }
            return(competitionStatistic);
        }
Пример #8
0
        public IActionResult Index()
        {
            var teams   = _context.Teams.ToList();
            var matches = _context.Matches.ToList();
            var players = _context.Players.ToList();
            var goals   = _context.Goals.ToList();
            List <PlayerStatistic> playerStatistics = new List <PlayerStatistic>();
            List <TeamStatistic>   teamStatistics   = new List <TeamStatistic>();
            Statistic statistics = new Statistic();

            foreach (Team t in teams)
            {
                TeamStatistic ts = new TeamStatistic();
                ts.team = t;

                int numOfWins   = 0;
                int numOfDraws  = 0;
                int numOfLosses = 0;

                foreach (Match m in matches)
                {
                    if (m.HostTeamId == t.TeamId || (m.GuestTeamId == t.TeamId))
                    {
                        string result = m.Result;
                        int    res1   = int.Parse(result.Split(":")[0]);
                        int    res2   = int.Parse(result.Split(":")[1]);
                        if (res1 > res2)
                        {
                            if (m.HostTeamId == t.TeamId)
                            {
                                numOfWins++;
                            }
                            else
                            {
                                numOfLosses++;
                            }
                        }
                        else if (res1 == res2)
                        {
                            numOfDraws++;
                        }
                    }
                }

                ts.numOfDraws  = numOfDraws;
                ts.numOfLosses = numOfLosses;
                ts.numOfWins   = numOfWins;

                teamStatistics.Add(ts);
            }

            foreach (Player p in players)
            {
                PlayerStatistic ps   = new PlayerStatistic();
                Team            team = _context.Teams.FirstOrDefault(t => t.TeamId == p.TeamId);
                p.Team    = team;
                ps.player = p;
                int numOfMatches = 0;
                int numOfGoals   = 0;

                foreach (Goal g in goals)
                {
                    if (g.PlayerId == p.PlayerId)
                    {
                        numOfMatches++;
                        numOfGoals += g.NumberOfGoals;
                    }
                }

                ps.numOfGoals   = numOfGoals;
                ps.numOfMatches = numOfMatches;
                playerStatistics.Add(ps);
            }

            statistics.playerStatistics = playerStatistics;
            statistics.teamStatistics   = teamStatistics;
            return(View("~/Views/Statistics/Index.cshtml", statistics));
        }