shuffle queue when all breaks taken

This commit is contained in:
nikolay 2021-02-08 23:16:10 +07:00
parent 1738e16a86
commit 5838bb216b
1 changed files with 27 additions and 8 deletions

View File

@ -88,15 +88,11 @@ class BreakQueue:
self.__short_break_time = config.get('short_break_interval')
self.__long_break_time = config.get('long_break_interval')
self.__is_random_order = config.get('random_order')
self.__config = config
self.__build_longs()
self.__build_shorts()
self.__short_queue = self.__build_queue(BreakType.SHORT_BREAK,
config.get('short_breaks'),
self.__short_break_time,
config.get('short_break_duration'))
self.__long_queue = self.__build_queue(BreakType.LONG_BREAK,
config.get('long_breaks'),
self.__long_break_time,
config.get('long_break_duration'))
# Interface guarantees that short_interval >= 1
# And that long_interval is a multiple of short_interval
@ -183,6 +179,11 @@ class BreakQueue:
# Update the index to next
self.__current_short = (self.__current_short + 1) % len(shorts)
# Shuffle queue
if self.__current_short == 0 and self.__is_random_order:
self.__build_shorts()
self.__shorts_taken += 1
return break_obj
@ -194,6 +195,11 @@ class BreakQueue:
# Update the index to next
self.__current_long = (self.__current_long + 1) % len(longs)
# Shuffle queue
if self.__current_long == 0 and self.__is_random_order:
self.__build_longs()
return break_obj
def __build_queue(self, break_type, break_configs, break_time, break_duration):
@ -231,6 +237,19 @@ class BreakQueue:
return queue
def __build_shorts(self):
self.__short_queue = self.__build_queue(BreakType.SHORT_BREAK,
self.__config.get('short_breaks'),
self.__short_break_time,
self.__config.get('short_break_duration'))
def __build_longs(self):
self.__long_queue = self.__build_queue(BreakType.LONG_BREAK,
self.__config.get('long_breaks'),
self.__long_break_time,
self.__config.get('long_break_duration'))
class State(Enum):
"""