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

NPM monthly and weekly downloads #939

Closed
calebcartwright opened this issue Apr 12, 2017 · 23 comments · Fixed by #958
Closed

NPM monthly and weekly downloads #939

calebcartwright opened this issue Apr 12, 2017 · 23 comments · Fixed by #958
Labels
good first issue New contributors, join in! service-badge Accepted and actionable changes, features, and bugs
Milestone

Comments

@calebcartwright
Copy link
Member

Not sure when it started but looks like all of the npm total downloads badges are incorrectly showing as zero. Monthly downloads appear to still be working. I noticed this on my own project but a few examples of well known packages below:

https://img.shields.io/npm/dt/express.svg
https://img.shields.io/npm/dt/angular.svg
https://img.shields.io/npm/dt/mocha.svg

https://img.shields.io/npm/dm/express.svg
https://img.shields.io/npm/dm/angular.svg
https://img.shields.io/npm/dm/mocha.svg

@mesaugat
Copy link
Contributor

Yes. Looks like it's the same for PyPi.

PyPI
PyPI
PyPI

@mitchallen
Copy link

mitchallen commented Apr 13, 2017

It looks like the code for npm/dt is making a call like this: https://api.npmjs.org/downloads/range/1000-01-01:3000-01-01/uuid which returns: {"error":"exceeded max days of 365"}

So since there is no downloads property, this line in server.js just converts to 0:
var downloads = JSON.parse(buffer).downloads || 0;

Note that npm/dm works fine. Internally it makes a call like this: https://api.npmjs.org/downloads/point/last-month/uuid that properly returns: {"downloads":19184120,"start":"2017-03-14","end":"2017-04-12","package":"uuid"}

@mesaugat
Copy link
Contributor

Looks like they have updated the API and now only support download counts for a year or not more than 365 days.

This works:
https://api.npmjs.org/downloads/range/2017-01-01:2018-01-01/uuid

We'll have to make multiple requests for counting total number of downloads for a package. It's better to switch to a downloads/year metric now.

@espadrine
Copy link
Member

Makes sense. Using https://api.npmjs.org/downloads/range/ is not that useful with this restriction. Let's switch to https://api.npmjs.org/downloads/point/last-year/.

For compatibility purposes, let's have npm/dt return the yearly count, as it's the best we can do. If we again get a way to display dt, we'll switch it to give the more accurate result.

And let's add an npm/dy badge.

@mesaugat
Copy link
Contributor

Seems good to me 👍

@espadrine
Copy link
Member

@mesaugat As for PyPi, there's little we can do for now: pypi/legacy#396 (comment)
Sometimes badges die…
The corresponding issue is #716.

@mesaugat
Copy link
Contributor

@espadrine I see, thanks!

I've not looked at the code properly but I think I will be able to work on npm/dt and npm/dy as you said.

@paulmelnikow paulmelnikow added bug Bugs in badges and the frontend needs-upstream-help Not actionable without help from a service provider labels Apr 13, 2017
@paulmelnikow
Copy link
Member

Am I right that npm/dt used to return the cumulative total downloads? That's what it looks like from a query like this:

https://api.npmjs.org/downloads/range/1000-01-01:3000-01-01/uuid

I could reach out to the npm registry folks. This badge seems popular with developers. Maybe they would add an endpoint for us.

@mesaugat
Copy link
Contributor

Yes, it's quite popular. If we can get an endpoint it would be awesome.

maxkfranz added a commit to cytoscape/cytoscape.js that referenced this issue Apr 13, 2017
maxkfranz added a commit to cytoscape/cytoscape.js that referenced this issue Apr 13, 2017
@mitchallen
Copy link

For npm talk to Benjamin Coe: https://github.com/bcoe https://twitter.com/BenjaminCoe

@mesaugat
Copy link
Contributor

Here's the GitHub repo: https://github.com/npm/download-counts

Reference: http://blog.npmjs.org/post/78719826768/download-counts-are-back

@mitchallen
Copy link

Via Twitter:

Benjamin Coe
@benjamincoe
Apr 13

@mitchallen @espadrine we're going to lift the limit for the time being, and will introduce an all-time shorthand soon too.

@paulmelnikow
Copy link
Member

Nice!

@paulmelnikow
Copy link
Member

Looks like we will need a code change:

https://api.npmjs.org/downloads/range/1000-01-01:3000-01-01/uuid

{
    error: "unknown error"
}

https://api.npmjs.org/downloads/range/2015-01-01:2018-01-01/uuid

{
start: "2015-01-01",
end: "2017-04-14",
package: "uuid",
downloads: [
{
downloads: 0,
day: "2015-01-01"
},
{
downloads: 0,
day: "2015-01-02"
},
{
downloads: 0,
day: "2015-01-03"
},
{
downloads: 0,
day: "2015-01-04"
},
...

@bcoe
Copy link
Contributor

bcoe commented Apr 13, 2017

@paulmelnikow I'm adding a change to protect you from this query; should be out in 10 minutes, will keep you updated.

@bcoe
Copy link
Contributor

bcoe commented Apr 13, 2017

okay, things should magically start working again; I've pinned dates to our epoch, and an appropriate point in the future, so that requesting 1000:3000 doesn't result in an expensive query.

@paulmelnikow
Copy link
Member

dt badges are back! Thanks for the fast response!

@mesaugat
Copy link
Contributor

Great, we should add a downloads/week and a downloads/year badge for npm too.

@paulmelnikow
Copy link
Member

Agreed. Would you like to open a PR?

@mesaugat
Copy link
Contributor

Sure, I will look into it when I find some time.

@paulmelnikow paulmelnikow changed the title NPM total downloads badge shows 0 for all packages NPM monthly and weekly downloads Apr 13, 2017
@paulmelnikow paulmelnikow added service-badge Accepted and actionable changes, features, and bugs and removed bug Bugs in badges and the frontend needs-upstream-help Not actionable without help from a service provider labels Apr 13, 2017
@calebcartwright
Copy link
Member Author

calebcartwright commented Apr 14, 2017

just want to say well done folks. thanks for getting this taken care of so quickly!

@elect86
Copy link

elect86 commented Dec 13, 2017

sorry for the ot

but how am I supposed to use the npm badge?
[![npm](https://img.shields.io/npm/dm/localeval.svg)]()

I tried
https://img.shields.io/npm/dm/kotlin-graphics/kotlin-unsigned.svg

but returns 0..

@paulmelnikow
Copy link
Member

@elect86 Could you open a new issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue New contributors, join in! service-badge Accepted and actionable changes, features, and bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants