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" tui = "0.8.0"
termion = "1.5" termion = "1.5"
serde_json = "1" serde_json = "1"
itertools = "0.9"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
time = { version = "0.2.9", features = ["serde"] } 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 { pub fn time_by_tasks(&self) -> String {
let mut time_by_task = std::collections::HashMap::new(); self.times
let durations = self .iter()
.times .tuple_windows()
//.iter() .map(|(prev, next)| (prev.text.clone(), next.time - prev.time))
//.tuple_windows() .fold(
.windows(2) std::collections::BTreeMap::new(),
.map(|ts| { |mut map, (text, duration)| {
let prev = &ts[0]; *map.entry(text).or_insert(time::Duration::zero()) += duration;
let next = &ts[1]; map
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
.into_iter() .into_iter()
.map(|(text, duration)| format!("{}: {}", text, format_duration(&duration))) .map(|(text, duration)| format!("{}: {}", text, format_duration(&duration)))
.collect(); .join(" | ")
times.sort();
times.join("; ")
} }
pub fn sum_as_str(&self) -> String { 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 super::todolist::TodoList;
use std::default::Default; use std::default::Default;
use std::fmt; use std::fmt;
@ -70,12 +70,7 @@ impl Tracc {
} }
Key::Char('a') | Key::Char('A') => self.set_mode(Mode::Insert)?, Key::Char('a') | Key::Char('A') => self.set_mode(Mode::Insert)?,
Key::Char(' ') => with_focused!(ListView::toggle_current), Key::Char(' ') => with_focused!(ListView::toggle_current),
// dd Key::Char('d') => with_focused!(ListView::remove_current),
Key::Char('d') => {
if let Key::Char('d') = inputs.next().unwrap()? {
with_focused!(ListView::remove_current)
}
}
Key::Char('p') => with_focused!(ListView::paste), Key::Char('p') => with_focused!(ListView::paste),
Key::Char('\t') => { Key::Char('\t') => {
self.focus = match self.focus { self.focus = match self.focus {
@ -142,9 +137,9 @@ impl Tracc {
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints( .constraints(
[ [
Constraint::Percentage(42), Constraint::Percentage(40),
Constraint::Percentage(42), Constraint::Percentage(40),
Constraint::Percentage(16), Constraint::Percentage(20),
] ]
.as_ref(), .as_ref(),
) )
@ -153,12 +148,13 @@ impl Tracc {
.render(&mut frame, chunks[0]); .render(&mut frame, chunks[0]);
selectable_list(" 🕑 ", &printable_times, bottom_focus).render(&mut frame, chunks[1]); selectable_list(" 🕑 ", &printable_times, bottom_focus).render(&mut frame, chunks[1]);
Paragraph::new( Paragraph::new(
[Text::raw(format!( [
"Sum for today: {}\n{}", Text::raw(format!("Sum for today: {}\n", total_time)),
total_time, times Text::raw(times)
))] ]
.iter(), .iter(),
) )
.wrap(true)
.block(Block::default().borders(Borders::ALL)) .block(Block::default().borders(Borders::ALL))
.render(&mut frame, chunks[2]); .render(&mut frame, chunks[2]);
})?; })?;