@@ -17,7 +17,7 @@ protected override async Task OnInitializedAsync()
1717 {
1818 _athlete = await AuthenticationService . GetCurrentAthleteAsync ( ) ;
1919
20- ActivityFilter filter = new ( _athlete . Id , false , DateTimeOffset . Now . AddMonths ( - 2 ) ) ;
20+ ActivityFilter filter = new ( _athlete . Id , false , DateTimeOffset . Now . AddMonths ( - 2 ) . ToFirstOfTheMonth ( ) ) ;
2121 _activities = await ActivityService . GetActivitiesAsync ( filter ) ;
2222 }
2323
@@ -38,59 +38,62 @@ private Dictionary<string, float[]> GetAggregatedMeasurementData(Func<Activity,
3838 . Sum ( selector ) ;
3939 } )
4040 . ToArray ( )
41- ) ;
41+ )
42+ . Where ( d => d . Value . Length > 0 )
43+ . ToDictionary ( ) ;
4244
43- if ( aggregatedData . Count != 0 )
44- {
45- aggregatedData [ "Total" ] =
46- [
47- .. aggregatedData . Values . Aggregate ( ( sum , next ) => [ .. sum . Zip ( next , ( a , b ) => a + b ) ] ) ,
48- ] ;
49- }
45+ // if (aggregatedData.Count != 0)
46+ // {
47+ // aggregatedData["Total"] =
48+ // [
49+ // .. aggregatedData.Values.Aggregate((sum, next) => [.. sum.Zip(next, (a, b) => a + b)]),
50+ // ];
51+ // }
5052
5153 return aggregatedData ;
5254 }
5355
5456 protected override async Task OnAfterRenderAsync ( bool firstRender )
5557 {
56- if ( firstRender )
57- {
58- _module = await Js . InvokeAsync < IJSObjectReference > ( "import" , "./Pages/Statistics.razor.js" ) ;
58+ if ( ! firstRender )
59+ return ;
60+
61+ _module = await Js . InvokeAsync < IJSObjectReference > ( "import" , "./Pages/Statistics.razor.js" ) ;
5962
60- List < int > lastThreeMonths =
61- [
63+ string [ ] lastThreeMonths = new int [ ]
64+ {
6265 DateTimeOffset . Now . AddMonths ( - 2 ) . Month ,
6366 DateTimeOffset . Now . AddMonths ( - 1 ) . Month ,
6467 DateTimeOffset . Now . Month ,
65- ] ;
66-
67- Dictionary < string , float [ ] > distancesLastThreeMonths =
68- GetAggregatedMeasurementData ( a => a . Details . DistanceInMeters ) ;
69- Dictionary < string , float [ ] > elevationLastThreeMonths =
70- GetAggregatedMeasurementData ( a => a . Details . TotalElevationGain ) ;
71- Dictionary < string , float [ ] > timeLastThreeMonths =
72- GetAggregatedMeasurementData ( a => ( float ) a . Details . MovingTimeInSeconds / 3600 ) ;
68+ }
69+ . Select ( CultureInfo . CurrentCulture . DateTimeFormat . GetMonthName )
70+ . ToArray ( ) ;
7371
72+ Dictionary < string , float [ ] > distanceLastThreeMonths =
73+ GetAggregatedMeasurementData ( a => ( float ) a . Details . DistanceInMeters / 1000 ) ;
74+ Dictionary < string , float [ ] > elevationLastThreeMonths =
75+ GetAggregatedMeasurementData ( a => a . Details . TotalElevationGain ) ;
76+ Dictionary < string , float [ ] > timeLastThreeMonths =
77+ GetAggregatedMeasurementData ( a => ( float ) a . Details . MovingTimeInSeconds / 3600 ) ;
7478
75- await _module . InvokeVoidAsync (
76- "drawChart" ,
77- distancesLastThreeMonths ,
78- lastThreeMonths . Select ( m => CultureInfo . CurrentCulture . DateTimeFormat . GetMonthName ( m ) ) . ToList ( ) ,
79- "totalDistanceChart" ,
80- "Total Distance [m]" ) ;
81- await _module . InvokeVoidAsync (
82- "drawChart" ,
83- elevationLastThreeMonths ,
84- lastThreeMonths . Select ( m => CultureInfo . CurrentCulture . DateTimeFormat . GetMonthName ( m ) ) . ToList ( ) ,
85- "totalElevationChart" ,
86- "Total Elevation [m]" ) ;
87- await _module . InvokeVoidAsync (
88- "drawChart" ,
89- timeLastThreeMonths ,
90- lastThreeMonths . Select ( m => CultureInfo . CurrentCulture . DateTimeFormat . GetMonthName ( m ) ) . ToList ( ) ,
91- "totalTimeChart" ,
92- "Total Time [h]" ) ;
93- }
79+ await _module . InvokeVoidAsync (
80+ "drawChart" ,
81+ distanceLastThreeMonths ,
82+ lastThreeMonths ,
83+ "totalDistanceChart" ,
84+ "Total Distance [km]" ) ;
85+ await _module . InvokeVoidAsync (
86+ "drawChart" ,
87+ elevationLastThreeMonths ,
88+ lastThreeMonths ,
89+ "totalElevationChart" ,
90+ "Total Elevation [m]" ) ;
91+ await _module . InvokeVoidAsync (
92+ "drawChart" ,
93+ timeLastThreeMonths ,
94+ lastThreeMonths ,
95+ "totalTimeChart" ,
96+ "Total Time [h]" ) ;
9497 }
9598
9699 public async ValueTask DisposeAsync ( )
0 commit comments