aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-02-26 06:56:37 +0000
committerAkshay <[email protected]>2020-02-26 06:56:37 +0000
commit39b21b4501e48da56ddbdbadc97c3ccf32746029 (patch)
treeaea052dd3265a4d0ebaf372df1edf0e3c8466c5e
parentce5f500998f05fac13c6472681eedb7702055a7f (diff)
fix null entry with bits, add remaining api
-rw-r--r--src/habit.rs15
-rw-r--r--src/views/habitview.rs3
2 files changed, 17 insertions, 1 deletions
diff --git a/src/habit.rs b/src/habit.rs
index cd1703e..8527ac2 100644
--- a/src/habit.rs
+++ b/src/habit.rs
@@ -33,6 +33,7 @@ pub trait HabitTrait {
33 fn get_by_date(&self, date: NaiveDate) -> Option<&HabitType>; 33 fn get_by_date(&self, date: NaiveDate) -> Option<&HabitType>;
34 fn insert_entry(&mut self, date: NaiveDate, val: HabitType); 34 fn insert_entry(&mut self, date: NaiveDate, val: HabitType);
35 fn reached_goal(&self, date: NaiveDate) -> bool; 35 fn reached_goal(&self, date: NaiveDate) -> bool;
36 fn remaining(&self, date: NaiveDate) -> u32;
36} 37}
37 38
38#[derive(Serialize, Debug)] 39#[derive(Serialize, Debug)]
@@ -73,7 +74,7 @@ impl Habit {
73 } 74 }
74 } else { 75 } else {
75 match self.goal { 76 match self.goal {
76 HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(false)), 77 HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)),
77 HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), 78 HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)),
78 } 79 }
79 } 80 }
@@ -109,4 +110,16 @@ impl HabitTrait for Habit {
109 } 110 }
110 return false; 111 return false;
111 } 112 }
113 fn remaining(&self, date: NaiveDate) -> u32 {
114 if self.reached_goal(date) {
115 return 0;
116 } else if let Some(val) = self.stats.get(&date) {
117 match val {
118 HabitType::Bit(_) => return 1,
119 HabitType::Count(c) => return self.goal.inner_count() - *c,
120 }
121 } else {
122 return 0;
123 }
124 }
112} 125}
diff --git a/src/views/habitview.rs b/src/views/habitview.rs
index 3ae0c90..ddeb456 100644
--- a/src/views/habitview.rs
+++ b/src/views/habitview.rs
@@ -41,6 +41,9 @@ impl HabitView {
41 pub fn get_title(&self) -> String { 41 pub fn get_title(&self) -> String {
42 return self.habit.get_name().to_owned(); 42 return self.habit.get_name().to_owned();
43 } 43 }
44 pub fn get_size(&self) -> Vec2 {
45 (self.view_width, self.view_height).into()
46 }
44} 47}
45 48
46impl View for HabitView { 49impl View for HabitView {