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

details.stats.efficiency give me %/100 not only % #960

Closed
trip1e opened this issue Jul 18, 2017 · 11 comments
Closed

details.stats.efficiency give me %/100 not only % #960

trip1e opened this issue Jul 18, 2017 · 11 comments
Labels

Comments

@trip1e
Copy link

trip1e commented Jul 18, 2017

Hello!

My problem is when I use:

		console.log(details.name + ': ' + details.stats.originalSize + ' kb');
		console.log(details.name + ': ' + details.stats.minifiedSize + ' kb');
		console.log(details.name + ': ' + details.stats.timeSpent + ' ms');
		console.log(details.name + ': ' + details.stats.efficiency + '%');

It write this:

style.css: 8597 kb 
style.css: 2514 kb
style.css: 220 ms
style.css: 0.7075724089798767% 

Why efficiency is in %/100?

Thanks for every help!

@scniro
Copy link
Contributor

scniro commented Jul 22, 2017

@trip1e the values seems to be correct and that long decimal indeed represents x/100. You should be able to craft this however you want, though - just play with it. I'm not entirely sure what format you're wanting, but hopefully this could get you on the right track...

`${parseFloat(details.stats.efficiency).toFixed(2) * 100}%` // => 71%

jsfiddle demo

@trip1e
Copy link
Author

trip1e commented Jul 22, 2017

Yes, I want exactly this! Thanks!

But you can fix this:

console.log(output.stats.efficiency); // a ratio of output size to input size (e.g. 25% if content was reduced from 100 bytes to 75 bytes

Becasue it isn’t return %

@scniro
Copy link
Contributor

scniro commented Jul 22, 2017

@trip1e you are welcome! Can you clarify what you mean in your second point? I don't quite follow...

@trip1e
Copy link
Author

trip1e commented Jul 22, 2017

In that code is mistake:
Ratio of output size to input size (e.g. 25%...
It return 0.25 not 25%

@scniro
Copy link
Contributor

scniro commented Jul 22, 2017

but 0.25/1.00 equates to 25%. There is no error in the code above I believe you just need to multiply by 100

@trip1e
Copy link
Author

trip1e commented Jul 22, 2017

Sorry not in code in documentation is good to change it to:
console.log(output.stats.efficiency); // a ratio of output size to input size (e.g. 0.25 if content was reduced from 100 bytes to 75 bytes

@scniro
Copy link
Contributor

scniro commented Jul 22, 2017

I still don't see a problem. Hopefully someone else can chime in here

@jakubpawlowicz
Copy link
Collaborator

@trip1e please feel free to send a PR changing that bit of documentation to what you suggested as it's not clear enough right now, thanks!

@MiguelDebruyne
Copy link

I think what he means is this:

In the docs: (https://github.com/jakubpawlowicz/clean-css)

console.log(output.stats.efficiency); // a ratio of output size to input size (e.g. 25% if content was reduced from 100 bytes to 75 bytes)

Since the produced output of output.stats.efficiency accordig to this example will be 0.25 and NOT 25% he wants to see the docs changed since it is not correct . It should state:

// a ratio of output size to input size (e.g. 0.25 if content was reduced from 100 bytes to 75 bytes)

@jakubpawlowicz
Copy link
Collaborator

Thanks @MiguelDebruyne, that should be it!

@jakubpawlowicz
Copy link
Collaborator

I rephrased it with actual calculation logic in place - fixed on master.

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

No branches or pull requests

4 participants