Files
Tesi/peertube/datavis/CRUD/player-statistics.js
2025-03-30 19:46:32 +02:00

103 lines
3.1 KiB
JavaScript

/* global use, db */
// MongoDB Playground
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
// Make sure you are connected to enable completions and to be able to run a playground.
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
// The result of the last command run in a playground is shown on the results panel.
// By default the first 20 documents will be returned with a cursor.
// Use 'console.log()' to print to the debug output.
// For more documentation on playgrounds please refer to
// https://www.mongodb.com/docs/mongodb-vscode/playgrounds/
// Select the database to use.
use('statistics');
// Insert a few documents into the sales collection.
db.getCollection('peertube_hetzner_high_latency').aggregate(
[
{
$group: {
_id: "$tags.session",
maxDownPeers: {
$max: "$player.Download Breakdown.Peers"
},
maxDownServer: {
$max: "$player.Download Breakdown.Server"
},
}
},
{
$group: {
_id: null,
totalDownPeers: {
$sum: "$maxDownPeers"
},
totalDownServer: {
$sum: "$maxDownServer"
}
}
},
{
$project: {
_id: 0,
totalDownPeers: 1,
totalDownServer: 1,
totalComputedDown: {
$sum: [
"$totalDownPeers",
"$totalDownServer"
]
}
}
},
{
$project: {
totalDownPeers: 1,
totalDownServer: 1,
totalComputedDown: 1,
percentageOfTotalPeers: {
$round: {
$multiply: [
{
$divide: [
"$totalDownPeers",
"$totalComputedDown"
]
},
100
]
}
},
percentageOfTotalServer: {
$round: {
$multiply: [
{
$divide: [
"$totalDownServer",
"$totalComputedDown"
]
},
100
]
}
},
ratio: {
$round: {
$divide: [
"$totalDownPeers",
"$totalDownServer"
]
}
}
}
},
{
$sort: {
ratio: -1
}
},
{
$limit: 10
}
]
)