Skip to content

Commit 9fb088b

Browse files
authored
Add query for statistical engine use (#3440)
1 parent 7e21ce4 commit 9fb088b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use('xforge')
2+
3+
const metrics = db.event_metrics.aggregate([
4+
{
5+
$match: {
6+
eventType: 'StartBuildAsync'
7+
}
8+
},
9+
{
10+
$group: {
11+
_id: '$projectId',
12+
count: { $sum: 1 },
13+
timeStamps: { $push: '$timeStamp' }
14+
}
15+
},
16+
{
17+
$lookup: {
18+
from: 'sf_projects',
19+
localField: '_id',
20+
foreignField: '_id',
21+
as: 'project'
22+
}
23+
},
24+
{ $unwind: '$project' },
25+
{
26+
$project: {
27+
_id: 1,
28+
count: 1,
29+
name: '$project.name',
30+
shortName: '$project.shortName',
31+
// only show the most recent timeStamp
32+
latestTimeStamp: { $arrayElemAt: [{ $slice: ['$timeStamps', -1] }, 0] }
33+
}
34+
},
35+
{ $sort: { latestTimeStamp: -1 } },
36+
]).toArray()
37+
38+
print('Project ID\tProject Name\tShort Name\tCount\tLatest TimeStamp')
39+
for (const metric of metrics) {
40+
print(`${metric._id}\t${metric.name}\t${metric.shortName}\t${metric.count}\t${metric.latestTimeStamp.toISOString().slice(0, -1)}`)
41+
}

0 commit comments

Comments
 (0)