Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to use PB rather than PiB #944

Merged

Conversation

marc-aurele-besner
Copy link
Collaborator

@marc-aurele-besner marc-aurele-besner commented Nov 13, 2024

User description

Change to use PB rather than PiB


PR Type

enhancement


Description

  • Changed the base for storage size calculation from 1024 to 1000 to align with decimal (SI) units.
  • Updated size units from binary (e.g., KiB, MiB) to decimal (e.g., KB, MB) in the formatSpacePledged function.

Changes walkthrough 📝

Relevant files
Enhancement
number.ts
Update storage size calculation to use decimal units         

explorer/src/utils/number.ts

  • Changed the base for size calculation from 1024 to 1000.
  • Updated size units from binary (KiB, MiB, etc.) to decimal (KB, MB,
    etc.).
  • +2/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @marc-aurele-besner marc-aurele-besner linked an issue Nov 13, 2024 that may be closed by this pull request
    Copy link

    netlify bot commented Nov 13, 2024

    Deploy Preview for dev-astral canceled.

    Name Link
    🔨 Latest commit 0c13103
    🔍 Latest deploy log https://app.netlify.com/sites/dev-astral/deploys/6734e4595484430008e882cb

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Calculation Accuracy
    The change from binary (1024) to decimal (1000) base might affect the accuracy of space calculations, especially for larger units. This could lead to discrepancies in reported vs actual space usage.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Prevent runtime errors by adding bounds checking for the index used with the sizes array

    Add error handling for cases where i might exceed the bounds of the sizes array to
    prevent runtime errors.

    explorer/src/utils/number.ts [87]

    +if (i >= sizes.length) throw new Error('Index exceeds size labels.');
     return parseFloat((value / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
    Suggestion importance[1-10]: 8

    Why: Adding bounds checking is crucial to prevent runtime errors if the index exceeds the array length, which is a significant improvement in terms of error handling and robustness.

    8
    Enhancement
    Enhance modularity and reusability by encapsulating size calculation and formatting in a utility function

    Consider adding a utility function to handle the calculation and formatting of the
    size, improving code modularity and reusability.

    explorer/src/utils/number.ts [85-87]

    -const i = Math.floor(Math.log(value) / Math.log(k))
    -return parseFloat((value / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
    +const formatSize = (value, base, sizes, decimals) => {
    +  const i = Math.floor(Math.log(value) / Math.log(base));
    +  return parseFloat((value / Math.pow(base, i)).toFixed(decimals)) + ' ' + sizes[i];
    +};
    +return formatSize(value, k, sizes, dm);
    Suggestion importance[1-10]: 7

    Why: Encapsulating the logic into a utility function enhances code modularity and reusability, making the code cleaner and potentially more maintainable.

    7
    Best practice
    Improve code readability and maintainability by using a named constant for the base value

    Consider using a constant for the base value 1000 to improve readability and
    maintainability.

    explorer/src/utils/number.ts [81]

    -const k = 1000
    +const BASE = 1000
    Suggestion importance[1-10]: 4

    Why: Renaming the constant from 'k' to 'BASE' improves readability but has a moderate impact on maintainability and does not affect functionality.

    4

    @marc-aurele-besner marc-aurele-besner merged commit dd1be4a into main Nov 14, 2024
    12 checks passed
    @marc-aurele-besner marc-aurele-besner deleted the feat/change-storage-pledge-mesurement-from-pb-to-pib branch November 14, 2024 02:53
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Change storage pledge mesurement from PB to PiB
    4 participants