git ssb

2+

Dominic / yap



Tree: 2e24f63f3e975823d94bc8e83243dd998d9caa5f

Files: 2e24f63f3e975823d94bc8e83243dd998d9caa5f / apis / progress.js

870 bytesRaw
1var u = require('yap-util')
2
3function round (n, p) {
4 return Math.round(n * p) / p
5}
6
7function percent (n) {
8 return (round(n, 1000)*100).toString().substring(0, 4)+'%'
9}
10
11function rate (prog) {
12 if(prog.target == prog.current) return 1
13 return (prog.current - prog.start) / (prog.target - prog.start)
14}
15
16module.exports = function (sbot) {
17 return function (opts, apply) {
18 return function (cb) {
19 sbot.progress(function (err, prog) {
20 var s = '', r = 1
21 for(var k in prog)
22 if(prog[k].current <= prog[k].target) {
23 var _r = rate(prog[k])
24 r = Math.min(r, _r)
25 s += (s ? ', ' : '') + k +': ' + percent(r)
26 }
27 cb(null, ['progress', Object.assign(
28 {value: r, max: 1, title: s},
29 apply.cacheAttrs('/progress', 'prog')
30 )
31 ])
32 })
33 }
34 }
35}
36
37
38
39

Built with git-ssb-web