Skip to content

Commit 3e9dd04

Browse files
authored
Fix rating calculation
1 parent 362aece commit 3e9dd04

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/store/index.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,6 @@ export default createStore({
9595
const activeTasks: number = state.tasks.filter(
9696
(taskList) => !taskList.isCompleted,
9797
).length; //calculate the number of active tasks (tasks that are not completed) using Array.filter
98-
const overdueTasks: number = state.tasks.filter(
99-
(taskList) =>
100-
new Date(
101-
new Date(
102-
new Date().setMinutes(
103-
new Date().getMinutes() - new Date().getTimezoneOffset(),
104-
),
105-
)
106-
.toISOString()
107-
.split("T")[0] + " 23:59:59.999",
108-
) >= new Date(taskList.dueDate + " 23:59:59.999"),
109-
).length; //calculate the number of overdue tasks (tasks after the due date) and the date of next midnight from now
11098
let activeTasksMultiplier: number; //calculate score multiplier for number of active tasks (tasks that are not completed)
11199
//calculate task repetition XP multiplier
112100
if (Number(task.repeatInterval) === 1) {
@@ -242,6 +230,24 @@ export default createStore({
242230
if (daysSinceLastCompletion >= 1) {
243231
//repeat for each day of inactivity
244232
for (let i = 0; i < daysSinceLastCompletion; i++) {
233+
const overdueTasks: number = state.tasks.filter(
234+
(taskList) =>
235+
new Date(
236+
new Date(
237+
new Date(String(state.user.lastCompletionDate)).setMinutes(
238+
new Date(
239+
String(state.user.lastCompletionDate),
240+
).getMinutes() -
241+
new Date(
242+
String(state.user.lastCompletionDate),
243+
).getTimezoneOffset(),
244+
) +
245+
86400000 * i,
246+
)
247+
.toISOString()
248+
.split("T")[0] + " 23:59:59.999",
249+
) >= new Date(taskList.dueDate + " 23:59:59.999"),
250+
).length; //calculate the number of overdue tasks (tasks after the due date) and the date of next midnight from now
245251
state.user.rating -= Math.max(
246252
Math.sqrt(Math.max(state.user.rating, 0)) *
247253
(1 + Math.log(Math.max(i + 1, 1))) *

0 commit comments

Comments
 (0)