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
AnalyticsModuleStartsPerStyle.cs
5
7{
12 {
13 private IPersonService _personService;
14
20 {
21 _personService = personService;
22 }
23
25 public bool AnalyticsAvailable => _personService.GetAllPersonStarts(onlyValidStarts: true).Count() > 0;
26
30 public Dictionary<SwimmingStyles, int> NumberStartsPerStyle => _personService.GetAllPersonStarts(onlyValidStarts:true)
31 .GroupBy(s => s.Style)
32 .ToDictionary(g => g.Key, g => g.Count())
33 .OrderByDescending(d => d.Value)
34 .ToDictionary();
35
39 public Dictionary<SwimmingStyles, double> PercentageStartsPerStyle => NumberStartsPerStyle.ToDictionary(d => d.Key, d => (d.Value / (double)_personService.GetAllPersonStarts(onlyValidStarts:true).Count()) * 100)
40 .OrderByDescending(d => d.Value)
41 .ToDictionary();
42
45 {
46 DocXPlaceholderHelper.TextPlaceholders textPlaceholder = new DocXPlaceholderHelper.TextPlaceholders();
47 Dictionary<SwimmingStyles, int> numberStartsPerStyle = NumberStartsPerStyle;
48
49 // Get the localized names for each style and determine the maximum length of these strings (will be used for padding)
50 Dictionary<SwimmingStyles, string> styleNameStringsDict = numberStartsPerStyle.ToDictionary(kv => kv.Key, kv => EnumCoreLocalizedStringHelper.Convert(kv.Key));
51 int maxStyleNameStrLen = styleNameStringsDict.Max(kv => kv.Value?.Length) ?? 12;
52
53 int maxNumStarts = numberStartsPerStyle.Max(kv => kv.Value);
54
55 // Create a string for each dictionary entry including a ASCII diagramm (Format e.g.: SwimmingStyle: 3x | ### 10%)
56 string moduleString = string.Join(Environment.NewLine,
57 numberStartsPerStyle
58 .Select(kv =>
59 {
60 SwimmingStyles style = kv.Key;
61 string styleString = EnumCoreLocalizedStringHelper.Convert(style);
62 int count = kv.Value;
63 double percentage = PercentageStartsPerStyle.TryGetValue(style, out var p) ? p : 0;
64 return $"{styleNameStringsDict[kv.Key]}: ".PadRight(maxStyleNameStrLen + 2) +
65 $"{count,2}x | {new string('#', count).PadRight(maxNumStarts)} {percentage.ToString("N1")}%";
66 }));
67
68 foreach (string placeholder in Placeholders.Placeholders_AnalyticsStartsPerStyle) { textPlaceholder.Add(placeholder, moduleString); }
69 return textPlaceholder;
70 }
71
73 public List<string> SupportedDocumentPlaceholderKeys => new List<string>()
74 {
75 Placeholders.PLACEHOLDER_KEY_ANALYTICS_STARTS_PER_STYLE
76 };
77 }
78}
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....
Dictionary< SwimmingStyles, int > NumberStartsPerStyle
Number of valid starts per style.
AnalyticsModuleStartsPerStyle(IPersonService personService)
Constructor for the AnalyticsModuleStartsPerStyle
Dictionary< SwimmingStyles, double > PercentageStartsPerStyle
Percentage of valid starts per style.
bool AnalyticsAvailable
Flag indicating if the analytics module has data.
Interface for a service used to get and store a list of Person objects.