-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Instead of the average build time, time elapsed since last …
…build is displayed. The average build time is now only displayed when the build is in progress. Closes #63 and closes #120.
- Loading branch information
Showing
13 changed files
with
195 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ain/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/Duration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration; | ||
|
||
abstract public class Duration { | ||
|
||
protected final long duration; | ||
|
||
public Duration(long milliseconds) { | ||
this.duration = milliseconds; | ||
} | ||
|
||
abstract public String toString(); | ||
|
||
public boolean greaterThan(Duration otherDuration) { | ||
return duration > otherDuration.toLong(); | ||
} | ||
|
||
private long toLong() { | ||
return duration; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...martcodeltd/jenkinsci/plugins/buildmonitor/viewmodel/duration/DurationInMilliseconds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.duration; | ||
|
||
public class DurationInMilliseconds extends Duration { | ||
|
||
public DurationInMilliseconds(long milliseconds) { | ||
super(milliseconds); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(duration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
angular. | ||
module('buildMonitor.filters', []). | ||
|
||
filter('estimatedTimeElapsedSince', function() { | ||
var seconds = 1000, | ||
minutes = 60 * seconds, | ||
hours = 60 * minutes, | ||
days = 24 * hours, | ||
months = 30 * days, | ||
years = 12 * months, | ||
|
||
unitsOfTime = [ | ||
{ divisor: seconds, singular: "%d second ago", plural: "%d seconds ago" }, | ||
{ divisor: minutes / seconds, singular: "%d minute ago", plural: "%d minutes ago" }, | ||
{ divisor: hours / minutes, singular: "%d hour ago", plural: "%d hours ago" }, | ||
{ divisor: days / hours, singular: "%d day ago", plural: "%d days ago" }, | ||
{ divisor: months / days, singular: "%d month ago", plural: "%d months ago" }, | ||
{ divisor: years / months, singular: "over a year ago", plural: "hasn't run in ages!" } | ||
]; | ||
|
||
function humanFriendly(remainder, unitOfTime) { | ||
var rounded = Math.round(remainder); | ||
|
||
return (rounded === 1 ? unitOfTime.singular : unitOfTime.plural).replace("%d", rounded); | ||
} | ||
|
||
function approximate(remainder, unitOfTime, tail) { | ||
return (tail.length === 0 || remainder < tail[0].divisor) ? | ||
humanFriendly(remainder, unitOfTime) : | ||
approximate(remainder / tail[0].divisor, tail[0], tail.slice(1)); | ||
} | ||
|
||
return function(ago) { | ||
switch(true) { | ||
case (ago <= 30 * seconds): return "just now :-)"; | ||
case (ago <= 5 * minutes): return "a moment ago"; | ||
default: return approximate(ago / unitsOfTime[0].divisor, unitsOfTime[0], unitsOfTime.slice(1)); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/javascript/unit/filters/estimatedTimeElapsedSinceSpec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
describe('buildMonitor', function () { | ||
describe('buildMonitor.filters', function () { | ||
describe('estimatedTimeElapsedSince', function () { | ||
var milliseconds = 1, | ||
seconds = 1000 * milliseconds, | ||
minutes = 60 * seconds, | ||
hours = 60 * minutes, | ||
days = 24 * hours, | ||
months = 30 * days, | ||
years = 12 * months; | ||
|
||
beforeEach(module('buildMonitor.filters')); | ||
|
||
it('converts time in milliseconds to something more user-friendly (under 5 minutes)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter(0 * minutes)).toEqual("just now :-)"); | ||
expect(estimatedTimeElapsedSinceFilter(0.5 * minutes)).toEqual("just now :-)"); | ||
expect(estimatedTimeElapsedSinceFilter(3 * minutes)).toEqual("a moment ago"); | ||
expect(estimatedTimeElapsedSinceFilter(4.5 * minutes)).toEqual("a moment ago"); | ||
})); | ||
|
||
it('approximates to the nearest minute (under 1 hour)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter( 5.5 * minutes)).toEqual("6 minutes ago"); | ||
expect(estimatedTimeElapsedSinceFilter(10.75 * minutes)).toEqual("11 minutes ago"); | ||
expect(estimatedTimeElapsedSinceFilter(30 * minutes)).toEqual("30 minutes ago"); | ||
expect(estimatedTimeElapsedSinceFilter(59 * minutes)).toEqual("59 minutes ago"); | ||
})); | ||
|
||
it('approximates to the nearest hour (under 1 day)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter(61 * minutes)).toEqual("1 hour ago"); | ||
expect(estimatedTimeElapsedSinceFilter(1.3 * hours )).toEqual("1 hour ago"); | ||
expect(estimatedTimeElapsedSinceFilter(1.5 * hours )).toEqual("2 hours ago"); | ||
expect(estimatedTimeElapsedSinceFilter( 2 * hours )).toEqual("2 hours ago"); | ||
expect(estimatedTimeElapsedSinceFilter(17.61 * hours )).toEqual("18 hours ago"); | ||
})); | ||
|
||
it('approximates to the nearest day (under 1 month)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter( 1.25 * days)).toEqual("1 day ago"); | ||
expect(estimatedTimeElapsedSinceFilter( 2 * days)).toEqual("2 days ago"); | ||
expect(estimatedTimeElapsedSinceFilter( 7 * days)).toEqual("7 days ago"); | ||
})); | ||
|
||
it('approximates to the nearest month (under 1 year)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter(31 * days )).toEqual("1 month ago"); | ||
expect(estimatedTimeElapsedSinceFilter( 2.3 * months)).toEqual("2 months ago"); | ||
expect(estimatedTimeElapsedSinceFilter(11.7 * months)).toEqual("12 months ago"); | ||
})); | ||
|
||
it('approximates to the nearest year (boy, I really hope no one needs this range!)', inject(function (estimatedTimeElapsedSinceFilter) { | ||
expect(estimatedTimeElapsedSinceFilter(13 * months)).toEqual("over a year ago"); | ||
expect(estimatedTimeElapsedSinceFilter(25 * months)).toEqual("hasn't run in ages!"); | ||
expect(estimatedTimeElapsedSinceFilter(5 * years)).toEqual("hasn't run in ages!"); | ||
})); | ||
}); | ||
}); | ||
}); |
cd3d664
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the quirky sayins in the Javascript, just curious why all the math on the JS side as opposed to it being passed from the backend using built-in Jenkins functions ... my own version/change using
Util.getPastTimeString
:Brantone@11420f1
@jan-molak Curious on ^^ ... all that JS seems bit over-kill if Jenkins has the "time since last" already available.