Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
AnalyticsModulePlacesAgeDistribution.cs
1using System.Drawing;
6
8{
13 {
14 #region Model
16 {
17 public int ResultPlace { get; set; }
18 public ushort BirthYear { get; set; }
19 public Person PersonObj { get; set; }
20 }
21 #endregion
22
23 private IScoreService _scoreService;
24 private IPersonService _personService;
25
32 {
33 _scoreService = scoreService;
34 _personService = personService;
35 }
36
38 public bool AnalyticsAvailable => _personService.PersonCount > 0;
39
43 public List<ModelPlacesAgeDistribution> BirthYearsPerResultPlace => _scoreService.GetPersonsSortedByScore(ResultTypes.Overall, true)
44 .Select((person, index) => new ModelPlacesAgeDistribution() { ResultPlace = index + 1, BirthYear = person.BirthYear, PersonObj = person }).ToList();
45
50 public List<PointF> LinearRegressionLinePoints
51 {
52 get
53 {
54 if(BirthYearsPerResultPlace == null || BirthYearsPerResultPlace.Count == 0) { return new List<PointF>(); }
55
56 List<ModelPlacesAgeDistribution> birthYearsPerResultPlace = BirthYearsPerResultPlace;
57 List<float> xs = birthYearsPerResultPlace.Select(p => (float)p.ResultPlace).ToList();
58 List<float> ys = birthYearsPerResultPlace.Select(p => (float)p.BirthYear).ToList();
59
60 float xAvg = xs.Average();
61 float yAvg = ys.Average();
62
63 float numerator = 0;
64 float denominator = 0;
65
66 for (int i = 0; i < xs.Count; i++)
67 {
68 numerator += (xs[i] - xAvg) * (ys[i] - yAvg);
69 denominator += (xs[i] - xAvg) * (xs[i] - xAvg);
70 }
71
72 float a = numerator / denominator;
73 float b = yAvg - a * xAvg;
74
75 int minPlace = birthYearsPerResultPlace.Min(p => p.ResultPlace);
76 int maxPlace = birthYearsPerResultPlace.Max(p => p.ResultPlace);
77
78 return new List<PointF>()
79 {
80 new PointF(minPlace, a * minPlace + b),
81 new PointF(maxPlace, a * maxPlace + b)
82 };
83 }
84 }
85
88 {
89 DocXPlaceholderHelper.TextPlaceholders textPlaceholder = new DocXPlaceholderHelper.TextPlaceholders();
90 // Create a string for each list entry (Format e.g.: Result List Place 1: Birth Year 2000 (Firstname, Name))
91 string placeholderString = string.Join(Environment.NewLine,
93 .Select(e => $"{Properties.Resources.ResultPlaceString} {e.ResultPlace.ToString().PadLeft(3)}: {Properties.Resources.BirthYearString} {e.BirthYear} ({e.PersonObj?.FirstName}, {e.PersonObj?.Name})"));
94 foreach (string placeholder in Placeholders.Placeholders_AnalyticsPlacesAgeDistribution) { textPlaceholder.Add(placeholder, placeholderString); }
95 return textPlaceholder;
96 }
97
99 public List<string> SupportedDocumentPlaceholderKeys => new List<string>()
100 {
101 Placeholders.PLACEHOLDER_KEY_ANALYTICS_PLACES_AGE_DISTRIBUTION
102 };
103
104 }
105}
AnalyticsModulePlacesAgeDistribution(IScoreService scoreService, IPersonService personService)
Constructor for the AnalyticsModulePlacesAgeDistribution
List< PointF > LinearRegressionLinePoints
List with the start and end points of a linear regression line through the BirthYearsPerResultPlace p...
List< string > SupportedDocumentPlaceholderKeys
List of all document placeholder keys that are supported by this analytics module....
DocXPlaceholderHelper.TextPlaceholders CollectDocumentPlaceholderContents()
Collect the values for all document placeholders that are supported by this IAnalyticsModule....
List< ModelPlacesAgeDistribution > BirthYearsPerResultPlace
List with ModelPlacesAgeDistribution ordered by the result place.
Class describing a person.
Definition Person.cs:12
Interface for a service used to get and store a list of Person objects.
Interface for a service used to calculate the scores for all persons.
ResultTypes
Available result types.
Definition ResultTypes.cs:7