@@ -197,6 +197,45 @@ class _VisualizationTabState extends State<VisualizationTab> {
197
197
value = totalRepsSets > 0 ? totalWeight / totalRepsSets : 0.0 ;
198
198
break ;
199
199
200
+ case 'Top3Avg' :
201
+ // Sort records by the value of interest in descending order
202
+ final sortedRecords = recordsForDay
203
+ .map ((record) => {
204
+ 'weight' :
205
+ double .tryParse (record['weight' ].toString ()) ?? 0.0 ,
206
+ 'reps' : double .tryParse (record['reps' ].toString ()) ?? 1.0 ,
207
+ 'sets' : double .tryParse (record['sets' ].toString ()) ?? 1.0 ,
208
+ })
209
+ .toList ()
210
+ ..sort ((a, b) => ((b['weight' ] ?? 0.0 ) *
211
+ (b['reps' ] ?? 1.0 ) *
212
+ (b['sets' ] ?? 1.0 ))
213
+ .compareTo ((a['weight' ] ?? 0.0 ) *
214
+ (a['reps' ] ?? 1.0 ) *
215
+ (a['sets' ] ?? 1.0 )));
216
+
217
+ // Take the top 3 records
218
+ final top3Records = sortedRecords.take (3 ).toList ();
219
+
220
+ // Calculate the weighted average for the top 3 records
221
+ double top3TotalWeight = 0.0 ;
222
+ double top3TotalRepsSets = 0.0 ;
223
+
224
+ for (var record in top3Records) {
225
+ final weight = record['weight' ];
226
+ final reps = record['reps' ];
227
+ final sets = record['sets' ];
228
+
229
+ top3TotalWeight +=
230
+ (sets ?? 1.0 ) * (reps ?? 1.0 ) * (weight ?? 0.0 );
231
+ top3TotalRepsSets += (sets ?? 1.0 ) * (reps ?? 1.0 );
232
+ }
233
+
234
+ value = top3TotalRepsSets > 0
235
+ ? top3TotalWeight / top3TotalRepsSets
236
+ : 0.0 ;
237
+ break ;
238
+
200
239
case 'Total' :
201
240
value = recordsForDay.fold (0.0 , (sum, record) {
202
241
final sets = double .tryParse (record['sets' ].toString ()) ?? 1.0 ;
@@ -317,7 +356,7 @@ class _VisualizationTabState extends State<VisualizationTab> {
317
356
mainAxisAlignment: MainAxisAlignment .spaceBetween,
318
357
children: [
319
358
SizedBox (
320
- width: 90 ,
359
+ width: 100 ,
321
360
child: _buildAggregationDropdown (theme),
322
361
),
323
362
const SizedBox (height: 16.0 ),
@@ -435,7 +474,7 @@ class _VisualizationTabState extends State<VisualizationTab> {
435
474
});
436
475
}
437
476
},
438
- items: ['Max' , 'Average' , 'Total' ].map ((method) {
477
+ items: ['Max' , 'Average' , 'Top3Avg' , ' Total' ].map ((method) {
439
478
return DropdownMenuItem <String >(
440
479
value: method,
441
480
child: Text (method,
0 commit comments