diff --git a/ctimer/controller.py b/ctimer/controller.py index a8a71a1..c13f7ec 100644 --- a/ctimer/controller.py +++ b/ctimer/controller.py @@ -43,6 +43,7 @@ def countdown(self): if not self.tm.clock_details.is_break: self.tm.clock_details.end_clock = time.time() self.tm.check_complete() + self.tm.clock_details.clock_count += 1 self.tv.countdown_display("Done!", self.tm.clock_details.is_break) # if end_break == end_clock : # the app has been force ended during the clock. Update the break time while termination. @@ -76,7 +77,6 @@ def countdown(self): self.tv.flash_window() self.tv.playback_voice_message("break_over") self.tm.clock_details.end_clock = time.time() - self.tm.check_complete() db.db_add_clock_details(self.tm.db_file, self.tm.clock_details) self.tm.clock_details.get_new_clock_entry() self.tm.remaining_time = self.tm.set_time diff --git a/ctimer/ctimer_db.py b/ctimer/ctimer_db.py index a965d7b..239e43d 100644 --- a/ctimer/ctimer_db.py +++ b/ctimer/ctimer_db.py @@ -35,6 +35,7 @@ def get_new_clock_entry(self): self.task_description = "Task description to be set" self.reached_bool = False self.reason = "N.A." + self.pause_toggled = False def clock_details_sanity_check(self): if self.date != f"{date.today()}": diff --git a/ctimer/model.py b/ctimer/model.py index 31e8d4c..138e454 100644 --- a/ctimer/model.py +++ b/ctimer/model.py @@ -59,30 +59,15 @@ def __init__( def check_complete(self): """ - Two scenario is consider completed. - 1. Clock duration is reached. - 2. Clock duration is not reached, but Goal is reached. (happens when clocks is pre-terminated when task is finished.) - ## TODO: rewrite this function and change definition. If terminate: check ... , If end: check... using - ## absolute timestamp duration is not working during interactive debug mode. - ### USE CHECK_COMPLETE to add clock count. + Definition of complete: no pause during the clock. If terminate the clock earlier, it could still be a + complete clock. """ - clock_duration = self.clock_details.end_clock - self.clock_details.start_clock - # if check_complete is asked during a break / when a break is finished, always return false. - if self.clock_details.is_break is True: - # if a clock did not continue for the full period straight (has pauses in between) + if self.clock_details.pause_toggled: self.clock_details.is_complete = False - # a clock has finished (within 0.01 s) automatically - elif abs(clock_duration - self.set_time) <= 1: - self.clock_details.is_complete = True - self.clock_details.clock_count += 1 - # a clock has been termianted when the user finishes the task but the time still has remaining. - elif self.clock_details.reached_bool: - self.clock_details.is_complete = True - self.clock_details.clock_count += 1 - # terminate a clock when the user is distracted. Clock count += 0 else: - self.clock_details.is_complete = False - self.clock_details.reached_bool, self.clock_details.reason = False, 0 + self.clock_details.is_complete = True + + class Meta: def __init__( diff --git a/ctimer/view.py b/ctimer/view.py index 6b168ef..1629922 100644 --- a/ctimer/view.py +++ b/ctimer/view.py @@ -335,6 +335,7 @@ def playback_voice_message(self, message_type): def toggle_start_pause(self): # is paused: start clock + self.tm.clock_details.pause_toggled = True if not self.tm.clock_ticking: if self.tm.fresh_new: self.playback_voice_message("start") @@ -363,8 +364,8 @@ def terminate(self): self.tm.clock_details.reached_bool, self.tm.clock_details.reason = self.ask_reached_goal_reason() # check terminate status self.tm.check_complete() - # expect check_complete would give is_complete == False - # self.tm.clock_details.is_complete = False + if self.tm.clock_details.is_complete: + self.clock_details.clock_count += 1 self.tm.clock_details.end_clock = time.time() db.db_add_clock_details(self.tm.db_file, self.tm.clock_details) # set to new status diff --git a/tests/test_widgets.py b/tests/test_widgets.py index e7c777d..a0e452f 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -9,13 +9,14 @@ from ctimer.controller import CtimerClockController from ctimer.view import CtimerClockView from ctimer.model import CtimerClockModel - +import os @pytest.fixture def controller(): print("Setup debugging-controller for testing.") db_path_debug = utils.get_cache_filepath(None, debug=True) - db_file_debug = f"{db_path_debug}/ctimer_debug_2021.db" + # create a new empty db file. + db_file_debug = f"{db_path_debug}/ctimer_debug_temp.db" db.create_connection(db_file_debug) current_clock_details = db.Clock_details(db_file_debug) @@ -54,6 +55,7 @@ def test_click_start_reached_one_clock(controller): patch('ctimer.view.simpledialog.askstring', MagicMock(return_value=expected_goal_string)), \ patch('ctimer.view.CtimerClockView.ask_reached_goal_reason', MagicMock(return_value=(True, "Fake reached reason"))): + assert tm.clock_details.clock_count == 0 tv._button_start_pause.invoke() controller.master.update() @@ -65,7 +67,6 @@ def test_click_start_reached_one_clock(controller): for ticking in range(one_clock_time - 1): controller.countdown() - controller.master.update() assert tm.remaining_time == 1 @@ -77,3 +78,6 @@ def test_click_start_reached_one_clock(controller): controller.master.update() assert tm.clock_details.reached_bool assert tm.clock_details.reason == "Fake reached reason" + assert tm.clock_details.clock_count == 1 + db_path_debug = utils.get_cache_filepath(None, debug=True) + os.remove(f"{db_path_debug}/ctimer_debug_temp.db") \ No newline at end of file