public void NormalizeYearChanges() { foreach (KeyValuePair <string, Dictionary <string, KeyValuePair <double[], double[]> > > kvp in bycountry) { CollectCountry.NormalizeYearChangesByCountry(kvp.Value); } }
public double EstimateHDI(string country, double year) { // find the year above and below if (!bycountry.ContainsKey(country) || !bycountry[country].ContainsKey("HDI") || bycountry[country]["HDI"].Value.Length == 0) { return(double.NaN); } KeyValuePair <double, double>[] points = CollectCountry.GetBorderValues(year, bycountry[country]["HDI"]); if (points.Length == 1 && points[0].Key == year) { return(points[0].Value); } if (!bycountry[country].ContainsKey("Total GDP- PPP") || !bycountry[country].ContainsKey("Total population")) { return(double.NaN); } double inYear = CollectCountry.GetYearValue(year, bycountry[country]["Total GDP- PPP"]) / CollectCountry.GetYearValue(year, bycountry[country]["Total population"]); if (points.Length == 1) { double inHdiYear = CollectCountry.GetYearValue(points[0].Key, bycountry[country]["Total GDP- PPP"]) / CollectCountry.GetYearValue(points[0].Key, bycountry[country]["Total population"]); return(Math.Min(1, points[0].Value * inYear / inHdiYear)); } else { double inHdiLowerYear = CollectCountry.GetYearValue(points[0].Key, bycountry[country]["Total GDP- PPP"]) / CollectCountry.GetYearValue(points[0].Key, bycountry[country]["Total population"]); double lowerEstimate = Math.Min(1, points[0].Value * inYear / inHdiLowerYear); double inHdiUpperYear = CollectCountry.GetYearValue(points[1].Key, bycountry[country]["Total GDP- PPP"]) / CollectCountry.GetYearValue(points[1].Key, bycountry[country]["Total population"]); double upperEstimate = Math.Min(1, points[0].Value * inYear / inHdiUpperYear); if (double.IsNaN(lowerEstimate)) { return(upperEstimate); } if (double.IsNaN(upperEstimate)) { return(lowerEstimate); } return(((year - points[0].Key) * upperEstimate + (points[1].Key - year) * lowerEstimate) / (points[1].Key - points[0].Key)); } }