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
AnalyticsModuleDistancesBetweenStarts.cs
5
7{
12 {
13 private IRaceService _raceService;
14
20 {
21 _raceService = raceService;
22 }
23
27 public bool AnalyticsAvailable => _raceService?.PersistedRacesVariant != null;
28
35 public Dictionary<Person, List<int>> DistancesBetweenStartsPerPerson
36 {
37 get
38 {
39 Dictionary<Person, List<int>> distancesBetweenStartsPerPerson = new Dictionary<Person, List<int>>();
40 if (!AnalyticsAvailable) { return distancesBetweenStartsPerPerson; }
41
42 RacesVariant racesVariant = _raceService.PersistedRacesVariant;
43
44 Dictionary<Person, int> lastRaceIndex = new Dictionary<Person, int>();
45 for (int i = 0; i < racesVariant.Races.Count; i++)
46 {
47 foreach (PersonStart personStart in racesVariant.Races[i].Starts)
48 {
49 // Only consider active starts
50 if (!personStart.IsActive) { continue; }
51
52 Person person = personStart.PersonObj;
53
54 if (lastRaceIndex.TryGetValue(person, out int lastIndex))
55 {
56 int distance = i - lastIndex;
57 if (!distancesBetweenStartsPerPerson.ContainsKey(person) || distancesBetweenStartsPerPerson[person] == null)
58 {
59 distancesBetweenStartsPerPerson[person] = new List<int>();
60 }
61 distancesBetweenStartsPerPerson[person].Add(distance);
62 }
63
64 lastRaceIndex[person] = i;
65 }
66 }
67 return distancesBetweenStartsPerPerson.OrderBy(d => d.Value.Min()).ToDictionary(d => d.Key, d => d.Value);
68 }
69 }
70
73 {
74 DocXPlaceholderHelper.TextPlaceholders textPlaceholder = new DocXPlaceholderHelper.TextPlaceholders();
75 Dictionary<Person, List<int>> distancesBetweenStartsPerPerson = DistancesBetweenStartsPerPerson;
76
77 // Get the joined name strings for each person and determine the maximum length of these strings (will be used for padding)
78 Dictionary<Person, string> nameStringsDict = distancesBetweenStartsPerPerson.ToDictionary(kv => kv.Key, kv => $"{kv.Key.FirstName}, {kv.Key.Name}");
79 int maxNameStrLen = nameStringsDict.Max(kv => kv.Value?.Length) ?? 30;
80
81 // Get the joined value strings for each person and determine the maximum length of these strings (will be used for padding)
82 Dictionary<Person, string> valueStringsDict = distancesBetweenStartsPerPerson.ToDictionary(kv => kv.Key, kv => string.Join(", ", kv.Value));
83 int maxValueStrLen = valueStringsDict.Max(kv => kv.Value?.Length) ?? 20;
84
85 // Create a string for each dictionary entry including a ASCII diagramm (Format e.g.: Firstname, Name: 3, 4, 2 | ###|####|## )
86 string moduleString = string.Join(Environment.NewLine,
87 distancesBetweenStartsPerPerson
88 .Select(kv => $"{nameStringsDict[kv.Key]}: ".PadRight(maxNameStrLen + 2) +
89 $"{valueStringsDict[kv.Key].PadRight(maxValueStrLen)} | " +
90 $"{string.Join("|", kv.Value.Select(v => new string('#', v)))}"));
91 foreach (string placeholder in Placeholders.Placeholders_AnalyticsDistancesBetweenStarts) { textPlaceholder.Add(placeholder, moduleString); }
92 return textPlaceholder;
93 }
94
96 public List<string> SupportedDocumentPlaceholderKeys => new List<string>()
97 {
98 Placeholders.PLACEHOLDER_KEY_ANALYTICS_DISTANCES_BETWEEN_STARTS
99 };
100 }
101}
DocXPlaceholderHelper.TextPlaceholders CollectDocumentPlaceholderContents()
Collect the values for all document placeholders that are supported by this IAnalyticsModule....
AnalyticsModuleDistancesBetweenStarts(IRaceService raceService)
Constructor for the AnalyticsModuleDistancesBetweenStarts
bool AnalyticsAvailable
This analytics is only available, when a persisted race is available.
Dictionary< Person, List< int > > DistancesBetweenStartsPerPerson
Distances between the starts (value) per person (key).
List< string > SupportedDocumentPlaceholderKeys
List of all document placeholder keys that are supported by this analytics module....
Class describing a person.
Definition Person.cs:12
Class describing a start of a person.
Definition PersonStart.cs:9
Class that represents a combination variant of all single races.
ObservableCollection< Race > Races
List with races.
Interface for a service used to manage Race and RacesVariant objects.