Skip to content

Commit

Permalink
fix: 🐛 improves storage calculation accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravinou committed Dec 8, 2024
1 parent b0fae4f commit fc3f57e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Components/UI/StorageBar/StorageBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down

0 comments on commit fc3f57e

Please sign in to comment.