forked from janek/mostr
1
0
Fork 0

feat: evaluate time tracked recursively

This commit is contained in:
xeruf 2024-07-19 09:44:12 +03:00
parent 44ea79bc81
commit 026915f870
2 changed files with 9 additions and 1 deletions

View File

@ -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;

View File

@ -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>>()