public static double calcTrottyScore(RankingTeam team) { /* Factors for the power rankings: * 1. Wins/Losses: .4/-.4 * 2. Points Scored: .15 * 3. Point Differential: .1 * 4. Points Against: .1 * 5. Win Streak: .1 * 6. Strength of Schedule: .15 * */ double trottyScore = 0.0; trottyScore += (double)team.wins * 100; trottyScore -= (double)team.losses * 100; trottyScore += team.totalPointsDifferential * 0.1; trottyScore += (double)team.streak * 10; return trottyScore; }
public static PowerRankingsViewModel PopulateRankingsModel(string controller, string leagueID, string teamID) { HtmlDocument standings = CrawlHelpers.GetHtmlDoc(controller, leagueID, teamID); PowerRankingsViewModel model = new PowerRankingsViewModel(); var testNodes = standings.DocumentNode.SelectNodes("//tr[@class='tableBody']"); model.Teams = new List<RankingTeam>(); foreach (var node in testNodes) { RankingTeam temp = new RankingTeam(); int i = 0; foreach (var child in node.ChildNodes) { if (i == 0) { var rawHtml = child.InnerHtml; char[] seperators = { '(', ')' }; string[] nameFinder = rawHtml.Split(seperators); temp.ownerName = nameFinder[1]; temp.teamName = child.InnerText; } else if (i == 1) { temp.wins = Convert.ToInt32(child.InnerText.ToString()); } else if (i == 2) { temp.losses = Convert.ToInt32(child.InnerText.ToString()); } else if (i == 3) { temp.ties = Convert.ToInt32(child.InnerText.ToString()); } else if (i == 4) { temp.pct = Convert.ToDouble(child.InnerText.ToString()); } i++; } model.Teams.Add(temp); //temp.teamName = node.ChildNodes } //now we gra additional data from the lower table on the page var testNodes2 = standings.DocumentNode.SelectNodes("//tr[@class='evenRow bodyCopy sortableRow']"); var testNodes3 = standings.DocumentNode.SelectNodes("//tr[@class='oddRow bodyCopy sortableRow']"); foreach (var node2 in testNodes2) { char[] parse = { '(', ')' }; string[] findOwnerName = node2.ChildNodes[0].InnerText.Split(parse); RankingTeam tempTeam = model.Teams.Where(n => n.ownerName == findOwnerName[1]).SingleOrDefault(); tempTeam.totalPoints = Convert.ToDouble(node2.ChildNodes[1].InnerText); tempTeam.totalPointsAgainst = Convert.ToDouble(node2.ChildNodes[2].InnerText); tempTeam.totalPointsDifferential = tempTeam.totalPoints - tempTeam.totalPointsAgainst; string streakFull = node2.ChildNodes[node2.ChildNodes.Count - 1].InnerText; string[] streak = streakFull.Split(new string[] { "-->" }, StringSplitOptions.None); if (streak[1].Substring(0, 1) == "W") { tempTeam.streak = Convert.ToInt32(streak[1].Substring(1, streak.Length - 1)); } else if (streak[1].Substring(0, 1) == "L") { tempTeam.streak = Convert.ToInt32(streak[1].Substring(1, streak.Length - 1)) * -1; } else { tempTeam.streak = 0; } } foreach (var node2 in testNodes3) { char[] parse = { '(', ')' }; string[] findOwnerName = node2.ChildNodes[0].InnerText.Split(parse); RankingTeam tempTeam = model.Teams.Where(n => n.ownerName == findOwnerName[1]).SingleOrDefault(); tempTeam.totalPoints = Convert.ToDouble(node2.ChildNodes[1].InnerText); tempTeam.totalPointsAgainst = Convert.ToDouble(node2.ChildNodes[2].InnerText); tempTeam.totalPointsDifferential = tempTeam.totalPoints - tempTeam.totalPointsAgainst; string streakFull = node2.ChildNodes[node2.ChildNodes.Count - 1].InnerText; string[] streak = streakFull.Split(new string[] { "-->" }, StringSplitOptions.None); if (streak[1].Substring(0, 1) == "W") { tempTeam.streak = Convert.ToInt32(streak[1].Substring(1, streak.Length - 1)); } else if (streak[1].Substring(0, 1) == "L") { tempTeam.streak = Convert.ToInt32(streak[1].Substring(1, streak.Length - 1)) * -1; } else { tempTeam.streak = 0; } } return model; }