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
AnalyticsWidgetCompetitionTimes.xaml.cs
1using LiveChartsCore;
2using LiveChartsCore.Kernel;
3using LiveChartsCore.Kernel.Events;
4using LiveChartsCore.SkiaSharpView;
5using LiveChartsCore.SkiaSharpView.Painting;
6using SkiaSharp;
7using System.Collections.Generic;
9using System.Windows.Media;
12
14{
18 public partial class AnalyticsWidgetCompetitionTimes : AnalyticsWidgetBase
19 {
21
22 public AnalyticsWidgetCompetitionTimes(AnalyticsModuleCompetitionTimes analyticsModule) : base(analyticsModule)
23 {
24 _availableSwimmingStyles = Enum.GetValues(typeof(SwimmingStyles)).Cast<SwimmingStyles>().Where(s => s != SwimmingStyles.Unknown).ToList();
25 InitializeComponent();
26 }
27
28 public override string Icon => "\uE916";
29
30 public override void Refresh()
31 {
32 OnPropertyChanged(nameof(CompetitionTimesPerAgeSeries));
33 OnPropertyChanged(nameof(XAxes));
34 OnPropertyChanged(nameof(YAxes));
35 base.Refresh();
36 }
37
38 private List<SwimmingStyles> _availableSwimmingStyles;
42 public List<SwimmingStyles> AvailableSwimmingStyles => _availableSwimmingStyles;
43
44 private SwimmingStyles _selectedSwimmingStyle;
49 {
50 get => _selectedSwimmingStyle;
51 set { _selectedSwimmingStyle = value; OnPropertyChanged(); OnPropertyChanged(nameof(CompetitionTimesPerAgeSeries)); }
52 }
53
54 private Genders _selectedGender;
59 {
60 get => _selectedGender;
61 set { _selectedGender = value; OnPropertyChanged(); OnPropertyChanged(nameof(CompetitionTimesPerAgeSeries)); }
62 }
63
64 public ISeries[] CompetitionTimesPerAgeSeries
65 {
66 get
67 {
68 if (_analyticsModule == null || AnalyticsAvailable == false) return null;
69
70 List<ISeries> seriesList = new List<ISeries>();
71
73
75 {
76 Values = competitionTimeModels,
77 Mapping = (model, index) =>
78 {
79 return new Coordinate(model.Age, model.Time.TotalMilliseconds);
80 },
81 YToolTipLabelFormatter = point =>
82 {
83 string tooltipString = $"{Properties.Resources.AgeString}: {point.Model.Age}{Environment.NewLine}{Properties.Resources.TimeString}: {point.Model.Time.ToString(@"mm\:ss\.ff")}";
84 if(point.Model.IsTimeFromRudolphTable)
85 {
86 tooltipString += $"{Environment.NewLine}{Properties.Resources.ParsedFromRudolphTableString}";
87 }
88 if (point.Model.IsOpenAgeTimeFromRudolphTable)
89 {
90 tooltipString += $"{Environment.NewLine}{Properties.Resources.OpenAgeTimeFromRudolphTableString}";
91 }
92 if (point.Model.IsTimeInterpolatedFromRudolphTable)
93 {
94 tooltipString += $"{Environment.NewLine}{Properties.Resources.InterpolatedFromRudolphTableString}";
95 }
96 return tooltipString;
97 },
98 Stroke = new SolidColorPaint(ColorPaintMahAppsAccent.Color, 4),
99 Fill = new SolidColorPaint(ColorPaintMahAppsAccent.Color.WithAlpha(0x33)), // modify alpha channel for transparency
100 GeometryStroke = new SolidColorPaint(ColorPaintMahAppsAccent.Color, 2),
101 GeometrySize = 15,
102 LineSmoothness = 0 // prevent overshots
103 }
104 .OnPointMeasured(point =>
105 {
106 // assign a color to each point depending on the model flags
107 if (point.Visual is null) return;
108
109 SolidColorBrush displayColor;
110 if (point.Model.IsOpenAgeTimeFromRudolphTable)
111 {
112 displayColor = Application.Current.Resources["BrushOpenAgeTimeFromRudolphTable"] as SolidColorBrush;
113 point.Visual.Fill = new SolidColorPaint(SKColor.Parse(displayColor.Color.ToString()));
114 }
115 else if (point.Model.IsTimeFromRudolphTable)
116 {
117 displayColor = Application.Current.Resources["BrushTimeFromRudolphTable"] as SolidColorBrush;
118 point.Visual.Fill = new SolidColorPaint(SKColor.Parse(displayColor.Color.ToString()));
119 }
120 else if(point.Model.IsTimeInterpolatedFromRudolphTable)
121 {
122 displayColor = Application.Current.Resources["BrushTimeInterpolatedFromRudolphTable"] as SolidColorBrush;
123 point.Visual.Fill = new SolidColorPaint(SKColor.Parse(displayColor.Color.ToString()));
124 }
125 });
126 seriesList.Add(series);
127 return seriesList.ToArray();
128 }
129 }
130
131 public Axis[] XAxes =>
132 [
133 new Axis
134 {
135 IsVisible = true,
136 Name = Properties.Resources.AgeString,
137 NamePaint = ColorPaintMahAppsText,
138 NameTextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
139 LabelsPaint = ColorPaintMahAppsText,
140 TextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
141 MinStep = 1
142 }
143 ];
144
145 public Axis[] YAxes =>
146 [
147 new Axis
148 {
149 IsVisible = true,
150 NamePaint = ColorPaintMahAppsText,
151 NameTextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
152 SeparatorsPaint = COLORPAINT_SEPARATORS,
153 LabelsPaint = ColorPaintMahAppsText,
154 TextSize = ANALYTICS_WIDGET_AXIS_TEXTSIZE_DEFAULT,
155 LabelsDensity = 0,
156 Labeler = (value) =>
157 {
158 return TimeSpan.FromMilliseconds(value).ToString(@"mm\:ss\.ff");
159 }
160 }
161 ];
162 }
163}
Analytics module to collect the competition times for all ages and all styles.
List< ModelCompetitionTimes > GetCompetitionTimesPerAge(Genders gender, SwimmingStyles swimmingStyle)
List with ModelCompetitionTimes for the requested gender and style.
SolidColorPaint ColorPaintMahAppsAccent
SolidColorPaint that represents the MahApps.Brushes.Accent brush.
bool AnalyticsAvailable
Indicating if the analytics module has data.
IAnalyticsModule AnalyticsModule
Analytics module used by this user control.
SolidColorPaint ColorPaintMahAppsText
SolidColorPaint that represents the MahApps.Brushes.Text brush.
AnalyticsWidgetBase(IAnalyticsModule analyticsModule)
Constructor of the AnalyticsWidgetBase
SwimmingStyles SelectedSwimmingStyle
Selected SwimmingStyles that is used to display the chart.
List< SwimmingStyles > AvailableSwimmingStyles
List with all available SwimmingStyles without SwimmingStyles.Unknown
SwimmingStyles
Available swimming styles.
Genders
Available genders for a person.
Definition Genders.cs:7