mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 19:30:23 +00:00
refactor: dedupe test and script helpers
This commit is contained in:
@@ -261,24 +261,14 @@ export function packFilesByDuration(files, bucketCount, estimateDurationMs) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const buckets = Array.from({ length: Math.min(normalizedBucketCount, files.length) }, () => ({
|
||||
totalMs: 0,
|
||||
files: [],
|
||||
}));
|
||||
|
||||
const sortedFiles = [...files].toSorted((left, right) => {
|
||||
return estimateDurationMs(right) - estimateDurationMs(left);
|
||||
});
|
||||
|
||||
for (const file of sortedFiles) {
|
||||
const bucket = buckets.reduce((lightest, current) =>
|
||||
current.totalMs < lightest.totalMs ? current : lightest,
|
||||
);
|
||||
bucket.files.push(file);
|
||||
bucket.totalMs += estimateDurationMs(file);
|
||||
}
|
||||
|
||||
return buckets.map((bucket) => bucket.files).filter((bucket) => bucket.length > 0);
|
||||
return packFilesIntoDurationBuckets(
|
||||
files,
|
||||
Array.from({ length: Math.min(normalizedBucketCount, files.length) }, () => ({
|
||||
totalMs: 0,
|
||||
files: [],
|
||||
})),
|
||||
estimateDurationMs,
|
||||
).filter((bucket) => bucket.length > 0);
|
||||
}
|
||||
|
||||
export function packFilesByDurationWithBaseLoads(
|
||||
@@ -292,14 +282,20 @@ export function packFilesByDurationWithBaseLoads(
|
||||
return [];
|
||||
}
|
||||
|
||||
const buckets = Array.from({ length: normalizedBucketCount }, (_, index) => ({
|
||||
totalMs:
|
||||
Number.isFinite(baseLoadsMs[index]) && baseLoadsMs[index] >= 0
|
||||
? Math.round(baseLoadsMs[index])
|
||||
: 0,
|
||||
files: [],
|
||||
}));
|
||||
return packFilesIntoDurationBuckets(
|
||||
files,
|
||||
Array.from({ length: normalizedBucketCount }, (_, index) => ({
|
||||
totalMs:
|
||||
Number.isFinite(baseLoadsMs[index]) && baseLoadsMs[index] >= 0
|
||||
? Math.round(baseLoadsMs[index])
|
||||
: 0,
|
||||
files: [],
|
||||
})),
|
||||
estimateDurationMs,
|
||||
);
|
||||
}
|
||||
|
||||
function packFilesIntoDurationBuckets(files, buckets, estimateDurationMs) {
|
||||
const sortedFiles = [...files].toSorted((left, right) => {
|
||||
return estimateDurationMs(right) - estimateDurationMs(left);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user