From 69eaad1c9f934bccaf7e28529a6b1657345f0184 Mon Sep 17 00:00:00 2001 From: Mx Kookie Date: Sat, 19 Dec 2020 15:15:20 +0000 Subject: cassiopeia: changing internal data representation to timeline module What this allows us to do is much better relationship tracking between sessions and invoices. The CASS file already has all the structure we need, and it would be silly to replicate it via complicated time association algorithms. This approach uses the linear nature of the data file to track the position relative to other entries. The timeline module is then responsible for making changes to the internal representation (in case it is being used as a library for multi-query commands), and emitting a `Delta` type that can be used to easily patch the IR in question, because the mapping between the timeline and IR representations is linear. --- apps/cassiopeia/src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'apps/cassiopeia/src/lib.rs') diff --git a/apps/cassiopeia/src/lib.rs b/apps/cassiopeia/src/lib.rs index e391c695237e..895110fe218d 100644 --- a/apps/cassiopeia/src/lib.rs +++ b/apps/cassiopeia/src/lib.rs @@ -10,9 +10,11 @@ mod data; mod date; +mod error; mod format; pub mod meta; mod time; +mod timeline; pub use date::Date; pub use time::Time; @@ -46,17 +48,17 @@ impl Cassiopeia { /// Start a new work session (with optional 15 minute rounding) pub fn start(&mut self, round: bool) -> Option<()> { - let s = self.tf.start(round)?; + let delta = self.tf.timeline.start(Time::rounded(round)).ok()?; clean_ir(&mut self.ir); - append_ir(&mut self.ir, s.make_ir()); + append_ir(&mut self.ir, delta.make_ir()); format::write_file(self.path.as_str(), &mut self.ir) } /// Stop the existing work session (with optional 15 minute rounding) pub fn stop(&mut self, round: bool) -> Option<()> { - let s = self.tf.stop(round)?; + let delta = self.tf.timeline.stop(Time::rounded(round)).ok()?; clean_ir(&mut self.ir); - append_ir(&mut self.ir, s.make_ir()); + append_ir(&mut self.ir, delta.make_ir()); format::write_file(self.path.as_str(), &mut self.ir) } @@ -70,6 +72,11 @@ impl Cassiopeia { clean_ir(&mut self.ir); format::write_file(self.path.as_str(), &mut self.ir) } + + /// Collect statistics on previous work sessions + pub fn stat(&self) -> Option { + None + } } /// An invoice generator builder @@ -142,9 +149,9 @@ impl<'cass> Invoicer<'cass> { return None; } - let inv = self.tf.tf.invoice()?; + let delta = self.tf.tf.timeline.invoice(Date::today()).ok()?; clean_ir(&mut self.tf.ir); - append_ir(&mut self.tf.ir, inv.make_ir()); + append_ir(&mut self.tf.ir, delta.make_ir()); format::write_file(self.tf.path.as_str(), &mut self.tf.ir) } } -- cgit v1.2.3