From bfa7d672fe733caa1416bd289118f69e1d835996 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Tue, 10 Dec 2019 11:46:04 +0800 Subject: [PATCH] fix: fixed a efficiency calculator bug --- src/efficiency/efficiency.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/efficiency/efficiency.ts b/src/efficiency/efficiency.ts index c843318..a05b9df 100644 --- a/src/efficiency/efficiency.ts +++ b/src/efficiency/efficiency.ts @@ -11,6 +11,10 @@ export function getEfficiency(isDistractionArr: boolean[], stayTimeArr: number[] 0 ); + if (totalTime === focusedTime || (isDistractionArr.length === 1 && !isDistractionArr[0])) { + return 1; + } + let prevEfficiency = 0; for (let i = 0; i < stayTimeArr.length; i += 1) { if (isDistractionArr[i]) { @@ -18,7 +22,7 @@ export function getEfficiency(isDistractionArr: boolean[], stayTimeArr: number[] } let lossFactor = 1; - if (prevEfficiency !== 0) { + if (i > 0) { lossFactor = 1 - Math.sqrt(Math.min(stayTimeArr[i - 1] / 30, 1)) * 0.5 - 0.5; }