-
Notifications
You must be signed in to change notification settings - Fork 6
/
npm_download_counts.juttle
56 lines (46 loc) · 1.77 KB
/
npm_download_counts.juttle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
input npm_package: text -default "juttle" -label "NPM Package";
input start: date -default :2016-01-01: -label "Start Date";
input end: date -default :today: -label "End Date";
function dayof(date) {
return Date.format(date, "YYYY-MM-DD");
}
// fetch the data
sub fetch() {
read http -url 'https://api.npmjs.org/downloads/range/${dayof(start)}:${dayof(end)}/${npm_package}' -timeField "day" -rootPath "downloads"
}
// add a simple title using markdown
sub title() {
emit -points [{title: '# Download Counts for ${npm_package}'}]
| view markdown -row 0
}
// Sum up the data by the given interval
sub rollup(interval) {
reduce -every interval value=sum(downloads) | put name='downloads'
}
// Add a rolling average series
sub trend(interval, window, label) {
(pass; reduce -every interval -over window value=Math.floor(avg(value)), name=label)
}
sub chart(interval, label, row, col, color) {
view timechart
-keyField 'name'
-series [{name: 'downloads', color: color, geom: 'bars'},
{color: '#909552'} ]
-title 'NPM Downloads per ${label} for ${npm_package}'
-yScales.primary.label "Download Count"
-downsample false
-interval interval
-row row -col col
}
title;
fetch
| (
rollup -interval :1d: | trend -interval :1d: -window :28d: -label '28 day trend'
| chart -interval :1d: -label 'day' -row 1 -col 0 -color '#A4B946';
rollup -interval :1w: | trend -interval :1w: -window :10w: -label '10 week trend'
| chart -interval :1w: -label 'week' -row 1 -col 1 -color '#79E0CB';
rollup -interval :1M:
| chart -interval :1M: -label 'month' -row 2 -col 0 -color '#666E4C';
rollup -interval :1y:
| chart -interval :1y: -label 'year' -row 2 -col 1 -color '#4E8DB8';
)