forked from janek/mostr
fix: show currently running timetracking for task
This commit is contained in:
parent
9fbe3e27cb
commit
15bd21059d
39
src/tasks.rs
39
src/tasks.rs
|
@ -13,7 +13,6 @@ use colored::Colorize;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagStandard, Timestamp, UncheckedUrl, Url};
|
use nostr_sdk::{Event, EventBuilder, EventId, Keys, Kind, PublicKey, Tag, TagStandard, Timestamp, UncheckedUrl, Url};
|
||||||
use nostr_sdk::base64::write::StrConsumer;
|
|
||||||
use nostr_sdk::prelude::Marker;
|
use nostr_sdk::prelude::Marker;
|
||||||
use TagStandard::Hashtag;
|
use TagStandard::Hashtag;
|
||||||
|
|
||||||
|
@ -172,11 +171,7 @@ impl Tasks {
|
||||||
.dedup()
|
.dedup()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Total time in seconds tracked on this task by the current user.
|
/// Dynamic time tracking overview for current task or current user.
|
||||||
pub(crate) fn time_tracked(&self, id: EventId) -> u64 {
|
|
||||||
TimesTracked::from(self.history.get(&self.sender.pubkey()).into_iter().flatten(), &vec![id]).sum::<Duration>().as_secs()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn times_tracked(&self) -> String {
|
pub(crate) fn times_tracked(&self) -> String {
|
||||||
match self.get_position() {
|
match self.get_position() {
|
||||||
None => {
|
None => {
|
||||||
|
@ -201,23 +196,29 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(id) => {
|
Some(id) => {
|
||||||
let vec = vec![id];
|
let ids = vec![id];
|
||||||
let res =
|
once(format!("Times tracked on {}", self.get_task_title(&id))).chain(
|
||||||
once(format!("Times tracked on {}", self.get_task_title(&id))).chain(
|
self.history.iter().flat_map(|(key, set)| {
|
||||||
self.history.iter().flat_map(|(key, set)|
|
let mut vec = Vec::with_capacity(set.len() / 2);
|
||||||
timestamps(set.iter(), &vec)
|
let mut iter = timestamps(set.iter(), &ids).tuples();
|
||||||
.tuples::<(_, _)>()
|
while let Some(((start, _), (end, _))) = iter.next() {
|
||||||
.map(move |((start, _), (end, _))| {
|
vec.push(format!("{} - {} by {}", start.to_human_datetime(), end.to_human_datetime(), key))
|
||||||
format!("{} - {} by {}", start.to_human_datetime(), end.to_human_datetime(), key)
|
}
|
||||||
})
|
iter.into_buffer().for_each(|(stamp, _)|
|
||||||
).sorted_unstable()
|
vec.push(format!("{} started by {}", stamp.to_human_datetime(), key)));
|
||||||
).join("\n");
|
vec
|
||||||
drop(vec);
|
}).sorted_unstable()
|
||||||
res
|
).join("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Total time in seconds tracked on this task by the current user.
|
||||||
|
pub(crate) fn time_tracked(&self, id: EventId) -> u64 {
|
||||||
|
TimesTracked::from(self.history.get(&self.sender.pubkey()).into_iter().flatten(), &vec![id]).sum::<Duration>().as_secs()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Total time in seconds tracked on this task and its subtasks by all users.
|
/// Total time in seconds tracked on this task and its subtasks by all users.
|
||||||
fn total_time_tracked(&self, id: EventId) -> u64 {
|
fn total_time_tracked(&self, id: EventId) -> u64 {
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
|
|
Loading…
Reference in New Issue