/// <summary> /// calculated SI factor /// </summary> /// <param name="fatherFromList">data of horses father</param> /// <param name="date">day of the race</param> /// <returns>returns SI</returns> public double ComputeSiblingsIndex(LoadedHorse fatherFromList, DateTime date, RaceModel raceModelProvider, List <LoadedHorse> horses, Dictionary <string, int> raceCategoryDictionary) { ResetComputeVariables(); horses = new List <LoadedHorse>(horses.OrderBy(l => l.Age)); //from smallest to biggest for (int i = 0; i < fatherFromList.AllChildren.Count; i++) { HorseChildDetails child = fatherFromList.AllChildren[i]; if (child.ChildAge == 0) { ChildFromList = horses .Where(h => h.Name.ToLower() == child .ChildName.ToLower()) .FirstOrDefault(); } else { ChildFromList = horses .Where(h => h.Name.ToLower() == child.ChildName.ToLower()) .Where(h => h.Age == child.ChildAge) .FirstOrDefault(); } if (ChildFromList != null && ChildFromList.AllRaces.Count > 0) { SiblingIndex = ComputeWinIndex(ChildFromList, date, null, raceModelProvider, raceCategoryDictionary); Counter++; } else { SiblingIndex = 0; } Result = Result + SiblingIndex; } if (Counter != 0) { FinalResult = Result / Counter; } else { FinalResult = 0; } return(FinalResult); }
public HorseChildDetails SplitChildNodeString(string jobType, string nodeString, string propertyName, DateTime raceDate) { HorseDataWrapper wrapper = new HorseDataWrapper(); HorseChildDetails child = new HorseChildDetails(); string name = SplitName(jobType, nodeString, typeof(LoadedHorse), propertyName); string age = SplitAge(jobType, nodeString, _dateToday, propertyName); string link = SplitLink(nodeString, jobType, propertyName); string jockey = ""; wrapper = ParseHorseData(_dateToday, name, age, link, jockey, jobType); child.ChildAge = wrapper.Age; child.ChildLink = wrapper.Link; child.ChildName = wrapper.HorseName; return(child); }
/// <summary> /// Some classes have collections of objects as props, here we get them /// </summary> /// <typeparam name="T">collection generic type</typeparam> /// <param name="raceHtmlAgilityList">list of HTML documents by HtmlAfilityPack framework</param> /// <param name="propertyName">property collection name of currently scrapped object (ex. AllRaces - of the horse)</param> /// <param name="nodeDictionary">xpath dictionary with property name as a Key</param> /// <param name="jobType">type of scrapping</param> /// <param name="raceDate">day of race input</param> /// <returns></returns> public List <T> GetGenericList <T>(List <HtmlDocument> raceHtmlAgilityList, string propertyName, Dictionary <string, string> nodeDictionary, string jobType, DateTime raceDate) { List <HorseChildDetails> children = new List <HorseChildDetails>(); List <RaceDetails> races = new List <RaceDetails>(); List <HorseDataWrapper> horses = new List <HorseDataWrapper>(); string xpath = nodeDictionary[propertyName]; bool nodeConditions = false; foreach (var raceHtmlAgility in raceHtmlAgilityList) { nodeConditions = _parseService.VerifyNodeCondition(raceHtmlAgility.DocumentNode.OuterHtml.ToString(), propertyName, jobType); if (nodeConditions) //check complete page { HtmlNode[] tableRowsNode = raceHtmlAgility.DocumentNode.SelectNodes(xpath).ToArray(); if (tableRowsNode.Length > 0) { foreach (var row in tableRowsNode) { string nodeString = row.OuterHtml.ToString(); nodeConditions = _parseService.VerifyNodeCondition(nodeString, propertyName, jobType); if (nodeConditions) //check single row { if (typeof(T) == typeof(HorseChildDetails)) { HorseChildDetails child = new HorseChildDetails(); child = _parseService.SplitChildNodeString(jobType, nodeString, propertyName, raceDate); children.Add(child); } else if (typeof(T) == typeof(RaceDetails)) { RaceDetails race = new RaceDetails(); race = _parseService.SplitRaceNodeString(jobType, nodeString, propertyName); races.Add(race); } else if (typeof(T) == typeof(HorseDataWrapper)) { HorseDataWrapper horse = new HorseDataWrapper(); horse = _parseService.SplitHorseNodeString(jobType, nodeString, propertyName, raceDate); horses.Add(horse); } } } } } } if (typeof(T) == typeof(HorseChildDetails)) { return((List <T>)Convert.ChangeType(children, typeof(List <T>))); } else if (typeof(T) == typeof(RaceDetails)) { return((List <T>)Convert.ChangeType(races, typeof(List <T>))); } else if (typeof(T) == typeof(HorseDataWrapper)) { return((List <T>)Convert.ChangeType(horses, typeof(List <T>))); } else { throw new ArgumentException(); } }