npm total statistic is wrong
- Dominant language
- JavaScript
- Stars
- 27.2k
- Forks
- 5.6k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 46
Description
I'll explain the problem on an example. https://shields.io/ displays the statistic of "express" package as an example. It shows the value 195M (see https://img.shields.io/npm/dt/express.svg) as the total statistic of express downloads.

The [npm-provider.js](https://github.com/badges/shields/blob/master/lib/npm-provider.js) uses [package download counts](https://github.com/npm/registry/blob/master/docs/download-counts.md) API to get NPM download statistic via request like
```
GET https://api.npmjs.org/downloads/point/{period}[/{package}]
```
One can easy verify that https://api.npmjs.org/downloads/point/2015-01-01:2017-12-31/express returns (today)
```json
{"downloads":194785100,"start":"2016-05-20","end":"2017-11-20","package":"express"}
```
and 194785100 corresponds 195M displayed in the badge https://img.shields.io/npm/dt/express.svg. The problem is that one supposes that "2016-05-20" is *really starting point of all downloads*. On the other side one can make another request https://api.npmjs.org/downloads/point/2014-01-01:2016-05-19/express, which returns
```json
{"downloads":57328706,"start":"2015-01-10","end":"2016-05-19","package":"express"}
```
(where "2016-05-19" is the date previous to "2016-05-20" from the `"start"` of the previous response). One more request https://api.npmjs.org/downloads/point/2014-01-01:2015-01-10/express returns
```json
{"downloads":0,"start":"2015-01-10","end":"2015-01-10","package":"express"}
```
0 downloads. As the result, the total downloads in the interval from 2014-01-01 till today would be 194785100 + 57328706 = **252113806** and **252M instead of 195M would be the correct number of downloads of express**.
As the reference one can open the page https://npm-stat.com/charts.html?package=express&from=2014-01-01&to=2017-11-19 and see exactly the same value:

Contributor guide
Research direction
Start in lib/npm-provider.js and review the npm download-counts API documentation. Reproduce the period requests for express and compare the provider's result with the earlier download interval described in the issue. Done means the npm total-download badge includes the available downloads before the API response's reported start date and has coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100