mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-20 15:05:43 +00:00
Merge pull request #24256 from overleaf/bg-backup-fix-sample
fix backup sample script GitOrigin-RevId: 4bf4c15324d9b3b7ebd809f7b212e52d75ab216d
This commit is contained in:
parent
28ff69b51b
commit
3b93efdf5c
1 changed files with 5 additions and 21 deletions
|
@ -32,34 +32,18 @@ async function takeSample(sampleSize) {
|
|||
[
|
||||
{ $sample: { size: sampleSize } },
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
hasBackup: {
|
||||
$ifNull: ['$overleaf.backup.lastBackedUpVersion', false],
|
||||
},
|
||||
},
|
||||
$match: { 'overleaf.backup.lastBackedUpVersion': { $exists: true } },
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
totalSampled: { $sum: 1 },
|
||||
backedUp: {
|
||||
$sum: {
|
||||
$cond: ['$hasBackup', 1, 0],
|
||||
},
|
||||
},
|
||||
},
|
||||
$count: 'total',
|
||||
},
|
||||
],
|
||||
{ readPreference: READ_PREFERENCE_SECONDARY }
|
||||
)
|
||||
.toArray()
|
||||
|
||||
if (results.length === 0) {
|
||||
return { totalSampled: 0, backedUp: 0 }
|
||||
}
|
||||
|
||||
return results[0]
|
||||
const count = results[0]?.total || 0
|
||||
return { totalSampled: sampleSize, backedUp: count }
|
||||
}
|
||||
|
||||
function calculateStatistics(
|
||||
|
@ -67,7 +51,7 @@ function calculateStatistics(
|
|||
cumulativeBackedUp,
|
||||
totalPopulation
|
||||
) {
|
||||
const proportion = cumulativeBackedUp / cumulativeSampled
|
||||
const proportion = Math.max(1, cumulativeBackedUp) / cumulativeSampled
|
||||
|
||||
// Standard error with finite population correction
|
||||
const fpc = Math.sqrt(
|
||||
|
|
Loading…
Add table
Reference in a new issue