cnumr / ecoindex_node Goto Github PK
View Code? Open in Web Editor NEWCalculates a webpage ecoindex (from http://www.ecoindex.fr)
License: MIT License
Calculates a webpage ecoindex (from http://www.ecoindex.fr)
License: MIT License
Hi,
I suspect there is an issue (or an inconsistency against the Ecoindex specification) in the current EcoIndex implementation.
As it is currently computed, EcoIndex is between -5 and 94 rather than between 0 and 99 :
<html></html>
containing 3 DOM objects (page + empty header + empty body), generating 1 HTTP request and being 13-byte long) gets an EcoIndex equal to 94.00 (if rounded to 2 digits after the decimal point).I attached a basic HTML page (designed to be a local file), which computes the EcoIndex number and grade for any manually-entered combination of the 3 input parameters (Dom, Req, Size), based on the current JavaScript implementation of the EcoIndex (as GitHub gives it).
Calculateur EcoIndex.html.txt
This page shows that the returned EcoIndex for a (theorical) HTML page with 0 DOM element, 0 HTTP request, 0-byte long gives an EcoIndex of 95 instead of 100.
It also shows that if you sets the worst value for one parameter and 0 for the 2 others, computed EcoIndex is lower than expected: for instance, the combination of 594,601 DOM objects, 0 HTTP requests and 0 kB gives an EcoIndex of 47.5 instead of the expected 50.
edit> After I created this issue, I found Rachel Pellin's EcoIndex simulator (https://rachelwe.github.io/Simulateur-ecoindex/), which shows the very same behaviour as my attached HTML page.
In my opinion, the issue lies in the calculateIndex
function, which should return:
return ((i - 1) + (value - quantiles[i - 1]) / (quantiles[i] - quantiles[i - 1]));
and
return quantiles.length - 1;
instead of:
return (i + (value - quantiles[i - 1]) / (quantiles[i] - quantiles[i - 1]));
and
return quantiles.length;
If such a change were to be made, the grade computation would obviously have to be also altered, by adding 5 to every threshold:
case score >= 80: return 'A';
...
case score >= 10: return 'F';
Incidentally, there is also a typo in the getGreenhouseGasEmmission
function name. The 'm' should not be doubled in the word "Emission".
Best Regards,
Olivier Descout
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.