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

Spike bookmark: Show deviation from reported averaged #23

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Public/FourKeyMetrics.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,22 @@ function Get-BucketedMetricsForPeriod($releaseMetrics, $endDate) {

if ($releaseCount -gt 0){
$deploymentFrequencyDays = ($releaseMetrics | ForEach-Object {$_.Interval.TotalDays} | Measure-Object -Average).Average;
$deploymentFrequencyLow = ($releaseMetrics | ForEach-Object {$_.Interval.TotalDays} | Measure-Object -Minimum).Minimum;
$deploymentFrequencyHigh = ($releaseMetrics | ForEach-Object {$_.Interval.TotalDays} | Measure-Object -Maximum).Maximum;
$failRate = $failedreleaseCount / $releaseCount
$leadTimes = $releaseMetrics | Where-Object {$null -ne $_.CommitAges } | % { $_.CommitAges };
$leadTimeMedian = Get-Median($leadTimes)
$leadTimes = $releaseMetrics | Where-Object {$null -ne $_.CommitAges } | ForEach-Object { $_.CommitAges };
$leadTimeMedian = Get-Median($leadTimes)
$leadTimeLow = ($leadTimes | ForEach-Object {$_.TotalDays} | Measure-Object -Minimum).Minimum;
$leadTimeHigh = ($leadTimes | ForEach-Object {$_.TotalDays}| Measure-Object -Maximum).Maximum
}
else {
$deploymentFrequencyDays = $null;
$deploymentFrequencyLow = $null;
$deploymentFrequencyHigh = $null;
$failRate = $null;
$leadTimeMedian = $null;
$leadTimeLow = $null;
$leadTimeHigh = $null;
}

if ($failedreleaseCount -gt 0){
Expand All @@ -272,8 +280,12 @@ function Get-BucketedMetricsForPeriod($releaseMetrics, $endDate) {
EndDate = $endDate
Releases = $releaseCount;
DeploymentFrequencyDays = $deploymentFrequencyDays;
DeploymentFrequencyLow = $deploymentFrequencyLow;
DeploymentFrequencyHigh = $deploymentFrequencyHigh;
MttrHours = $mttrAverage;
LeadTimeDays = $leadTimeMedian;
LeadTimeLow = $leadTimeLow;
LeadTimeHigh = $leadTimeHigh;
FailRate = $failRate;
}
}
Expand Down Expand Up @@ -345,7 +357,7 @@ function global:New-FourKeyMetricsReport {
}

function ConvertTo-JsonWithJavascript($period){
"[new Date($(DateTimeToTimestamp($period.EndDate))), $(ValueOrNull($period.DeploymentFrequencyDays)), $(ValueOrNull($period.LeadTimeDays)), $(ValueOrNull($period.FailRate)), $(ValueOrNull($period.MttrHours))]"
"[new Date($(DateTimeToTimestamp($period.EndDate))), $(ValueOrNull($period.DeploymentFrequencyDays)), $(ValueOrNull($period.DeploymentFrequencyLow)), $(ValueOrNull($period.DeploymentFrequencyHigh)), $(ValueOrNull($period.LeadTimeDays)), $(ValueOrNull($period.LeadTimeLow)), $(ValueOrNull($period.LeadTimeHigh)), $(ValueOrNull($period.FailRate)), $(ValueOrNull($period.MttrHours))]"
}

function ValueOrNull($value)
Expand Down
29 changes: 20 additions & 9 deletions Public/FourKeyMetricsTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
var data = new google.visualization.DataTable();
data.addColumn("date", "EndDate");
data.addColumn("number", "Deployment Frequency");
data.addColumn({type:"number", id:"i0", role:'interval'});
data.addColumn({type:"number", id:"i1", role:'interval'});
data.addColumn("number", "Delivery Lead Time");
data.addColumn({type:"number", id:"i0", role:'interval'});
data.addColumn({type:"number", id:"i1", role:'interval'});
data.addColumn("number", "Change Failure Rate");
data.addColumn("number", "Mean Time to Recovery");

Expand All @@ -30,20 +34,22 @@
]);

const charts = [
[1, "deploy-freq", "Days", "#336dc2"],
[2, "lead-time", "Days", "#128024"],
[3, "fail-rate", "Percent", "#c00", "percent"],
[4, "mttr", "Hours", "#fc9003"]
[1, 2, 3, "deploy-freq", "Days", "#336dc2"],
[4, 5, 6, "lead-time", "Days", "#128024"],
[7, 7, 7, "fail-rate", "Percent", "#c00", "percent"],
[8, 8, 8, "mttr", "Hours", "#fc9003"]
];

charts.forEach(c => {
const [colIndex, elementId, vAxisTitle, color, format] = c;
const [colIndex, lowColIndex, highColIndex, elementId, vAxisTitle, color, format] = c;

var dataView = new google.visualization.DataView(data);
dataView.setColumns([0, colIndex]);
var chart = new google.visualization.LineChart(
dataView.setColumns([0, colIndex, lowColIndex, highColIndex]);

var chart = new google.visualization.ComboChart(
document.getElementById(elementId).getElementsByClassName("content")[0]
);

chart.draw(dataView, {
vAxis: { title: vAxisTitle, format, minValue: 0, maxValue: 1 },
legend: { position: "none" },
Expand All @@ -52,7 +58,12 @@
pointSize: 6,
trendlines: { 0: { pointSize: 0 }},
interpolateNulls: true,
hAxis: {minValue: REPORTSTARTDATE_PLACEHOLDER, maxValue: REPORTENDDATE_PLACEHOLDER}
hAxis: {minValue: REPORTSTARTDATE_PLACEHOLDER, maxValue: REPORTENDDATE_PLACEHOLDER},
curveType: 'function',
interval: {
'i0': { style:'area', color: color},
'i1': { style:'area', color: color}
}
});
});
}
Expand Down
16 changes: 14 additions & 2 deletions Tests/FourKeyMetrics.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ Describe 'Get-BucketedMetricsForPeriod' {
It 'should return an empty set of metrics' {
$bucketedMetrics.Releases | Should -Be "0" # Explicitly provide zero releases
$bucketedMetrics.DeploymentFrequencyDays | Should -Be $null
$bucketedMetrics.DeploymentFrequencyLow | Should -Be $null
$bucketedMetrics.DeploymentFrequencyHigh | Should -Be $null
$bucketedMetrics.MttrHours | Should -Be $null
$bucketedMetrics.LeadTimeDays | Should -Be $null
$bucketedMetrics.LeadTimeLow | Should -Be $null
$bucketedMetrics.LeadTimeHigh | Should -Be $null
$bucketedMetrics.FailRate | Should -Be $null
$bucketedMetrics.EndDate | Should -Be $endDate
}
Expand All @@ -68,8 +72,12 @@ Describe 'Get-BucketedMetricsForPeriod' {

$bucketedMetrics.Releases | Should -Be "1" # Explicitly provide one release
$bucketedMetrics.DeploymentFrequencyDays | Should -Be "14" # Only 1 release, so the deployment frequency should be the same as the release interval
$bucketedMetrics.DeploymentFrequencyHigh | Should -Be "14"
$bucketedMetrics.DeploymentFrequencyLow | Should -Be "14"
$bucketedMetrics.MttrHours | Should -Be $null # No recoveries in the provided dataset
$bucketedMetrics.LeadTimeDays | Should -Be "1" # Release has a lead time of one day
$bucketedMetrics.LeadTimeLow | Should -Be "1"
$bucketedMetrics.LeadTimeHigh | Should -Be "1"
$bucketedMetrics.FailRate | Should -Be "0" # No failures
$bucketedMetrics.EndDate | Should -Be $endDate
}
Expand All @@ -96,7 +104,7 @@ Describe 'Get-BucketedMetricsForPeriod' {
ToDate = [DateTime]"2019-05-21"
Interval = New-Timespan -D 4;
IsFix = $true;
CommitAges = @(New-Timespan -H 24);
CommitAges = @(New-Timespan -H 12);
}

$releaseOne = [PSCustomObject]@{
Expand All @@ -106,7 +114,7 @@ Describe 'Get-BucketedMetricsForPeriod' {
ToDate = [DateTime]"2019-05-17"
Interval = New-Timespan -D 1;
IsFix = $false;
CommitAges = @(New-Timespan -H 24);
CommitAges = @(New-Timespan -H 36);
}

$releases = @($releaseTwo, $releaseOne)
Expand All @@ -118,8 +126,12 @@ Describe 'Get-BucketedMetricsForPeriod' {
It 'should calculate the correct bucketed metrics' {
$bucketedMetrics.Releases | Should -Be "2" # Explicitly provide two releases
$bucketedMetrics.DeploymentFrequencyDays | Should -Be "2.5" # Release intervals were 1 and 4, so average is 2.5
$bucketedMetrics.DeploymentFrequencyLow | Should -Be "1"
$bucketedMetrics.DeploymentFrequencyHigh | Should -Be "4"
$bucketedMetrics.MttrHours | Should -Be 96 # Single recovery took four whole days
$bucketedMetrics.LeadTimeDays | Should -Be "1" # Both releases have a lead time of one day
$bucketedMetrics.LeadTimeLow | Should -Be "0.5"
$bucketedMetrics.LeadTimeHigh | Should -Be "1.5"
$bucketedMetrics.FailRate | Should -Be "0.5" # One of two releases was a failure
$bucketedMetrics.EndDate | Should -Be $endDate
}
Expand Down