在切换todo项时计算项目进度



我正在制作一个todo应用程序,我想了一些方法来增加趣味性,所以我实现了一个项目进度功能。所以在应用程序中,你可以创建projects,每个项目可以有todolists,每个todolist可以有todos
因此,当用户切换待办事项时,我会以这种方式重新计算项目进度

const todoContirubutioToProjectPorgess=1/projectTodosTotalCount
project.progress += todoContirubutioToProjectPorgess

如果项目中的todo具有相同数量的todo,那么这很好,但当它们没有时,这就没有意义了,因为,例如,让我们考虑以下情况:
案例1

project : [
todoList1[todo1,todo2],
todoList2[todo3,todo4]
]
//todo1's contribution to project's progress is the same todo3's so it works here 


情况2

project : [
todoList1[todo1,todo2],
todoList2[todo3,todo4,todo5]
]
//todo1's contribution to project's progress is bigger than todo3 , since todo1 makes 50% of todoList1 and todo3 makes only 30% todoList2

我试过这个

const todoListContirubutioToProjectPorgess  =  todoListTodosCount/projectTodosTotalCount
const todoContirubutioToPorgess =  1/todoListContirubutioToProjectPorgess  
project.progress += todoContirubutioToPorgess

但它并没有像我预期的那样起作用,你对此有什么看法,你会如何处理

设为xtodo列表,任务数为[t1, t2, t3, ...tx]
每个待办事项列表的贡献=100/x %
列表1中的每个项目的贡献=(100/x) / t1%=100/(x*t1) %
列表2中每个项目的贡献=(100/x) / t2%=100/(x*t2) %
列表x=(100/x) / tx%=100/(x*tx) %中每个项目的贡献。

对于每个任务,您只需要两个变量:列表的总数和当前列表中的任务数。然后使用上面的公式来获得进度增量。

最新更新