From 90be8a74a490f0dd6125ffb0e585dffab1d743f0 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 3 Mar 2024 00:20:43 +0100 Subject: [PATCH] feat(red bin and green bin): status is ko if the duration is off by 10% the estimation (min 1min) --- src/modules/record/components/StepRecord.vue | 14 +++++++++----- .../services/compare-with-estimation.test.ts | 19 +++++++++++++++++++ .../services/compare-with-estimation.ts | 9 +++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/modules/record/services/compare-with-estimation.test.ts create mode 100644 src/modules/record/services/compare-with-estimation.ts diff --git a/src/modules/record/components/StepRecord.vue b/src/modules/record/components/StepRecord.vue index c5efb70..2832577 100644 --- a/src/modules/record/components/StepRecord.vue +++ b/src/modules/record/components/StepRecord.vue @@ -4,6 +4,7 @@ import { formatDiffInMinutes } from '@/shared/format-date' import { toISODate } from '@/shared/types/date' import { computed, onUnmounted, ref } from 'vue' import { useTaskRecordStore } from '../stores/useTaskRecordStore' +import { is10PercentOffThanEstimation } from '@/modules/record/services/compare-with-estimation' const props = defineProps<{ taskId: string @@ -52,12 +53,15 @@ const duration = computed(() => { ) }) -const isGreaterThanEstimation = computed(() => { +const isOffEstimation = computed(() => { if (!step.value || !stepRecord.value || !duration.value) { return false } - return duration.value > step.value.estimation + return is10PercentOffThanEstimation({ + estimation: step.value.estimation, + duration: duration.value + }) }) @@ -80,9 +84,9 @@ const isGreaterThanEstimation = computed(() => { - - - + + + {{ step.title }} diff --git a/src/modules/record/services/compare-with-estimation.test.ts b/src/modules/record/services/compare-with-estimation.test.ts new file mode 100644 index 0000000..ce0724b --- /dev/null +++ b/src/modules/record/services/compare-with-estimation.test.ts @@ -0,0 +1,19 @@ +import { is10PercentOffThanEstimation } from '@/modules/record/services/compare-with-estimation' +import { describe, expect, it } from 'vitest' + +describe('compareWithEstimation', () => { + it('should tells if the estimation is off by 10% or more', () => { + expect(is10PercentOffThanEstimation({ estimation: 10, duration: 9 })).toBe( + false + ) + expect(is10PercentOffThanEstimation({ estimation: 5, duration: 4 })).toBe( + false + ) + expect(is10PercentOffThanEstimation({ estimation: 10, duration: 5 })).toBe( + true + ) + expect(is10PercentOffThanEstimation({ estimation: 10, duration: 8 })).toBe( + true + ) + }) +}) diff --git a/src/modules/record/services/compare-with-estimation.ts b/src/modules/record/services/compare-with-estimation.ts new file mode 100644 index 0000000..8c22e9c --- /dev/null +++ b/src/modules/record/services/compare-with-estimation.ts @@ -0,0 +1,9 @@ +export const is10PercentOffThanEstimation = ({ + estimation, + duration +}: { + estimation: number + duration: number +}) => { + return Math.abs(duration - estimation) > Math.max(estimation * 0.1, 1) +}