From 418662febedd3dc478b6ed4a6428899ec2931d05 Mon Sep 17 00:00:00 2001 From: e-for-eshaan Date: Tue, 3 Sep 2024 11:39:49 +0530 Subject: [PATCH] directly passes weekly dep-freq to the score function --- .../DoraCards/WeeklyDeliveryVolumeCard.tsx | 26 ++++++++++------- .../DoraMetrics/DoraCards/sharedHooks.tsx | 20 +++++-------- web-server/src/types/resources.ts | 5 +++- web-server/src/utils/dora.ts | 29 +++++++++---------- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/web-server/src/content/DoraMetrics/DoraCards/WeeklyDeliveryVolumeCard.tsx b/web-server/src/content/DoraMetrics/DoraCards/WeeklyDeliveryVolumeCard.tsx index 39194d71..b5fb861d 100644 --- a/web-server/src/content/DoraMetrics/DoraCards/WeeklyDeliveryVolumeCard.tsx +++ b/web-server/src/content/DoraMetrics/DoraCards/WeeklyDeliveryVolumeCard.tsx @@ -18,10 +18,9 @@ import { } from '@/hooks/useStateTeamConfig'; import { useSelector } from '@/store'; import { IntegrationGroup } from '@/types/resources'; -import { merge } from '@/utils/datatype'; import { getSortedDatesAsArrayFromMap } from '@/utils/date'; -import { useAvgWeeklyDeploymentFrequency } from './sharedHooks'; +import { useAvgIntervalBasedDeploymentFrequency } from './sharedHooks'; import { DoraMetricsComparisonPill } from '../DoraMetricsComparisonPill'; import { getDoraLink } from '../getDoraLink'; @@ -54,7 +53,7 @@ const chartOptions = { export const WeeklyDeliveryVolumeCard = () => { const { integrationSet } = useAuth(); const dateRangeLabel = useCurrentDateRangeLabel(); - const deploymentFrequencyProps = useAvgWeeklyDeploymentFrequency(); + const deploymentFrequencyProps = useAvgIntervalBasedDeploymentFrequency(); const { addPage } = useOverlayPage(); const deploymentsConfigured = true; @@ -62,11 +61,19 @@ export const WeeklyDeliveryVolumeCard = () => { IntegrationGroup.CODE ); - const weekDeliveryVolumeData = useSelector((s) => - merge( - s.doraMetrics.metrics_summary?.deployment_frequency_trends.current, - s.doraMetrics.metrics_summary?.deployment_frequency_trends.previous - ) + const currentWeekDeliveryVolumeData = useSelector( + (s) => s.doraMetrics.metrics_summary?.deployment_frequency_trends.current + ); + const previousWeekDeliveryVolumeData = useSelector( + (s) => s.doraMetrics.metrics_summary?.deployment_frequency_trends.previous + ); + + const weekDeliveryVolumeData = useMemo( + () => ({ + ...currentWeekDeliveryVolumeData, + ...previousWeekDeliveryVolumeData + }), + [currentWeekDeliveryVolumeData, previousWeekDeliveryVolumeData] ); const totalDeployments = useSelector( @@ -81,8 +88,7 @@ export const WeeklyDeliveryVolumeCard = () => { label: 'Deployments', fill: 'start', data: getSortedDatesAsArrayFromMap(weekDeliveryVolumeData).map( - (date: keyof typeof weekDeliveryVolumeData) => - weekDeliveryVolumeData[date].count + (date) => weekDeliveryVolumeData[date].count ), backgroundColor: deploymentFrequencyProps?.backgroundColor, borderColor: alpha(deploymentFrequencyProps?.backgroundColor, 0.5), diff --git a/web-server/src/content/DoraMetrics/DoraCards/sharedHooks.tsx b/web-server/src/content/DoraMetrics/DoraCards/sharedHooks.tsx index 897a7abd..01de6d72 100644 --- a/web-server/src/content/DoraMetrics/DoraCards/sharedHooks.tsx +++ b/web-server/src/content/DoraMetrics/DoraCards/sharedHooks.tsx @@ -108,39 +108,35 @@ export const useLeadTimeProps = () => { export const useDoraStats = () => { const { integrationSet } = useAuth(); const leadTimeProps = useLeadTimeProps(); - const depsConfigured = true; - const { count: df } = useAvgWeeklyDeploymentFrequency(); const { count: cfr } = useChangeFailureRateProps(); const { count: mttr, isNoDataAvailable } = useMeanTimeToRestoreProps(); const lt = leadTimeProps.count; - const interval = useSelector( + const weeklyDeploymentFrequency = useSelector( (s) => - s.doraMetrics.metrics_summary?.deployment_frequency_stats.current.duration + s.doraMetrics.metrics_summary?.deployment_frequency_stats.current + .avg_weekly_deployment_frequency ); return useMemo( () => getDoraScore({ lt: integrationSet.has(IntegrationGroup.CODE) ? lt : null, - df: depsConfigured ? df : null, + df: weeklyDeploymentFrequency, cfr: integrationSet.has(IntegrationGroup.INCIDENT) ? cfr : null, mttr: integrationSet.has(IntegrationGroup.INCIDENT) && !isNoDataAvailable ? mttr - : null, - dfInterval: interval + : null }), [ cfr, - depsConfigured, - df, integrationSet, - interval, isNoDataAvailable, lt, - mttr + mttr, + weeklyDeploymentFrequency ] ); }; @@ -219,7 +215,7 @@ export const usePropsForChangeTimeCard = () => { }; }; -export const useAvgWeeklyDeploymentFrequency = () => { +export const useAvgIntervalBasedDeploymentFrequency = () => { const avgDeploymentFrequency = useSelector( (s) => s.doraMetrics.metrics_summary?.deployment_frequency_stats.current diff --git a/web-server/src/types/resources.ts b/web-server/src/types/resources.ts index b191b7ba..9987f7ea 100644 --- a/web-server/src/types/resources.ts +++ b/web-server/src/types/resources.ts @@ -579,7 +579,10 @@ export type TeamDoraMetricsApiResponseType = { current: DeploymentFrequencyAnalyticsResponse; previous: DeploymentFrequencyAnalyticsResponse; }; - deployment_frequency_trends: Record; + deployment_frequency_trends: { + current: Record; + previous: Record; + }; lead_time_prs: PR[]; assigned_repos: (Row<'TeamRepos'> & Row<'OrgRepo'>)[]; unsynced_repos: ID[]; diff --git a/web-server/src/utils/dora.ts b/web-server/src/utils/dora.ts index a170ce77..fc0cc569 100644 --- a/web-server/src/utils/dora.ts +++ b/web-server/src/utils/dora.ts @@ -2,8 +2,7 @@ import { secondsInHour, secondsInDay, secondsInMonth, - secondsInWeek, - daysInWeek + secondsInWeek } from 'date-fns/constants'; import { isNil, mean, reject } from 'ramda'; @@ -41,15 +40,21 @@ export const IndustryStandardsDoraScores: Record = { [Industries.OTHER]: 6.7 }; +/** + * Calculates the DORA (DevOps Research and Assessment) score based on the provided parameters. + * + * @param {Object} params - An object containing the following properties: + * @param {number | null} [params.lt] - Lead Time for Changes + * @param {number | null} [params.df] - Weekly Deployment Frequency. IMPORTANT: must be weekly + * @param {number | null} [params.cfr] - Change Failure Rate + * @param {number | null} [params.mttr] - Mean Time to Recovery. + */ export const getDoraScore = ({ lt, df, cfr, - mttr, - dfInterval -}: Partial> & { - dfInterval: string; -}) => { + mttr +}: Partial>) => { const ltMttrBreakpoints = [ secondsInMonth * 6, secondsInMonth, @@ -59,12 +64,6 @@ export const getDoraScore = ({ 0 ]; - let deploymentFrequency = df; - - if (dfInterval === 'day') deploymentFrequency = df * daysInWeek; - else if (dfInterval === 'week') deploymentFrequency = df; - else if (dfInterval === 'month') deploymentFrequency = (df / 30) * daysInWeek; - const deployBreakpoints = [ 1 / (4 * 6), // ~once in 6 months 1 / 4, // once in 4 weeks (~monthly) @@ -85,8 +84,8 @@ export const getDoraScore = ({ const scores = { lt: typeof lt === 'number' ? getScoreFromData(lt, ltMttrBreakpoints) : null, df: - typeof deploymentFrequency === 'number' - ? getScoreFromDataInv(deploymentFrequency, deployBreakpoints) + typeof df === 'number' + ? getScoreFromDataInv(df, deployBreakpoints) : null, cfr: typeof cfr === 'number' ? getCFRScore(cfr) : null, mttr: