Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

option to calculate and display an ETA #22

Open
jokeyrhyme opened this issue Feb 7, 2016 · 8 comments
Open

option to calculate and display an ETA #22

jokeyrhyme opened this issue Feb 7, 2016 · 8 comments

Comments

@jokeyrhyme
Copy link

For a CLI project I'm currently engaged in, I looked closely at both gauge and https://github.com/tj/node-progress . I ended up opting for gauge, primarily because my project discovers more work to do as it progresses, which gauge handles perfectly.

However, I would like to eventually display an ETA to my users, especially as the workload stabilises fairly early within the process. Just not early enough to use progress instead.

Is this something that you think is within the scope of this project?
Or should we have some sort of extension mechanism first, and develop ETAs as a third-party extension?

@iarna
Copy link
Contributor

iarna commented Feb 22, 2016

@jokeyrhyme So this was kind of a pain with gauge@1, but with the just released gauge@2 it's pretty easy... it'd be something like

var themes = require('gauge/themes')
var Gauge = require('gauge')
// Add the ability to include eta to all existing and future themes
themes.addToAllThemes({
  eta: function (values, theme, width) {
    // compute the eta here, in the example we just hard code it
    // values.completed has the percent completion in it.
    return 'eta 3m30s'
  }
})
// add a new template that includes the eta
var etaTemplate = [
  {type: 'progressbar', length: 20},
  {type: 'eta', length: 9},
  {type: 'activityIndicator', kerning: 1, length: 1},
  {type: 'section', kerning: 1},
  {type: 'subsection', kerning: 1}
]
var gauge = new Gauge(process.stderr, {template: etaTemplate})

I would be all for adding an eta implementation to the base theme (adding it to the default template will require a little more tought, but I'm hesitantly for it).

@jokeyrhyme
Copy link
Author

@iarna thanks. I see if I can play with this soon. :)

@iarna
Copy link
Contributor

iarna commented Mar 15, 2016

@jokeyrhyme I updated the example to use the updated theme mixin support.

@jokeyrhyme
Copy link
Author

Nice GIF. :)

@iarna
Copy link
Contributor

iarna commented Jun 8, 2016

Thanks =)

I've fiddled a bit with adding ETA support and right now I'm seeing a lot more jitter in the estimates than I'd like, dejittering it requires some place for template functions to store state, which will require a bit of architectural fiddling, but it's on my mind.

@jokeyrhyme
Copy link
Author

Yeah, I've actually started wondering about a React renderer for the console. Not using blessed or ncurses, just something that renders (or re-renders) one line at a time for typical non-interactive console output. Then we could really treat everything on that line as a component, which might make things like progress bars and colours easier to manage. Hmmmm.....

@iarna
Copy link
Contributor

iarna commented Jun 8, 2016

My wip for this is over here:

https://github.com/iarna/gauge/tree/eta

@iarna
Copy link
Contributor

iarna commented Jun 8, 2016

It has render-template.js half way converted to a class as template.js. I'd like to finish that conversion before actually using that code.

It also has a pretty nice implementation of the eta template item in https://github.com/iarna/gauge/blob/eta/eta.js

The jitter was easy enough to cleanup by just not updating the eta every tick (I, arbitrarily, chose once a second, and that feels a lot better).

themes.addToAllThemes({
  'eta': function (values, theme, width) {
    var eta = getEta(this)
    var now = process.hrtime()
    var sinceLast = elapsed(now, eta.last)
    if (sinceLast >= 1 || !eta.remaining || eta.remaining < 1) {
      var tillNow = elapsed(eta.last, eta.created)
      var remaining = (tillNow / values.completed) - tillNow
      eta.last = now
      eta.remaining = remaining
    }
    return formatNumber(eta.remaining)
  },
  'elapsed': function (values, theme, width) {
    var eta = getEta(this)
    return formatNumber(elapsed(process.hrtime(), eta.created))
  }
})

Originally I was using process.uptime() and I'd probably go back to that, which means we can ditch the elapsed function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants