forked from janek/mostr
fix: task progress percentage
This commit is contained in:
parent
7f34a888f3
commit
5b05c53947
1 changed files with 12 additions and 5 deletions
17
src/tasks.rs
17
src/tasks.rs
|
@ -150,12 +150,18 @@ impl Tasks {
|
||||||
State::Closed => None,
|
State::Closed => None,
|
||||||
State::Done => Some(1.0),
|
State::Done => Some(1.0),
|
||||||
_ => {
|
_ => {
|
||||||
let count = t.children.len() as f32;
|
let mut sum = 0f32;
|
||||||
|
let mut count = 0;
|
||||||
|
for prog in t.children.iter().filter_map(|e| self.total_progress(e)) {
|
||||||
|
sum += prog;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
Some(
|
Some(
|
||||||
t.children
|
if count > 0 {
|
||||||
.iter()
|
sum / (count as f32)
|
||||||
.filter_map(|e| self.total_progress(e).map(|p| p / count))
|
} else {
|
||||||
.sum(),
|
0.0
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -338,6 +344,7 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
"progress" => self
|
"progress" => self
|
||||||
.total_progress(task.get_id())
|
.total_progress(task.get_id())
|
||||||
|
.filter(|_| task.children.len() > 0)
|
||||||
.map_or(String::new(), |p| format!("{:2.0}%", p * 100.0)),
|
.map_or(String::new(), |p| format!("{:2.0}%", p * 100.0)),
|
||||||
"path" => self.get_task_path(Some(task.event.id)),
|
"path" => self.get_task_path(Some(task.event.id)),
|
||||||
"rpath" => self.relative_path(task.event.id),
|
"rpath" => self.relative_path(task.event.id),
|
||||||
|
|
Loading…
Add table
Reference in a new issue