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

Feature Request: Dynamic Scaling of Displayed Values on Home Page #1973

Open
davecgh opened this issue Sep 4, 2023 · 9 comments
Open

Feature Request: Dynamic Scaling of Displayed Values on Home Page #1973

davecgh opened this issue Sep 4, 2023 · 9 comments

Comments

@davecgh
Copy link
Member

davecgh commented Sep 4, 2023

Notice in the screenshot how the Mining difficulty says "0 Mil". I suggest this should be a dynamically scaled humanized value instead. Similarly, the hashrate is being reproted in Ph/s. It should scale dynamically too.

image

Example code:

func humanizeHPS(b uint64) string {
	const unit = 1000
	if b < unit {
		return fmt.Sprintf("%d h/s", b)
	}
	div, exp := uint64(unit), 0
	for n := b / unit; n >= unit; n /= unit {
		div *= unit
		exp++
	}
	return fmt.Sprintf("%.2f %ch/s", float64(b)/float64(div), "kMGTPE"[exp])
}
func main() {
	const maxUint64 = 1<<64 - 1
	testVals := []uint64{0}
	for hps := uint64(1); hps < 10e18; hps *= 10 {
		testVals = append(testVals, hps)
	}
	testVals = append(testVals, maxUint64)

	for _, hps := range testVals {
		fmt.Printf("%v (input: %d)\n", humanizeHPS(max(hps, 1)), hps)
	}
}

Output:

1 h/s (input: 0)
1 h/s (input: 1)
10 h/s (input: 10)
100 h/s (input: 100)
1.00 kh/s (input: 1000)
10.00 kh/s (input: 10000)
100.00 kh/s (input: 100000)
1.00 Mh/s (input: 1000000)
10.00 Mh/s (input: 10000000)
100.00 Mh/s (input: 100000000)
1.00 Gh/s (input: 1000000000)
10.00 Gh/s (input: 10000000000)
100.00 Gh/s (input: 100000000000)
1.00 Th/s (input: 1000000000000)
10.00 Th/s (input: 10000000000000)
100.00 Th/s (input: 100000000000000)
1.00 Ph/s (input: 1000000000000000)
10.00 Ph/s (input: 10000000000000000)
100.00 Ph/s (input: 100000000000000000)
1.00 Eh/s (input: 1000000000000000000)
18.45 Eh/s (input: 18446744073709551615)
@xaur
Copy link

xaur commented Sep 5, 2023

Yes please! Big zero in Difficulty and Hashrate look like something is broken.

While at it we may also change h/s to H/s per this discussion but it is a minor thing and can be skipped.

@matthawkins90
Copy link
Contributor

matthawkins90 commented Sep 25, 2023

I spent a long time trying to get familiar with the codebase so I could make this change. I'm nearly there, but it's more challenging than just plug-n-play Dave's code.

I'm going to write some notes down because I'm about to go on vacation, and I'll need a reminder when I get back.

  • The hashrate value itself is calculated in db/dbtypes/conversion.go as CalculateHashRate. However, it's calculated in PH/s for some reason. It's simple to just remove the final / 1000000 so that it's now calculated H/s, but I'm not sure what else is using this code and if changing it will break things. In a pinch, I could also just multiply the value by 1e6, but that feels bad.
  • Once you have the true H/s value, you have to Humanize it. That part is pretty easy. There's basically two options:
    • use the already-included dependency of "github.com/dustin/go-humanize", and call `humanize.SIWithDigits(hashrate, 8, "H/s")
    • Use Dave's code with some minor modifications
  • Unfortunately, both of the two options above return Strings with the unit attached. And the Home page itself has a lot of formatting applied. The first few digits are a different weight/size, and the PH/s unit itself is another style. So I got stuck trying to figure out different ways to solve the formatting issues.
  • In addition to home.tmpl, homepage_controller.js also needs to be updated so that anyone viewing with JS active doesn't get a different output
  • All this stuff needs to be double-checked that it doesn't break the hash rate values and scaling (especially on the Y axis) of the charts.

If anyone wants to pick this up in the next two weeks, feel free, or I'll just continue when I get back.

@ukane-philemon
Copy link
Contributor

If anyone wants to pick this up in the next two weeks, feel free,

@matthawkins90 are you back from vacation? I could look into this issue if you’re still away.

@matthawkins90
Copy link
Contributor

I'm back, haha. Just haven't prioritized this yet. I was actually going to take a stab at it again this week based on Xaur's feedback about how the difficulty could be formatted.

The difficulty on the front page is one thing, but the difficulty in the charts / graphs seems like it's a whole lot harder and I don't even know where to begin.

@ukane-philemon
Copy link
Contributor

Oh, okay. Sounds good.

@matthawkins90
Copy link
Contributor

@ukane-philemon I just finished the difficulty, where I ended up just using threeSigFigs, which is possible because it doesn't need any units.

But since the hash rate requires units, I don't think you can use threeSigFigs for it, and might need to use Dave's original code at the top. Can you take care of that?

@ukane-philemon
Copy link
Contributor

matthawkins90 commented 14 hours ago
@ukane-philemon I just finished the difficulty, where I ended up just using threeSigFigs, which is possible because it doesn't need any units.

Do you have a PR for this yet?

@matthawkins90
Copy link
Contributor

#1975

I'll be honest, I'm not sure why the build is failing.

@ukane-philemon
Copy link
Contributor

#1975

I'll be honest, I'm not sure why the build is failing.

I think the Go test failure is not from you, but the JS, you can fix it by running npm run build and committing the changes. You edited a js file and now the hash does not match what we have in the script tag.

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

No branches or pull requests

4 participants