forked from janek/mostr
feat: evaluate time tracked recursively
This commit is contained in:
parent
44ea79bc81
commit
026915f870
|
@ -82,7 +82,7 @@ impl Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total time this task has been active.
|
/// Total time this task has been active.
|
||||||
/// Todo: Recursive
|
/// TODO: Consider caching
|
||||||
pub(crate) fn time_tracked(&self) -> u64 {
|
pub(crate) fn time_tracked(&self) -> u64 {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
let mut start: Option<Timestamp> = None;
|
let mut start: Option<Timestamp> = None;
|
||||||
|
|
|
@ -35,6 +35,13 @@ impl Tasks {
|
||||||
tasks.iter().filter_map(|id| self.tasks.get(id)).collect()
|
tasks.iter().filter_map(|id| self.tasks.get(id)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Total time this task and its subtasks have been active
|
||||||
|
fn total_time_tracked(&self, task: &EventId) -> u64 {
|
||||||
|
self.tasks.get(task).map_or(0, |t| {
|
||||||
|
t.time_tracked() + t.children.iter().map(|e| self.total_time_tracked(e)).sum::<u64>()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn set_filter(&mut self, view: Vec<EventId>) {
|
pub(crate) fn set_filter(&mut self, view: Vec<EventId>) {
|
||||||
self.view = view
|
self.view = view
|
||||||
}
|
}
|
||||||
|
@ -62,6 +69,7 @@ impl Tasks {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| match p.as_str() {
|
.map(|p| match p.as_str() {
|
||||||
"path" => self.taskpath(Some(task.event.id)),
|
"path" => self.taskpath(Some(task.event.id)),
|
||||||
|
"ttime" => self.total_time_tracked(&task.event.id).to_string(),
|
||||||
prop => task.get(prop).unwrap_or(String::new()),
|
prop => task.get(prop).unwrap_or(String::new()),
|
||||||
})
|
})
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
|
|
Loading…
Reference in New Issue