public static StatValue Create(string raw, StatDefinition stat) { if (FloatStats.Contains(stat.Id)) { // Multiply by 1000 and go with an int if (raw == "-") { return(new StatValue(raw, 0, stat)); } float f = float.Parse(raw); f = f * 1000; return(new StatValue(raw, (int)f, stat)); } if (RatioStats.Contains(stat.Id)) { // Do the math and multiply by 1000 if (raw == "-/-") { return(new StatValue(raw, 0, stat)); } string[] parts = raw.Split('/'); float n = float.Parse(parts[0]) * 1000; float d = float.Parse(parts[1]); float v = n / d; return(new StatValue(raw, (int)v, stat)); } if (InningsStats.Contains(stat.Id)) { if (raw == "-") { return(new StatValue(raw, 0, stat)); } string[] parts = raw.Split('.'); int wholeInnings = int.Parse(parts[0]); int additionalOuts = int.Parse(parts[1]); return(new StatValue(raw, (wholeInnings * 3) + additionalOuts, stat)); } // It's already an int! if (raw == "-") { return(new StatValue(raw, 0, stat)); } return(new StatValue(raw, int.Parse(raw), stat)); }
private StatValue(string raw, int processed, StatDefinition stat) { this.Raw = raw; this.Processed = processed; this.Stat = stat; }
public static async Task <League> Create(string leagueId) { string leagueXml = await Services.Http.GetRawDataAsync(UrlGen.LeagueSettingsUrl(leagueId)); XmlDocument doc = new XmlDocument(); doc.LoadXml(leagueXml); NSMgr nsmgr = new NSMgr(doc); XmlNode league = doc.SelectSingleNode(nsmgr.GetXPath("fantasy_content", "league"), nsmgr); string key = nsmgr.GetValue(league, "league_key"); string name = nsmgr.GetValue(league, "name"); Dictionary <int, StatDefinition> stats = new Dictionary <int, StatDefinition>(); foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "stat_categories", "stats", "stat"), nsmgr)) { StatDefinition stat = StatDefinition.Create(node, nsmgr); stats[stat.Id] = stat; } List <RosterPosition> rosterPositions = new List <RosterPosition>(); foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("settings", "roster_positions", "roster_position"), nsmgr)) { rosterPositions.Add(RosterPosition.Create(node, nsmgr)); } string leagueTeams = await Services.Http.GetRawDataAsync(UrlGen.TeamsWithRostersUrl(leagueId)); doc.LoadXml(leagueTeams); nsmgr = new NSMgr(doc); league = doc.SelectSingleNode(nsmgr.GetXPath("fantasy_content", "league"), nsmgr); List <Team> teams = new List <Team>(); foreach (XmlNode team in league.SelectNodes(nsmgr.GetXPath("teams", "team"), nsmgr)) { teams.Add(Team.Create(team, nsmgr)); } Dictionary <string, Player> players = new Dictionary <string, Player>(); foreach (Player player in await Player.GetAllPlayers(leagueId)) { player.SetStatValues(stats); players[player.Key] = player; } string leagueStandings = await Services.Http.GetRawDataAsync(UrlGen.LeagueStandings(leagueId)); doc.LoadXml(leagueStandings); nsmgr = new NSMgr(doc); league = doc.SelectSingleNode(nsmgr.GetXPath("fantasy_content", "league"), nsmgr); List <Standings> standings = new List <Standings>(); foreach (XmlNode node in league.SelectNodes(nsmgr.GetXPath("standings", "teams", "team"), nsmgr)) { standings.Add(Standings.Create(node, nsmgr)); } return(new League(key, name, stats, rosterPositions, teams, players, standings)); }