getUserStatistics
Retrieve contribution statistics for a specific user in Weblate translation projects to track and analyze translation activity.
Instructions
Get contribution statistics for a specific user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | Yes | The username to get statistics for |
Implementation Reference
- src/tools/statistics.tool.ts:258-282 (handler)The main execution logic of the getUserStatistics tool. Fetches stats from service, formats them, and returns formatted text content or error.async getUserStatistics({ username }: { username: string }) { try { const stats = await this.statisticsService.getUserStatistics(username); return { content: [ { type: 'text', text: this.formatUserStatistics(username, stats), }, ], }; } catch (error) { this.logger.error(`Failed to get user statistics for ${username}`, error); return { content: [ { type: 'text', text: `Error getting user statistics: ${error.message}`, }, ], isError: true, }; } }
- src/tools/statistics.tool.ts:251-257 (schema)Zod schema and metadata for the getUserStatistics tool, defining input parameter 'username'.@Tool({ name: 'getUserStatistics', description: 'Get contribution statistics for a specific user', parameters: z.object({ username: z.string().describe('The username to get statistics for'), }), })
- Service helper that calls Weblate API to retrieve raw user statistics data.async getUserStatistics(username: string) { try { const response = await usersStatisticsRetrieve({ client: this.clientService.getClient(), path: { username }, query: { format: 'json' }, }); if (response.error) { throw new Error(`Failed to get user statistics: ${response.error}`); } return response.data; } catch (error) { this.logger.error(`Failed to get user statistics for ${username}`, error); throw error; } }
- src/tools/statistics.tool.ts:473-494 (helper)Helper function to format the raw statistics into a user-friendly markdown string.private formatUserStatistics(username: string, stats: any): string { const getStatValue = (key: string, defaultValue = 'N/A') => { return stats?.[key] !== undefined ? stats[key] : defaultValue; }; return `## π€ User Statistics: ${stats?.full_name || username} **User Details:** - π€ Username: ${getStatValue('username')} - π§ Email: ${getStatValue('email')} - π Joined: ${stats?.date_joined ? new Date(stats.date_joined).toLocaleDateString() : 'N/A'} **Contribution Stats:** - βοΈ Translations: ${getStatValue('translated')} - β Approved: ${getStatValue('approved')} - π‘ Suggestions: ${getStatValue('suggestions')} - π¬ Comments: ${getStatValue('comments')} **Activity:** - π Total Changes: ${getStatValue('total_changes')} - ποΈ Last Activity: ${stats?.last_login ? new Date(stats.last_login).toLocaleDateString() : 'N/A'}`; }