mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
Update stats API - date and source filters apply to stats
This commit is contained in:
@@ -723,19 +723,41 @@ export class App {
|
||||
// get stats for showing in chatflow
|
||||
this.app.get('/api/v1/stats/:id', async (req: Request, res: Response) => {
|
||||
const chatflowid = req.params.id
|
||||
const chatTypeFilter = chatType.EXTERNAL
|
||||
let chatTypeFilter = req.query?.chatType as chatType | undefined
|
||||
const startDate = req.query?.startDate as string | undefined
|
||||
const endDate = req.query?.endDate as string | undefined
|
||||
|
||||
const totalMessages = await this.AppDataSource.getRepository(ChatMessage).count({
|
||||
where: {
|
||||
chatflowid,
|
||||
chatType: chatTypeFilter
|
||||
if (chatTypeFilter) {
|
||||
try {
|
||||
const chatTypeFilterArray = JSON.parse(chatTypeFilter)
|
||||
if (chatTypeFilterArray.includes(chatType.EXTERNAL) && chatTypeFilterArray.includes(chatType.INTERNAL)) {
|
||||
chatTypeFilter = undefined
|
||||
} else if (chatTypeFilterArray.includes(chatType.EXTERNAL)) {
|
||||
chatTypeFilter = chatType.EXTERNAL
|
||||
} else if (chatTypeFilterArray.includes(chatType.INTERNAL)) {
|
||||
chatTypeFilter = chatType.INTERNAL
|
||||
}
|
||||
} catch (e) {
|
||||
return res.status(500).send(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const chatMessageFeedbackRepo = this.AppDataSource.getRepository(ChatMessageFeedback)
|
||||
const chatmessages = (await this.getChatMessage(
|
||||
chatflowid,
|
||||
chatTypeFilter,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
startDate,
|
||||
endDate,
|
||||
'',
|
||||
true
|
||||
)) as Array<ChatMessage & { feedback?: ChatMessageFeedback }>
|
||||
const totalMessages = chatmessages.length
|
||||
|
||||
const totalFeedback = await chatMessageFeedbackRepo.count({ where: { chatflowid } })
|
||||
const positiveFeedback = await chatMessageFeedbackRepo.countBy({ chatflowid, rating: ChatMessageRatingType.THUMBS_UP })
|
||||
const totalFeedback = chatmessages.filter((message) => !message?.feedback).length
|
||||
const positiveFeedback = chatmessages.filter((message) => message?.feedback?.rating === 'THUMBS_UP').length
|
||||
|
||||
const results = {
|
||||
totalMessages,
|
||||
|
||||
Reference in New Issue
Block a user