This commit is contained in:
Drew Ansbacher
2021-11-30 14:33:48 -07:00
committed by Aiden McClelland
parent 91cf6f9a5d
commit 1614e88738
2 changed files with 41 additions and 41 deletions

View File

@@ -1,36 +1,36 @@
import { InstallProgress } from "src/app/services/patch-db/data-model";
import { InstallProgress } from 'src/app/services/patch-db/data-model'
export function packageLoadingProgress(
loadData: InstallProgress
export function packageLoadingProgress (
loadData: InstallProgress,
): ProgressData {
let {
downloaded,
validated,
unpacked,
size,
"download-complete": downloadComplete,
"validation-complete": validationComplete,
"unpack-complete": unpackComplete,
} = loadData;
'download-complete': downloadComplete,
'validation-complete': validationComplete,
'unpack-complete': unpackComplete,
} = loadData
// only permit 100% when "complete" == true
downloaded = downloadComplete ? size : Math.max(downloaded - 1, 0);
validated = validationComplete ? size : Math.max(validated - 1, 0);
unpacked = unpackComplete ? size : Math.max(unpacked - 1, 0);
downloaded = downloadComplete ? size : Math.max(downloaded - 1, 0)
validated = validationComplete ? size : Math.max(validated - 1, 0)
unpacked = unpackComplete ? size : Math.max(unpacked - 1, 0)
const downloadWeight = 1;
const validateWeight = 0.2;
const unpackWeight = 0.7;
const downloadWeight = 1
const validateWeight = 0.2
const unpackWeight = 0.7
const numerator = Math.floor(
downloadWeight * downloaded +
validateWeight * validated +
unpackWeight * unpacked
);
unpackWeight * unpacked,
)
const denominator = Math.floor(
size * (downloadWeight + validateWeight + unpackWeight)
);
size * (downloadWeight + validateWeight + unpackWeight),
)
return {
totalProgress: Math.floor((100 * numerator) / denominator),
@@ -38,13 +38,13 @@ export function packageLoadingProgress(
validateProgress: Math.floor((100 * validated) / size),
unpackProgress: Math.floor((100 * unpacked) / size),
isComplete: downloadComplete && validationComplete && unpackComplete,
};
}
}
export interface ProgressData {
totalProgress: number;
downloadProgress: number;
validateProgress: number;
unpackProgress: number;
isComplete: boolean;
totalProgress: number
downloadProgress: number
validateProgress: number
unpackProgress: number
isComplete: boolean
}