feat(red bin and green bin): status is ko if the duration is off by 10% the estimation (min 1min)

This commit is contained in:
Julien Calixte
2024-03-03 00:20:43 +01:00
parent aab5116535
commit 90be8a74a4
3 changed files with 37 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ import { formatDiffInMinutes } from '@/shared/format-date'
import { toISODate } from '@/shared/types/date' import { toISODate } from '@/shared/types/date'
import { computed, onUnmounted, ref } from 'vue' import { computed, onUnmounted, ref } from 'vue'
import { useTaskRecordStore } from '../stores/useTaskRecordStore' import { useTaskRecordStore } from '../stores/useTaskRecordStore'
import { is10PercentOffThanEstimation } from '@/modules/record/services/compare-with-estimation'
const props = defineProps<{ const props = defineProps<{
taskId: string taskId: string
@@ -52,12 +53,15 @@ const duration = computed(() => {
) )
}) })
const isGreaterThanEstimation = computed(() => { const isOffEstimation = computed(() => {
if (!step.value || !stepRecord.value || !duration.value) { if (!step.value || !stepRecord.value || !duration.value) {
return false return false
} }
return duration.value > step.value.estimation return is10PercentOffThanEstimation({
estimation: step.value.estimation,
duration: duration.value
})
}) })
</script> </script>
@@ -80,9 +84,9 @@ const isGreaterThanEstimation = computed(() => {
</div> </div>
</td> </td>
<td class="status"> <td class="status">
<span v-if="stepRecord?.end && !isGreaterThanEstimation"></span> <span v-if="!stepRecord?.end"></span>
<span v-else-if="isGreaterThanEstimation"></span> <span v-else-if="isOffEstimation"></span>
<span v-else></span> <span v-else></span>
</td> </td>
<td class="step-title"> <td class="step-title">
{{ step.title }} {{ step.title }}

View File

@@ -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
)
})
})

View File

@@ -0,0 +1,9 @@
export const is10PercentOffThanEstimation = ({
estimation,
duration
}: {
estimation: number
duration: number
}) => {
return Math.abs(duration - estimation) > Math.max(estimation * 0.1, 1)
}