From 6eeed553056126e258cdffc9d7a55bf4b556170b Mon Sep 17 00:00:00 2001 From: Aslihan Date: Mon, 3 Aug 2020 23:08:05 +0300 Subject: [PATCH 1/3] Refactor html template --- template/template.go | 681 +++++++++++-------------------------------- 1 file changed, 177 insertions(+), 504 deletions(-) diff --git a/template/template.go b/template/template.go index 5cdf8f0..a409a41 100644 --- a/template/template.go +++ b/template/template.go @@ -10,535 +10,177 @@ func GetHtml() string { four-key Metrics - - - + + }) + - - - -
-

four-key Metrics

-
{repositoryName} | {teamName} | {startDate} - {endDate}
-
Deployment Frequencies
-
+ canvas { + margin: 50px 0; + } -
Lead Times
-
+ .button-wrapper { + margin: auto; + width: max-content; + } -
Mean Times
-
+ .btn-chart { + appearance: none; + border: 1px solid #767676; + background-color: transparent; + color: #767676; + padding: 7px 14px; + margin: 0 5px; + outline: none; + cursor: pointer; + } -
Fail Percentages
-
-
+ .btn-chart:hover { + border: 1px solid #2185d0; + color: #2185d0; + } + + + +
+

four-key Metrics

+
allTeams | allTeams | 2019-01-01 - 2021-01-01
+ +
+
Deployment Frequencies
+ +
+ + + +
+
+ +
Lead Times
+ + +
Mean Times
+ + + +
Fail Percentages
+ +
- - ` } From a7b9bba480d6dbd4911e739fd294ad929934f637 Mon Sep 17 00:00:00 2001 From: Aslihan Date: Wed, 5 Aug 2020 00:15:17 +0300 Subject: [PATCH 2/3] Add weekly chart --- template/template.go | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/template/template.go b/template/template.go index a409a41..7daaace 100644 --- a/template/template.go +++ b/template/template.go @@ -33,12 +33,24 @@ func GetHtml() string { deploymentFrequencyChart: "" } + + function getWeek(date) { + const dayNumber = (date.getDay() + 6) % 7; + date.setDate(date.getDate() - dayNumber + 3); + + let tempDate = new Date(date.getFullYear(), 0, 4); + let dayDiff = (date - tempDate) / 86400000; + return 1 + Math.ceil(dayDiff / 7); + } + function prepareData(data) { let newData = Object.assign([], data) let months = [] let years = [] + let weeks = [] let days = [] let monthly = [] + let weekly = [] newData.sort(function (a, b) { return new Date(a.date) - new Date(b.date); @@ -50,6 +62,8 @@ func GetHtml() string { const month = ALL_MONTHS_SHORT[date.getMonth()] const day = date.getDate() const year = date.getFullYear() + const week = getWeek(date) + if (!item.month) { item.month = month } @@ -59,6 +73,9 @@ func GetHtml() string { if (!item.year) { item.year = year } + if (!item.week) { + item.week = week + } if (!days.includes(day)) { days.push(day) } @@ -68,6 +85,10 @@ func GetHtml() string { if (!years.includes(year)) { years.push(year) } + if (!weeks.includes(week)) { + weeks.push({ week, year }) + } + }); years.forEach(year => { @@ -75,10 +96,24 @@ func GetHtml() string { monthly[year] = [] } - let totalValue = 0 - totalValue = newData.filter(item => item.year == year).reduce(function getSum(total, item) { - return total + parseInt(item.value); - }, totalValue) + if (!weekly.includes(year)) { + weekly[year] = [] + for (let i = 0; i < 52; i++) { + weekly[year].push({ + label: i + 1, + totalValue: 0 + }) + } + } + + weeks.forEach((week) => { + totalValue = 0 + let totalWeeks = weeks.filter(item => + item.week == week.week && year == week.year + ) + weekly[year][week.week - 1].totalValue = totalWeeks.length + }); + ALL_MONTHS_SHORT.forEach(mon => { totalValue = 0 @@ -90,14 +125,14 @@ func GetHtml() string { label: mon, totalValue }) - }); - }); + return { data: newData, - monthly + monthly, + weekly } } @@ -109,11 +144,11 @@ func GetHtml() string { var red = randomNum(); var green = randomNum(); var blue = randomNum(); - return red + ", " + green + ", 235"; + return red + ", " + green + ", " + blue; } function getDataSets(data) { - const a = Object.entries(data).map(([key, values]) => { + return Object.entries(data).map(([key, values]) => { return { label: key, data: values.map(item => item.totalValue), fill: false, @@ -126,8 +161,6 @@ func GetHtml() string { borderWidth: 5 } }) - - return a } function getChartData(chartId, type) { @@ -135,7 +168,7 @@ func GetHtml() string { const activeLabelType = LABEL_TYPES.find(labelType => labelType == type) return { - labels: activeLabelType == "monthly" ? ALL_MONTHS_SHORT : Object.keys(data[activeLabelType]), + labels: Object.values(data[activeLabelType])[0].map(item => item.label), datasets: getDataSets(data[activeLabelType]) } } From 7faa1682b14b5dc27a2d2501f064e6749de78137 Mon Sep 17 00:00:00 2001 From: Aslihan Date: Sat, 8 Aug 2020 21:49:16 +0300 Subject: [PATCH 3/3] Refactor chart --- helpers/repository_metric_helper.go | 4 +- template/template.go | 360 ++++++++++++++++++---------- 2 files changed, 241 insertions(+), 123 deletions(-) diff --git a/helpers/repository_metric_helper.go b/helpers/repository_metric_helper.go index e8f1942..7ecc7f2 100644 --- a/helpers/repository_metric_helper.go +++ b/helpers/repository_metric_helper.go @@ -85,8 +85,8 @@ func CalculateMetrics(repo *git.Repository, request MetricsRequest) (FourKeyMetr tagMetricDto := TagMetricDto{ TagName: tagNameParse[len(tagNameParse)-1], TagDate: tagMetricDateRange.tagDate, - MeanTimeRestoreAverage: GetSecondsToHour(tagMetricDateRange.tagMeanTimeRestoreAverageSeconds), - LeadTime: GetSecondsToHour(tagMetricDateRange.tagLeadTimeSeconds), + MeanTimeRestoreAverage: tagMetricDateRange.tagMeanTimeRestoreAverageSeconds, + LeadTime: tagMetricDateRange.tagLeadTimeSeconds, ChangeFailPercentage: tagMetricDateRange.tagChangeFailPercentage, } tagMetricDtoList = append(tagMetricDtoList, tagMetricDto) diff --git a/template/template.go b/template/template.go index 7daaace..17d97cf 100644 --- a/template/template.go +++ b/template/template.go @@ -14,90 +14,97 @@ func GetHtml() string { + - - - -
-

four-key Metrics

-
allTeams | allTeams | 2019-01-01 - 2021-01-01
- -
-
Deployment Frequencies
- -
- - - -
-
- -
Lead Times
- - -
Mean Times
- - - -
Fail Percentages
- -
+ + + +
+

four-key Metrics

+
allTeams | allTeams | 2019-01-01 - 2021-01-01
+ +
+
Deployment Frequencies
+ +
+ + + +
+
+ +
+
Lead Times
+ +
+ + + +
+
+ +
+
Mean Times
+ +
+ + + +
+
+ +
+
Fail Percentages
+ +
+ + + +
+
+