Skip to content

Commit

Permalink
directly passes weekly dep-freq to the score function
Browse files Browse the repository at this point in the history
  • Loading branch information
e-for-eshaan committed Sep 5, 2024
1 parent 9669d58 commit 418662f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,19 +53,27 @@ const chartOptions = {
export const WeeklyDeliveryVolumeCard = () => {
const { integrationSet } = useAuth();
const dateRangeLabel = useCurrentDateRangeLabel();
const deploymentFrequencyProps = useAvgWeeklyDeploymentFrequency();
const deploymentFrequencyProps = useAvgIntervalBasedDeploymentFrequency();

const { addPage } = useOverlayPage();
const deploymentsConfigured = true;
const isCodeProviderIntegrationEnabled = integrationSet.has(
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(
Expand All @@ -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),
Expand Down
20 changes: 8 additions & 12 deletions web-server/src/content/DoraMetrics/DoraCards/sharedHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
);
};
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion web-server/src/types/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ export type TeamDoraMetricsApiResponseType = {
current: DeploymentFrequencyAnalyticsResponse;
previous: DeploymentFrequencyAnalyticsResponse;
};
deployment_frequency_trends: Record<DateString, DeploymentFrequencyTrendBase>;
deployment_frequency_trends: {
current: Record<DateString, DeploymentFrequencyTrendBase>;
previous: Record<DateString, DeploymentFrequencyTrendBase>;
};
lead_time_prs: PR[];
assigned_repos: (Row<'TeamRepos'> & Row<'OrgRepo'>)[];
unsynced_repos: ID[];
Expand Down
29 changes: 14 additions & 15 deletions web-server/src/utils/dora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
secondsInHour,
secondsInDay,
secondsInMonth,
secondsInWeek,
daysInWeek
secondsInWeek
} from 'date-fns/constants';
import { isNil, mean, reject } from 'ramda';

Expand Down Expand Up @@ -41,15 +40,21 @@ export const IndustryStandardsDoraScores: Record<Industries, number> = {
[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<Record<'lt' | 'df' | 'cfr' | 'mttr', number | null>> & {
dfInterval: string;
}) => {
mttr
}: Partial<Record<'lt' | 'df' | 'cfr' | 'mttr', number | null>>) => {
const ltMttrBreakpoints = [
secondsInMonth * 6,
secondsInMonth,
Expand All @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit 418662f

Please sign in to comment.