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

1723 Adopt to locale string for all our number output #2553

Merged
merged 7 commits into from
Jun 28, 2017
Merged

1723 Adopt to locale string for all our number output #2553

merged 7 commits into from
Jun 28, 2017

Conversation

arturmiz
Copy link
Contributor

@arturmiz arturmiz commented Jun 20, 2017

fixes #1723

Hi, I have come across this beginner issue, did some debugging how it can be fixed and I noticed that there are already some changes introduced with #2295. I followed the pattern and used this utility helper across audits which I think required use of it. Waiting for your feedback, thanks! 😅

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

Thanks for this consistency improvement @arturmiz, great first contribution!

@@ -34,7 +35,7 @@ class UnusedBytes extends Audit {
* @return {string}
*/
static bytesToKbString(bytes) {
return Math.round(bytes / KB_IN_BYTES).toLocaleString() + ' KB';
return `${Util.formateBytesToKB(bytes)} KB`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

you inherited this typo but do you want to update it to formatBytesToKB while you're in here? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll add the 'KB' inside this helper, similar how it's done now for milliseconds. One question though as formatMilliseconds helper looks:

 return `${coarseTime.toLocaleString()}${NBSP}ms`;

Which (at least on my machine) renders to sth like 1,000ms so there is no space between number and ms. Should I done it the same way or just ad KB at the end for formatBytestoKB?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's keep the nonbreaking space for now, cc: @paulirish for the final decision, but it's supposed to be a happy medium between a full space and no-space on most machines

@@ -54,7 +55,7 @@ class UnusedBytes extends Audit {
* @return {string}
*/
static bytesToMsString(bytes, networkThroughput) {
return (Math.round(bytes / networkThroughput * 100) * 10).toLocaleString() + 'ms';
return Util.formatMilliseconds( Math.round(bytes / networkThroughput * 100) * 10, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you could reduce this to just formatMilliseconds(bytes / networkThroughout * 1000)

return {
url: item.tag.url,
totalKb: `${Math.round(item.transferSize / 1024)} KB`,
totalMs: `${Math.round((item.endTime - startTime) * 1000)}ms`
totalKb: `${transferSizeKbs} KB`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

could do this inline and remove the Math.round for just formatBytesToKB(item.transferSize, 0)

@@ -35,15 +35,16 @@ class Util {
/**
* Format number.
* @param {number} number
* @param {number} decimalPlaces Number of decimal places to include. Defaults to 1.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: number= since it's optional

}

/**
* @param {number} size
* @param {number=} decimalPlaces Number of decimal places to include. Defaults to 2.
* @param {number} decimalPlaces Number of decimal places to include. Defaults to 2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

keep the = here since it's still optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, my bad, I thought it's a typo that's why I removed it... 😀

Copy link
Collaborator

Choose a reason for hiding this comment

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

haha, no worries! here's a quick guide to the closure types in case you want to decipher what all these comments mean :)

@@ -52,7 +53,7 @@ class Util {

/**
* @param {number} ms
* @param {number=} granularity Controls how coarse the displayed value is, defaults to 10
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@codecov
Copy link

codecov bot commented Jun 26, 2017

Codecov Report

Merging #2553 into master will increase coverage by 0.74%.
The diff coverage is 87.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2553      +/-   ##
==========================================
+ Coverage   84.52%   85.26%   +0.74%     
==========================================
  Files         169      178       +9     
  Lines        5614     5835     +221     
  Branches      774      815      +41     
==========================================
+ Hits         4745     4975     +230     
+ Misses        855      833      -22     
- Partials       14       27      +13
Impacted Files Coverage Δ
lighthouse-core/audits/estimated-input-latency.js 95.65% <ø> (ø) ⬆️
lighthouse-core/audits/load-fast-enough-for-pwa.js 97.61% <ø> (ø) ⬆️
lighthouse-core/audits/first-meaningful-paint.js 93.75% <ø> (ø) ⬆️
lighthouse-core/audits/is-on-https.js 100% <100%> (ø) ⬆️
...se-core/report/v2/renderer/crc-details-renderer.js 95.83% <100%> (ø) ⬆️
lighthouse-core/audits/deprecations.js 100% <100%> (ø) ⬆️
...re/audits/byte-efficiency/byte-efficiency-audit.js 84.61% <100%> (+0.3%) ⬆️
lighthouse-core/report/v2/renderer/util.js 93.44% <100%> (+0.1%) ⬆️
...thouse-core/report/v2/renderer/details-renderer.js 89.28% <100%> (ø) ⬆️
lighthouse-core/audits/dobetterweb/dom-size.js 100% <100%> (ø) ⬆️
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bfcbc30...05b60f0. Read the comment docs.

@paulirish
Copy link
Member

cc @stevepeak btw it came back ⬆️ ⬆️ ⬆️ ⬆️

our .codecov.yml

@patrickhulce
Copy link
Collaborator

@arturmiz are you ready for a re-review? :)

@stevepeak
Copy link

@paulirish looks like the yaml does not exist on this specific commit: https://github.com/arturmiz/lighthouse/blob/329d5a7ab1783f14997fed7e6618c5ac672796ae/.codecov.yml 404's. Codecov always uses the commit's yaml being tested. Thoughts on how to improve this?

@arturmiz
Copy link
Contributor Author

@patrickhulce, anytime 😉

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

looks good to me % nits, nicely done!

@@ -54,7 +55,7 @@ class UnusedBytes extends Audit {
* @return {string}
*/
static bytesToMsString(bytes, networkThroughput) {
return (Math.round(bytes / networkThroughput * 100) * 10).toLocaleString() + 'ms';
return Util.formatMilliseconds(bytes / networkThroughput * 1000, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's keep the granularity at the default 10 here instead of 1

@@ -34,7 +35,7 @@ class UnusedBytes extends Audit {
* @return {string}
*/
static bytesToKbString(bytes) {
return Math.round(bytes / KB_IN_BYTES).toLocaleString() + ' KB';
return Util.formatBytesToKB(bytes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's keep the round effect with 0 decimal places e.g. formatBytesToKB(bytes, 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, are you sure? With 0 decimal places in some cases it will lead to misleading results e.g. instead of having 0.5 KB (50%) it will show 0 KB (50%).

Copy link
Collaborator

Choose a reason for hiding this comment

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

most of these audits should be ignoring savings less than 2-4 KB have you seen some that don't? we should fix those separately :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, is it filtered on the audit level or somewhere further? If on audit level, then I can't see any such condition in this one so it returns everything. I found this example using some fake data in a unit test. I'll add it so you'll know during future fixing that this kind of result shouldn't be there.

@patrickhulce patrickhulce merged commit 5c8d4ec into GoogleChrome:master Jun 28, 2017
@patrickhulce
Copy link
Collaborator

awesome thanks again @arturmiz! 🎉

@arturmiz
Copy link
Contributor Author

Thanks for accepting my PR @patrickhulce ! Happy to help! 😄

@paulirish
Copy link
Member

Thanks for taking on this bug, @arturmiz. We really appreciate it. 😁

@arturmiz arturmiz deleted the 1723-adopt-toLocaleString-for-all-our-number-output branch July 3, 2017 20:19
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

Successfully merging this pull request may close these issues.

Adopt toLocaleString for all our number output
4 participants