Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Update stats percentage when units change (#193) #286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bguillaumat
Copy link

@bguillaumat bguillaumat commented Jan 15, 2021

This will resolve #193

Copy link
Contributor

@louneskmt louneskmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you just add a new prop to the Stat component instead of actually fixing the issue.

Could you explain this to me?

@bguillaumat
Copy link
Author

bguillaumat commented Jan 15, 2021

I don't understand why you just add a new prop to the Stat component instead of actually fixing the issue.

Could you explain this to me?

Hi,

The actual issue is "due" to this code :

    abbreviateHashRate(n) {
      if (n < 1e3) return [Number(n.toFixed(1)), "H/s"];
      if (n >= 1e3 && n < 1e6) return [Number((n / 1e3).toFixed(1)), "kH/s"];
      if (n >= 1e6 && n < 1e9) return [Number((n / 1e6).toFixed(1)), "MH/s"];
      if (n >= 1e9 && n < 1e12) return [Number((n / 1e9).toFixed(1)), "GH/s"];
      if (n >= 1e12 && n < 1e15) return [Number((n / 1e12).toFixed(1)), "TH/s"];
      if (n >= 1e15 && n < 1e18) return [Number((n / 1e15).toFixed(1)), "PH/s"];
      if (n >= 1e18 && n < 1e21) return [Number((n / 1e18).toFixed(1)), "EH/s"];
      if (n >= 1e21) return [Number(+(n / 1e21).toFixed(1)), "ZH/s"];
    }, 

It transform the initial value (that I've copied in rawValue) to a modified value which is coherent with the suffix (kH/MH/etc)
So when you pass from 900MH to 1GH the stat component will say that 1 is inferior to 900 so the percent that will be displayed is -99% and not +11%

At this moment I've thought to two solutions:

  • Check the suffix in the Stat Component to set the new and old value on the same suffix then do the percent (not the best/scalable)
  • Send the rawValue to the component so it still have the "truncated" number to display value in the good suffix but use the real value to make the percent change (what I've done)

Maybe I've missed an other/better solution

@louneskmt
Copy link
Contributor

Okay I see now.

Maybe a better way to do that could be use the abbreviateXXX function in the Stat component.

For example, we could add a modifier prop to the component, to pass a function to be used on the value to display.

So the component gets the raw value, and use the modifier on it for the display part.

What do you think? Maybe yours is better.

@bguillaumat
Copy link
Author

I guess that can be done, my concern is that on Lightning.vue the use of Stats is different from Bitcoin.vue and I don't know if adding a function as a props would be better/simpler in that case

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stats percentage changes incorrectly when the units change
2 participants