44 .Select((person, index) =>
new ModelPlacesAgeDistribution() { ResultPlace = index + 1, BirthYear = person.BirthYear, PersonObj = person }).ToList();
57 List<float> xs = birthYearsPerResultPlace.Select(p => (
float)p.ResultPlace).ToList();
58 List<float> ys = birthYearsPerResultPlace.Select(p => (
float)p.BirthYear).ToList();
60 float xAvg = xs.Average();
61 float yAvg = ys.Average();
64 float denominator = 0;
66 for (
int i = 0; i < xs.Count; i++)
68 numerator += (xs[i] - xAvg) * (ys[i] - yAvg);
69 denominator += (xs[i] - xAvg) * (xs[i] - xAvg);
72 float a = numerator / denominator;
73 float b = yAvg - a * xAvg;
75 int minPlace = birthYearsPerResultPlace.Min(p => p.ResultPlace);
76 int maxPlace = birthYearsPerResultPlace.Max(p => p.ResultPlace);
78 return new List<PointF>()
80 new PointF(minPlace, a * minPlace + b),
81 new PointF(maxPlace, a * maxPlace + b)