File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -145,10 +145,20 @@ const ProgressScreen = () => {
145145 } ;
146146
147147 const getAverageWorkoutDuration = ( ) => {
148- if ( workouts . length === 0 ) return 0 ;
149- const total = workouts . reduce ( ( sum , w ) => sum + w . duration , 0 ) ;
150- return Math . round ( total / workouts . length ) ;
148+ const completed = workouts . filter ( w => w . is_completed && ( w . updated_at || w . completed_date ) ) ;
149+
150+ if ( completed . length === 0 ) return 0 ;
151+
152+ const totalMinutes = completed . reduce ( ( sum , w ) => {
153+ const start = new Date ( w . created_at ) . getTime ( ) ;
154+ const end = new Date ( w . updated_at ?? w . completed_date ) . getTime ( ) ;
155+ const duration = Math . round ( ( end - start ) / 60000 ) ; // in minutes
156+ return sum + duration ;
157+ } , 0 ) ;
158+
159+ return Math . round ( totalMinutes / completed . length ) ;
151160 } ;
161+
152162
153163 const unfinishedCount = useMemo (
154164 ( ) => workouts . filter ( w => ! w . is_completed ) . length ,
@@ -196,7 +206,7 @@ const ProgressScreen = () => {
196206 </ View >
197207 < View style = { styles . statCard } >
198208 < Text style = { styles . statNumber } > { getAverageWorkoutDuration ( ) } </ Text >
199- < Text style = { styles . statLabel } > Avg Duration </ Text >
209+ < Text style = { styles . statLabel } > Avg Mins Per Workout </ Text >
200210 </ View >
201211 </ View >
202212
You can’t perform that action at this time.
0 commit comments