Get User Statistics
Retrieve comprehensive workout statistics for a user, including total workouts, current streak, and workout history.
Authentication
Bearer JWT token obtained from login
Users can only access their own statistics. The authenticated user ID must match the :userId parameter.
Path Parameters
MongoDB ObjectId of the user
Response
Indicates if the request was successful
Statistics object containing all metrics Total number of completed workout sessions
Total number of individual exercises completed
Total training time in minutes
Current consecutive days with completed workouts
Maximum streak ever achieved by the user
Number of workouts completed in the last 7 days
Number of workouts completed in the last 30 days
Array of the most recent 20 workout sessions ISO 8601 date when workout was completed
Name of the workout day (e.g., “Día 1 - Pecho y Tríceps”)
List of exercises completed in this session
Workout duration in minutes
Estimated calories burned
Array of unlocked achievements Unique identifier for the achievement
ISO 8601 timestamp when achievement was unlocked
Example Request
curl -X GET 'https://api.fitaiid.com/api/estadisticas/507f1f77bcf86cd799439011' \
-H 'Authorization: Bearer YOUR_JWT_TOKEN'
Example Response
{
"success" : true ,
"data" : {
"totalWorkouts" : 45 ,
"totalExercises" : 340 ,
"totalMinutes" : 2250 ,
"currentStreak" : 12 ,
"maxStreak" : 18 ,
"thisWeekWorkouts" : 5 ,
"thisMonthWorkouts" : 18 ,
"workoutHistory" : [
{
"date" : "2024-03-05T18:30:00.000Z" ,
"dayName" : "Día 1 - Pecho y Tríceps" ,
"exercises" : [
{
"nombre" : "Press de banca" ,
"series" : 4 ,
"repeticiones" : "8-10"
},
{
"nombre" : "Press inclinado con mancuernas" ,
"series" : 3 ,
"repeticiones" : "10-12"
}
],
"duration" : 50 ,
"caloriesBurned" : 320
},
{
"date" : "2024-03-04T17:15:00.000Z" ,
"dayName" : "Día 2 - Espalda y Bíceps" ,
"exercises" : [
{
"nombre" : "Dominadas" ,
"series" : 4 ,
"repeticiones" : "6-8"
}
],
"duration" : 55 ,
"caloriesBurned" : 340
}
],
"achievements" : [
{
"achievementId" : "first_workout" ,
"unlockedAt" : "2024-01-15T10:30:00.000Z"
},
{
"achievementId" : "week_streak" ,
"unlockedAt" : "2024-02-01T18:45:00.000Z"
},
{
"achievementId" : "ten_workouts" ,
"unlockedAt" : "2024-02-10T20:00:00.000Z"
}
]
}
}
Get Chart Data
Retrieve formatted data for visualizing workout statistics in charts.
Authentication
Bearer JWT token obtained from login
Path Parameters
MongoDB ObjectId of the user
Response
Indicates if the request was successful
Chart data organized by visualization type Workouts grouped by day of the week Day names: [“Lun”, “Mar”, “Mié”, “Jue”, “Vie”, “Sáb”, “Dom”]
Workout counts for each day
Workouts grouped by week (last 4 weeks) Week labels: [“Sem 4”, “Sem 3”, “Sem 2”, “Esta semana”]
Workout counts for each week
Workouts grouped by muscle group focus Workout counts per muscle group
Workouts grouped by time of day Time periods: [“Mañana (6-12h)”, “Tarde (12-18h)”, “Noche (18-24h)”]
Workout counts per time period
Example Request
const response = await fetch (
`https://api.fitaiid.com/api/estadisticas/graficos/ ${ userId } ` ,
{
headers: { 'Authorization' : `Bearer ${ token } ` }
}
);
const { data } = await response . json ();
// Use with Chart.js
const weeklyChart = new Chart ( ctx , {
type: 'bar' ,
data: {
labels: data . weeklyChart . labels ,
datasets: [{
label: 'Entrenamientos por día' ,
data: data . weeklyChart . data
}]
}
});
Example Response
{
"success" : true ,
"data" : {
"weeklyChart" : {
"labels" : [ "Lun" , "Mar" , "Mié" , "Jue" , "Vie" , "Sáb" , "Dom" ],
"data" : [ 8 , 7 , 9 , 8 , 6 , 4 , 3 ]
},
"monthlyChart" : {
"labels" : [ "Sem 4" , "Sem 3" , "Sem 2" , "Esta semana" ],
"data" : [ 12 , 15 , 14 , 18 ]
},
"focusChart" : {
"labels" : [ "Pecho" , "Espalda" , "Piernas" , "Hombros" , "Brazos" ],
"data" : [ 10 , 9 , 12 , 7 , 7 ]
},
"timeChart" : {
"labels" : [ "Mañana (6-12h)" , "Tarde (12-18h)" , "Noche (18-24h)" ],
"data" : [ 8 , 22 , 15 ]
}
}
}
Error Responses
Unauthorized - User trying to access another user’s statistics {
"success" : false ,
"message" : "No autorizado para acceder a estos datos"
}
User not found {
"success" : false ,
"message" : "Usuario no encontrado"
}
Implementation Notes
Statistics are calculated in real-time from the user’s fitnessStats field in MongoDB. The streak calculation considers consecutive days with at least one completed workout.
Use the /graficos endpoint specifically for dashboard visualizations. It returns data pre-formatted for Chart.js integration.
Workout History Get detailed workout history with all exercises
Achievements View all unlocked achievements
User Profile Get complete user profile