Beispiel #1
0
        private static void ExtractGoaliesFromSection(Team team, TeamSection teamSection)
        {
            foreach (string line in teamSection.GoalieInformationLines)
            {
                IEnumerable <string> acronyms = line.GetAcronymns();
                Goalie goalie = new Goalie()
                {
                    Name        = line.Substring(0, 30).RemoveAcronyms().Replace("_", "").Trim(),
                    IsRookie    = acronyms.Contains("R"),
                    IsCaptain   = acronyms.Contains("C"),
                    IsAlternate = acronyms.Contains("A"),
                };

                // Convert string of values into stats
                string   rawStatsLine = line.Substring(30, line.Length - 30).Replace("%", "").Trim();
                string[] rawStats     = rawStatsLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                ConvertRawStats(rawStats, goalie);

                // Optional acronym found in traded players
                goalie.SeasonTotals.TeamAcronym = Helper.GetTeamAcronym(acronyms);

                team.Goalies.Add(goalie);
            }

            CombineTradedGoalieSubtotals(team);
        }
Beispiel #2
0
        private static void CombineTradedGoalieSubtotals(Team team)
        {
            // Traded goalies stored as new goalies are removed
            // Their season stats are pushed into the parent's subtotals
            List <Goalie> goaliesToDelete = new List <Goalie>();
            Goalie        previousGoalie  = team.Goalies.FirstOrDefault();

            foreach (Goalie goalie in team.Goalies.Skip(1))
            {
                if (goalie.Name == previousGoalie.Name)
                {
                    goaliesToDelete.Add(goalie);
                    if (previousGoalie.SeasonSubTotals == null)
                    {
                        previousGoalie.SeasonSubTotals = new List <GoalieSeasonStats>();
                    }
                    previousGoalie.SeasonSubTotals.Add(goalie.SeasonTotals);
                }
                else
                {
                    previousGoalie = goalie;
                }
            }

            // Removes extra goalies
            team.Goalies = team.Goalies.Where(goalie => !goaliesToDelete.Contains(goalie)).ToList();
        }
Beispiel #3
0
        private static void ExtractGoaliesFromSection(Team team, TeamSection teamSection)
        {
            // Goalie Stat Section
            foreach (HtmlNode row in teamSection.GoalieInformationNode.Descendants("tr").Where(a => a.ParentNode.Name != "thead"))
            {
                IList <HtmlNode> cells = row.Descendants("td").ToList();

                string name     = cells.First().InnerText;
                bool   isTraded = name.StartsWith("_");
                name = name.Replace("_", "").Trim();
                IEnumerable <string> acronyms = name.GetAcronymns();

                Goalie goalie = new Goalie()
                {
                    Name        = name.RemoveAcronyms(),
                    IsRookie    = acronyms.Contains("R"),
                    IsCaptain   = acronyms.Contains("C"),
                    IsAlternate = acronyms.Contains("A"),
                };

                ConvertCellsToStats(cells, goalie);

                if (isTraded)
                {
                    goalie.SeasonTotals.TeamAcronym = acronyms.Where(a => a.Length == 3).First();
                }

                team.Goalies.Add(goalie);
            }

            CombineTradedGoalieSubtotals(team);
        }
Beispiel #4
0
 public void ReduceTimeUntilAvailable()
 {
     Centre.ReduceTimeUntilAvailable();
     LeftWing.ReduceTimeUntilAvailable();
     RightWing.ReduceTimeUntilAvailable();
     LeftDefense.ReduceTimeUntilAvailable();
     RightDefense.ReduceTimeUntilAvailable();
     Goalie.ReduceTimeUntilAvailable();
 }
Beispiel #5
0
 public void MakeAllPlayersAvailable()
 {
     Centre.MakeAvailable();
     LeftWing.MakeAvailable();
     RightWing.MakeAvailable();
     LeftDefense.MakeAvailable();
     RightDefense.MakeAvailable();
     Goalie.MakeAvailable();
 }
Beispiel #6
0
        private void AddGoalies()
        {
            Goalie previousGoalie = new Goalie()
            {
                Name = ""
            };
            GoalieSeason previousSeason = null;

            foreach (var goalieRow in season.GoalieRows)
            {
                Goalie dbGoalie = GetGoalieFromRow(previousGoalie, goalieRow);

                int          i = 0;
                GoalieSeason dbGoalieSeason = new GoalieSeason()
                {
                    Goalie              = dbGoalie,
                    League              = league,
                    Season              = season.SeasonNumber,
                    isPlayoffs          = season.IsPlayoffs,
                    GamesPlayed         = goalieRow.Stats[i++],
                    Wins                = goalieRow.Stats[i++],
                    Losses              = goalieRow.Stats[i++],
                    OvertimeLosses      = goalieRow.Stats[i++],
                    Minutes             = goalieRow.Stats[i++],
                    PenaltyMinutes      = goalieRow.Stats[i++],
                    Shutouts            = goalieRow.Stats[i++],
                    GoalsAgainst        = goalieRow.Stats[i++],
                    ShotsAgainst        = goalieRow.Stats[i++],
                    Assists             = goalieRow.Stats[i++],
                    EmptyGoalAgainst    = goalieRow.Stats[i++],
                    PenaltyShotAttempts = goalieRow.Stats[i++],
                    Starts              = goalieRow.Stats[i++],
                    Backups             = goalieRow.Stats[i++],
                    PenaltyShotSaves    = goalieRow.Stats[i++],
                };


                dbGoalieSeason.Team = (goalieRow.TeamAcronym != null) ?
                                      teams.First(a => a.Acronym == goalieRow.TeamAcronym) : null;

                if (goalieRow.IsSubTotal)
                {
                    dbGoalieSeason.SubtotalFor = previousSeason;
                }
                else
                {
                    previousGoalie = dbGoalie;
                    previousSeason = dbGoalieSeason;
                }

                db.GoalieSeasons.Add(dbGoalieSeason);
            }
        }
Beispiel #7
0
        public GoaliePlayerStatsModel(BeaujeauxEntities database, Goalie goalie, int leagueId) : base(database, leagueId)
        {
            Goalie = goalie;

            var seasonTypes = Goalie.GoalieSeasonStats
                              .Select(sss => sss.Season.SeasonType)
                              .Distinct()
                              .ToList();

            var statGroups = new List <GoalieStatGroup>();

            foreach (var type in seasonTypes)
            {
                var stats = database.GoalieSeasonStats
                            .Where(sss => sss.Season.SeasonTypeId == type.Id)
                            .Where(sss => sss.Season.LeagueId == leagueId)
                            .Where(sss => sss.GoalieId == Goalie.Id)
                            .Where(sss => !sss.IsSubtotal)
                            .OrderByDescending(sss => sss.Season.Number)
                            .ToList();

                GoalieSeasonStat totals = new GoalieSeasonStat()
                {
                    GP  = stats.Sum(a => a.GP),
                    W   = stats.Sum(a => a.W),
                    L   = stats.Sum(a => a.L),
                    OTL = stats.Sum(a => a.OTL),
                    MP  = stats.Sum(a => a.MP),
                    PIM = stats.Sum(a => a.PIM),
                    SO  = stats.Sum(a => a.SO),
                    A   = stats.Sum(a => a.A),
                    EG  = stats.Sum(a => a.EG),
                    GA  = stats.Sum(a => a.GA),
                    SA  = stats.Sum(a => a.SA),
                    PSS = stats.Sum(a => a.PSS),
                    PSA = stats.Sum(a => a.PSA),
                    ST  = stats.Sum(a => a.ST),
                    BG  = stats.Sum(a => a.BG),
                    S1  = stats.Sum(a => a.S1),
                    S2  = stats.Sum(a => a.S2),
                    S3  = stats.Sum(a => a.S3),
                };

                statGroups.Add(new GoalieStatGroup()
                {
                    SeasonType = type,
                    Stats      = stats,
                    TotalStats = totals,
                });
            }
            GroupedStats = statGroups;
        }
Beispiel #8
0
        public ActionResult Goalie(int?li, int?pi)
        {
            if (pi == null)
            {
                RedirectToAction("Search");
            }

            var    _database = new BeaujeauxEntities();
            Goalie goalie    = _database.Goalies.Where(g => g.Id == pi).FirstOrDefault();

            if (goalie == null)
            {
                throw new Exception("no player found");
            }

            int leagueId = GetLeagueId(li);

            return(View(new GoaliePlayerStatsModel(_database, goalie, leagueId)));
        }
Beispiel #9
0
        private static void ConvertCellsToStats(IList <HtmlNode> cells, Goalie goalie)
        {
            double[]          numericValues = cells.Skip(1).Select(cell => double.Parse(cell.InnerText.Replace("%", ""))).ToArray();
            GoalieSeasonStats seasonStats   = new GoalieSeasonStats();

            seasonStats.GP  = (int)numericValues[0];
            seasonStats.W   = (int)numericValues[1];
            seasonStats.L   = (int)numericValues[2];
            seasonStats.OTL = (int)numericValues[3];
            //seasonStats.PCT = (int)numericValues[4]; // Don't need percentage
            //seasonStats.GAA = (int)numericValues[5]; // Don't need percentage
            seasonStats.MP  = (int)numericValues[6];
            seasonStats.PIM = (int)numericValues[7];
            seasonStats.SO  = (int)numericValues[8];
            seasonStats.GA  = (int)numericValues[9];
            seasonStats.SA  = (int)numericValues[10];
            seasonStats.SAR = (int)numericValues[11];
            seasonStats.A   = (int)numericValues[12];
            seasonStats.EG  = (int)numericValues[13];
            //seasonStats.PSPer = (int)numericValues[14]; // Don't need percentage
            seasonStats.PSA = (int)numericValues[15];
            seasonStats.PSS = Helper.GetPercentageAmount(numericValues[14] * 100, seasonStats.PSA);
            seasonStats.ST  = (int)numericValues[16];
            seasonStats.BG  = (int)numericValues[17];
            if (numericValues.Length == 21)
            {
                seasonStats.S1 = (int)numericValues[18];
                seasonStats.S2 = (int)numericValues[19];
                seasonStats.S3 = (int)numericValues[20];
            }
            else
            {
                seasonStats.S1 = 0;
                seasonStats.S2 = 0;
                seasonStats.S3 = 0;
            }

            goalie.SeasonTotals = seasonStats;
        }
Beispiel #10
0
        private static void ConvertRawStats(string[] rawStats, Goalie goalie)
        {
            double[]          numericValues = rawStats.Select(stats => double.Parse(stats)).ToArray();
            GoalieSeasonStats seasonStats   = new GoalieSeasonStats();

            seasonStats.GP  = (int)numericValues[0];
            seasonStats.W   = (int)numericValues[1];
            seasonStats.L   = (int)numericValues[2];
            seasonStats.OTL = (int)numericValues[3];
            //seasonStats.PCT = (int)numericValues[4]; // Don't need percentage
            //seasonStats.GAA = (int)numericValues[5]; // Don't need percentage
            seasonStats.MP  = (int)numericValues[6];
            seasonStats.PIM = (int)numericValues[7];
            seasonStats.SO  = (int)numericValues[8];
            seasonStats.GA  = (int)numericValues[9];
            seasonStats.SA  = (int)numericValues[10];
            seasonStats.SAR = (int)numericValues[11];
            seasonStats.A   = (int)numericValues[12];
            seasonStats.EG  = (int)numericValues[13];
            //seasonStats.PSPer = (int)numericValues[14]; // Don't need percentage
            seasonStats.PSA = (int)numericValues[15];
            seasonStats.PSS = Helper.GetPercentageAmount(numericValues[14] * 100, seasonStats.PSA);
            seasonStats.ST  = (int)numericValues[16];
            seasonStats.BG  = (int)numericValues[17];
            if (numericValues.Length == 21)
            {
                seasonStats.S1 = (int)numericValues[18];
                seasonStats.S2 = (int)numericValues[19];
                seasonStats.S3 = (int)numericValues[20];
            }
            else
            {
                seasonStats.S1 = 0;
                seasonStats.S2 = 0;
                seasonStats.S3 = 0;
            }

            goalie.SeasonTotals = seasonStats;
        }
Beispiel #11
0
        private Goalie GetGoalieFromRow(Goalie previousGoalie, GoalieRow goalieRow)
        {
            Goalie dbGoalie = null;

            if (previousGoalie.Name == goalieRow.Name)
            {
                dbGoalie = previousGoalie;
            }
            if (dbGoalie == null)
            {
                dbGoalie = db.Goalies.FirstOrDefault(a => a.Name == goalieRow.Name);
            }
            if (dbGoalie == null)
            {
                dbGoalie = new Goalie()
                {
                    Name = goalieRow.Name
                };
                db.Goalies.Add(dbGoalie);
            }
            return(dbGoalie);
        }
Beispiel #12
0
        public void addGoalieFromPlayer(Player myPlayer)
        {
            Goalie myGoalie = null;
            
            //ensure the current player is removed from the list
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].Equals(myPlayer))
                {
                    //if there is a player object matching the given player

                    //if that player is a goalie
                    if (players[i].GetType().ToString().Equals("icehockeyWA.Models.Goalie"))
                    {
                        //set the current goalie to that player
                        myGoalie = (Goalie)players[i];
                    }
                    else
                    {
                        players.RemoveAt(i);
                        //create a new goalie object in the list
                        myGoalie = new Goalie(myPlayer.playerID, myPlayer.name, myPlayer.number);
                        players.Add(myGoalie);
                    }
                }
            }

            currentGoalie = myGoalie;
        }
Beispiel #13
0
 public void addGoalie(int id, string name, int num)
 {
     Goalie myGoalie = new Goalie(id, name, num);
     players.Add(myGoalie);
     currentGoalie = myGoalie;
 }
Beispiel #14
0
 public new static GoalieFullDto Create(Goalie source) =>
 AutoMapper.Mapper.Map <GoalieFullDto>(source);
Beispiel #15
0
 public static PlayerDto Create(Goalie source) =>
 AutoMapper.Mapper.Map <PlayerDto>(source);