fix: 🐛 improves storage calculation accuracy

This commit is contained in:
Ravinou 2024-11-15 10:16:39 +01:00
commit fc3f57e24c
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
2 changed files with 8 additions and 6 deletions

View file

@ -3,8 +3,10 @@ import classes from './StorageBar.module.css';
export default function StorageBar(props) {
//Var
//storageUsed is in octet, storageSize is in GB. Round to 1 decimal for %.
const storageUsedPercent = (((props.storageUsed / 1000000) * 100) / props.storageSize).toFixed(1);
//storageUsed is in kB, storageSize is in GB. Round to 1 decimal for %.
const storageUsedPercent = (((props.storageUsed / 1024 ** 2) * 100) / props.storageSize).toFixed(
1
);
return (
<div className={classes.barContainer}>
@ -19,8 +21,8 @@ export default function StorageBar(props) {
<div className={classes.progressionStyle} />
</div>
<div className={classes.tooltip}>
{storageUsedPercent}% ({(props.storageUsed / 1000000).toFixed(1)} GB / {props.storageSize}{' '}
GB)
{storageUsedPercent}% ({(props.storageUsed / 1024 ** 2).toFixed(1)} GB /{' '}
{props.storageSize} GB)
</div>
</div>
</div>

View file

@ -71,9 +71,9 @@ export default function StorageUsedChartBar() {
datasets: [
{
label: 'Storage used (%)',
//storageUsed is in octet, storageSize is in GB. Round to 1 decimal for %.
//storageUsed is in kB, storageSize is in GB. Round to 1 decimal for %.
data: data.map((repo) =>
(((repo.storageUsed / 1000000) * 100) / repo.storageSize).toFixed(1)
(((repo.storageUsed / 1024 ** 2) * 100) / repo.storageSize).toFixed(1)
),
backgroundColor: '#704dff',
},