clean up time grouping

This commit is contained in:
kageru 2020-04-19 19:04:27 +02:00
parent 292aeb417f
commit 84f13d1806
Signed by untrusted user: kageru
GPG Key ID: 8282A2BEA4ADA3D2
3 changed files with 24 additions and 41 deletions

View File

@ -8,6 +8,7 @@ edition = "2018"
tui = "0.8.0"
termion = "1.5"
serde_json = "1"
itertools = "0.9"
serde = { version = "1", features = ["derive"] }
time = { version = "0.2.9", features = ["serde"] }
itertools = "0.9"
#cmd_lib = "0.7.8"

View File

@ -75,34 +75,20 @@ impl TimeSheet {
}
pub fn time_by_tasks(&self) -> String {
let mut time_by_task = std::collections::HashMap::new();
let durations = self
.times
//.iter()
//.tuple_windows()
.windows(2)
.map(|ts| {
let prev = &ts[0];
let next = &ts[1];
let diff = next.time - prev.time;
(prev.text.clone(), diff)
});
//.fold(
//std::collections::HashMap::new(),
//|mut map, (text, duration)| {
// *map.entry(text).or_insert(time::Duration::zero()) += duration;
// map
//},
//);
for (text, duration) in durations {
*time_by_task.entry(text).or_insert(time::Duration::zero()) += duration;
}
let mut times: Vec<_> = time_by_task
self.times
.iter()
.tuple_windows()
.map(|(prev, next)| (prev.text.clone(), next.time - prev.time))
.fold(
std::collections::BTreeMap::new(),
|mut map, (text, duration)| {
*map.entry(text).or_insert(time::Duration::zero()) += duration;
map
},
)
.into_iter()
.map(|(text, duration)| format!("{}: {}", text, format_duration(&duration)))
.collect();
times.sort();
times.join("; ")
.join(" | ")
}
pub fn sum_as_str(&self) -> String {

View File

@ -1,4 +1,4 @@
use super::timesheet::{TimePoint, TimeSheet};
use super::timesheet::TimeSheet;
use super::todolist::TodoList;
use std::default::Default;
use std::fmt;
@ -70,12 +70,7 @@ impl Tracc {
}
Key::Char('a') | Key::Char('A') => self.set_mode(Mode::Insert)?,
Key::Char(' ') => with_focused!(ListView::toggle_current),
// dd
Key::Char('d') => {
if let Key::Char('d') = inputs.next().unwrap()? {
with_focused!(ListView::remove_current)
}
}
Key::Char('d') => with_focused!(ListView::remove_current),
Key::Char('p') => with_focused!(ListView::paste),
Key::Char('\t') => {
self.focus = match self.focus {
@ -142,9 +137,9 @@ impl Tracc {
.direction(Direction::Vertical)
.constraints(
[
Constraint::Percentage(42),
Constraint::Percentage(42),
Constraint::Percentage(16),
Constraint::Percentage(40),
Constraint::Percentage(40),
Constraint::Percentage(20),
]
.as_ref(),
)
@ -153,12 +148,13 @@ impl Tracc {
.render(&mut frame, chunks[0]);
selectable_list(" 🕑 ", &printable_times, bottom_focus).render(&mut frame, chunks[1]);
Paragraph::new(
[Text::raw(format!(
"Sum for today: {}\n{}",
total_time, times
))]
[
Text::raw(format!("Sum for today: {}\n", total_time)),
Text::raw(times)
]
.iter(),
)
.wrap(true)
.block(Block::default().borders(Borders::ALL))
.render(&mut frame, chunks[2]);
})?;