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

feat(956) human readable estimates (#956) #1176

Merged
merged 12 commits into from
Oct 9, 2018

Conversation

sanderkoenders
Copy link
Member

Adds human readable estimates to the progressbar during stryker testing.

resolves #956

@ghost ghost assigned sanderkoenders Oct 6, 2018
@ghost ghost added the 🔎 Needs review label Oct 6, 2018
Copy link
Member

@simondel simondel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I have some small remarks, but they are non-blocking in my opinion :)

const minutes = Math.floor((timeLeft / 60) - (hours * 60));
const seconds = Math.floor(timeLeft - (hours * 3600) - (minutes * 60));

let output = (hours !== 0) ? `${hours}h, ` : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nicer to check for a positive number. If any of our inputs is negative, we will probably end up with a negative timeleft.

@@ -22,18 +22,21 @@ export default class ProgressBarReporter extends ProgressKeeper {
public onMutantTested(result: MutantResult): void {
const ticksBefore = this.progress.tested;
super.onMutantTested(result);

const progressBarContent = Object.assign(this.progress, { etc: this.getEtc() });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use the spread operator here: const progressBarContent = { ...this.progress, etc: this.getEtc() };

@nicojs
Copy link
Member

nicojs commented Oct 7, 2018

Cool PR. I would like to review before merging. 👍

@sanderkoenders
Copy link
Member Author

I refactored a bit of the code to process Simons feedback.

Copy link
Member

@nicojs nicojs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this approach. It also aligns the ProgressAppendOnlyReporter.

I've got some small remarks. One show stopper for me is the leaving out of minutes when there are hours.

if (isFinite(timeLeft)) {
const hours = Math.floor(timeLeft / 3600);
const minutes = Math.floor((timeLeft / 60) - (hours * 60));
const seconds = Math.floor(timeLeft - (hours * 3600) - (minutes * 60));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplification suggestion:

const hours = Math.floor(totalSecondsLeft / 3600); 
const minutes = Math.floor(totalSecondsLeft / 60 % 60);
const seconds = Math.floor(totalSecondsLeft % 60);

@@ -24,5 +26,23 @@ abstract class ProgressKeeper implements Reporter {
this.progress.survived++;
}
}

protected getEtc() {
const timeLeft = Math.floor(this.timer.elapsedSeconds() / this.progress.tested * (this.progress.total - this.progress.tested));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should now be renamed to "totalSecondsLeft", as everything here has to do with "time left"

const seconds = Math.floor(timeLeft - (hours * 3600) - (minutes * 60));

let output = (hours > 0) ? `${hours}h, ` : '';
output += (minutes > 0) ? `${minutes}m, ` : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When hours is greater than 0, but minutes is 0 it means that minutes is left out. Though technically correct, i think it would be clearer if minutes is displayed. For example: 1h, 0m, 20s instead of 1h, 20s.

Suggestion:

if (hours > 0) {
  return `${hours}h, ${minutes}m, ${seconds}s`;
} else if(minutes > 0) {
  return `${minutes}m, ${seconds}s`;
} else {
  return `${seconds}s`
}

expect(progressBar.tick).to.have.been.calledWithMatch({ etc: '10s' });
});

it('should show to an estimate of "1m, 40s" in the progressBar after hundred seconds and 1 mutants tested', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous remark about leaving out minutes.

@sanderkoenders
Copy link
Member Author

@nicojs, should be good to go now.

@nicojs nicojs merged commit 4e76b46 into master Oct 9, 2018
@nicojs nicojs deleted the feat-956-human-readable-estimates branch October 9, 2018 05:14
@nicojs
Copy link
Member

nicojs commented Oct 9, 2018

Awesome 👍

@ghost ghost removed the 🔎 Needs review label Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show ETC as minutes or hours when applicable
3 participants