Skip to content

Commit

Permalink
update check_complete make sure clock always +1. Include in test_widg…
Browse files Browse the repository at this point in the history
…ets.py
  • Loading branch information
zztin committed Jun 2, 2021
1 parent 78f4820 commit 9288cb3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ctimer/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ctimer/ctimer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}":
Expand Down
27 changes: 6 additions & 21 deletions ctimer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
5 changes: 3 additions & 2 deletions ctimer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand All @@ -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

Expand All @@ -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")

0 comments on commit 9288cb3

Please sign in to comment.