Untitled
Anonymous
Plain Text
09/02/2025 10:04 AM
1.4 KB
15
Indexable
Never
use VFSessionHistoryDB
db.Sessions.aggregate([
// [OPZIONALE] filtri (es. per progetto o periodo)
// { $match: { PrjId: "23", SessionEndDate: { $gte: ISODate("2025-08-26T00:00:00Z"), $lt: ISODate("2025-08-27T00:00:00Z") } } },
{ $match: { PrjId: "23" } },
// Considera solo TextAnalysisFeedbacks
{
$project: {
ta: { $ifNull: ["$Feedbacks.TextAnalysisFeedbacks", []] }
}
},
{ $unwind: "$ta" },
// Solo ServiceType = 7 e rating non null
{
$match: {
"ta.ServiceType": 7,
"ta.FeedbackRating": { $ne: null }
}
},
// Conteggi rating 5 e 0
{
$group: {
_id: null,
total_rated: { $sum: 1 },
rating5_count: { $sum: { $cond: [{ $eq: ["$ta.FeedbackRating", 5] }, 1, 0] } },
rating0_count: { $sum: { $cond: [{ $eq: ["$ta.FeedbackRating", 0] }, 1, 0] } }
}
},
// Percentuali
{
$project: {
_id: 0,
total_rated: 1,
rating5_count: 1,
rating0_count: 1,
rating5_pct: {
$cond: [
{ $gt: ["$total_rated", 0] },
{ $round: [{ $multiply: [{ $divide: ["$rating5_count", "$total_rated"] }, 100] }, 2] },
null
]
},
rating0_pct: {
$cond: [
{ $gt: ["$total_rated", 0] },
{ $round: [{ $multiply: [{ $divide: ["$rating0_count", "$total_rated"] }, 100] }, 2] },
null
]
}
}
}
])Editor is loading...
Leave a Comment