I have an OOD/OOP problem, where I need to design a scheduler to output the date for certain activities with different frequencies.
For example, I can have this event to schedule every one hour, every 4 hours, every day, or every week, even every month.
I can also set the event to happen at noon, at dinner time, or before bed.
What's more, you can also set the event to happen randomly.
The output would be a list of time which will be scheduled in the future.
My original plan was, to use enum to set the frequency:
class TimeUnit(enum):
hour
day
week
month
class Scheduler():
def __init__(self):
self.time_table = []
def update_timetable(self, time_unit: TimeUnit, frequency: int, start_data: datetime):
pass
scheduler = Scheduler()
# As a result, the following means to set the event to happen 3 times a day.
scheduler.update_timetable(TimeUnit.day, 3, Oct.25.2020)
But I am not sure how to design the scheduler to elegantly meet the needs of scheduling the event at a certain fixed time, like dinner time, or several fixed times like at 9 am 4 pm, and 10 pm every day.
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire