/// <summary> /// Finds the number of pages stat category /// </summary> protected static int GetPageCount(HtmlNode tableNode) { int resultsCount = NhlBaseClass.GetResultsCount(tableNode); // There are 30 results per page, so divide number of results by 30 double numPages = Math.Ceiling(Convert.ToDouble(resultsCount) / 30); return(Convert.ToInt32(numPages)); }
/// <summary> /// Gets a list of all the results in a stat category on fromDate and later /// </summary> /// <remarks> /// This method assumes that rows are sorted in descending order by date (newest to oldest). /// /// year defaults to the current year /// fromDate defaults to DateTime.MinValue /// /// </remarks> protected virtual List <HtmlNode> GetResultsForSeasonType([Optional] int year, NhlSeasonType nhlSeasonType, [Optional] DateTime fromDate) { year = NhlModelHelper.SetDefaultYear(year); List <HtmlNode> results = new List <HtmlNode>(); HtmlNode firstPageTableNode = this.ParseHtmlTableFromPage(year, nhlSeasonType, 1); int numberOfResults = NhlBaseClass.GetResultsCount(firstPageTableNode); if (numberOfResults <= 0) { return(results); } int numberOfPages = NhlBaseClass.GetPageCount(firstPageTableNode); // Handle the first page. Go through each row and add it to the list of results. When we encounter a result with a date earlier than fromDate then we stop. List <HtmlNode> firstPageRows = NhlBaseClass.ParseRowsFromTable(firstPageTableNode); foreach (HtmlNode row in firstPageRows) { DateTime resultDate = this.ParseDateFromHtmlRow(row); if (resultDate < fromDate) { return(results); } else { results.Add(row); } } // Now similar code to handle the rest of the pages. Go through each row, add it to the list, stop when we hit a date prior to fromDate. for (int i = 2; i < numberOfPages + 1; i++) { HtmlNode tableNode = this.ParseHtmlTableFromPage(year, nhlSeasonType, i); List <HtmlNode> rows = NhlBaseClass.ParseRowsFromTable(tableNode); foreach (HtmlNode row in rows) { DateTime resultDate = this.ParseDateFromHtmlRow(row); if (resultDate < fromDate) { return(results); } else { results.Add(row); } } } return(results); }