public Player(RawPlayerStats stats) { _rawStats = stats; try { Club = Clubs.GetClubFromName(stats.TeamName); } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse club for player '{0}'", stats.Name), e); } Position = (Enums.Position)Enum.Parse(typeof(Enums.Position), stats.PositionString); switch (stats.AvailabilityStatusString.Trim()) { case "a": AvailabilityStatus = Enums.Status.Available; break; case "i": AvailabilityStatus = Enums.Status.Injured; break; case "d": AvailabilityStatus = Enums.Status.Doubtful; break; case "n": AvailabilityStatus = Enums.Status.Unavailable; break; case "s": AvailabilityStatus = Enums.Status.Suspended; break; case "u": AvailabilityStatus = Enums.Status.Unavailable; break; default: throw new ApplicationException("Unknown status: " + stats.AvailabilityStatusString); } try { GameweekHistory = new PlayerGameweekHistory(Club, stats.GameweekHistory.RawGameweeks); } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse gameweek history for player '{0}'", stats.Name), e); } try { if (stats.SeasonHistory != null && stats.SeasonHistory.Any()) { PreviousSeasons = new Dictionary <string, PlayerSeasonPerformance>(); foreach (var season in stats.SeasonHistory) { PreviousSeasons.Add(((string)season[0]).Trim(), new PlayerSeasonPerformance(season)); } } } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse season history for player '{0}'", stats.Name), e); } Fixtures = stats.Fixtures.AllFixtures .Where(f => f[0] != "-") .GroupBy(f => int.Parse(f[1].Split(' ')[1])) // group by gameweek (f[1] in form "Gameweek x") .ToDictionary( grp => grp.Key, grp => grp.Select(f => new Fixture(Club, f)).ToArray() ); }
public Player(RawPlayerStats stats) { _rawStats = stats; try { Club = Clubs.GetClubFromName(stats.TeamName); } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse club for player '{0}'", stats.Name), e); } Position = (Enums.Position)Enum.Parse(typeof(Enums.Position), stats.PositionString); switch(stats.AvailabilityStatusString.Trim()) { case "a": AvailabilityStatus = Enums.Status.Available; break; case "i": AvailabilityStatus = Enums.Status.Injured; break; case "d": AvailabilityStatus = Enums.Status.Doubtful; break; case "n": AvailabilityStatus = Enums.Status.Unavailable; break; case "s": AvailabilityStatus = Enums.Status.Suspended; break; case "u": AvailabilityStatus = Enums.Status.Unavailable; break; default: throw new ApplicationException("Unknown status: " + stats.AvailabilityStatusString); break; } try { GameweekHistory = new PlayerGameweekHistory(Club, stats.GameweekHistory.RawGameweeks); } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse gameweek history for player '{0}'", stats.Name), e); } try { if (stats.SeasonHistory != null && stats.SeasonHistory.Any()) { PreviousSeasons = new Dictionary<string, PlayerSeasonPerformance>(); foreach (var season in stats.SeasonHistory) PreviousSeasons.Add(((string)season[0]).Trim(), new PlayerSeasonPerformance(season)); } } catch (Exception e) { throw new ApplicationException(string.Format("Unable to parse season history for player '{0}'", stats.Name), e); } Fixtures = stats.Fixtures.AllFixtures .Where(f => f[0] != "-") .GroupBy(f => int.Parse(f[1].Split(' ')[1])) // group by gameweek (f[1] in form "Gameweek x") .ToDictionary( grp => grp.Key, grp => grp.Select(f => new Fixture(Club, f)).ToArray() ); }