Skip to content

Instantly share code, notes, and snippets.

@katipogluMustafa
Created November 15, 2020 22:24
Show Gist options
  • Save katipogluMustafa/09d95970806dc2b11f0bc2f7aa79fcd3 to your computer and use it in GitHub Desktop.
Save katipogluMustafa/09d95970806dc2b11f0bc2f7aa79fcd3 to your computer and use it in GitHub Desktop.
class TimeConstraint:
"""
TimeConstraint is a constraint on the timestamp of the movie ratings.
We classify a TimeConstraint as either max_time_constraint or time_bin_constraint.
max_time_constraint is used to simulate real life in which we do not know the future but all the data up until one point in time.
time_bin_constraint is used to grab a portion of a time interval where starting and ending points are strictly defined and data is well known.
"""
def __init__(self, end_dt, start_dt=None):
"""
When end_dt is only given, system will have a max time constraint only.
When end_dt and start_dt are given, system will have a time_bin_constraint.
:param end_dt: The ending time boundary.
:param start_dt: The starting time boundary.
Always set start_dt to None if you change the object from time_bin to max_limit.
"""
self.end_dt = end_dt
self.start_dt = start_dt
def is_valid_time_bin(self) -> bool:
"""
Check whether this TimeConstraint object represents a valid time bin.
"""
if self.is_time_bin() and (self._end_dt > self._start_dt):
return True
return False
def is_valid_max_limit(self) -> bool:
"""
Check whether this TimeConstraint represents a valid max time limit.
"""
if (self._end_dt is not None) and (self._start_dt is None):
return True
return False
def is_time_bin(self) -> bool:
if (self._start_dt is not None) and (self._end_dt is not None):
return True
return False
# Properties
@property
def end_dt(self):
return self._end_dt
@end_dt.setter
def end_dt(self, value):
self._end_dt = value
@property
def start_dt(self):
return self._start_dt
@start_dt.setter
def start_dt(self, value):
self._start_dt = value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment