public IEnumerable <CountryGwpItem> FindCloseAverageGwpPeers(string country, string lineOfBusiness, int yearStart, int yearEnd, int peersToReturn) { CountryGwpItem selectedCountry = _countryGwpItems.FirstOrDefault(c => c.Country == country && c.LineOfBusiness == lineOfBusiness); var selectedCountryAvgGrowthRate = CountryGwpBusinessModel.GetAverageGrowthRate(selectedCountry, yearStart, yearEnd); var peers = _countryGwpItems .Where(p => p.LineOfBusiness == lineOfBusiness) .OrderByDescending(p => SqrRootDistanceToAvgGrowthRate(selectedCountryAvgGrowthRate, p, yearStart, yearEnd)) .Take(peersToReturn); return(peers); }
private double SqrRootDistanceToAvgGrowthRate(double selectedCountryAvgGrowthRate, CountryGwpItem countryGwp, int yearStart, int yearEnd) { return(Math.Sqrt(Math.Pow((selectedCountryAvgGrowthRate - CountryGwpBusinessModel.GetAverageGrowthRate(countryGwp, yearStart, yearEnd)), 2))); }