Adjust to simply step forward in time until present day

This commit is contained in:
Marc Di Luzio 2024-08-10 15:13:42 +01:00
parent 874a24dd1d
commit e002c5c9d5

View file

@ -6,13 +6,10 @@ import history
# Number of days to step forward from the start of history for each match attempt # Number of days to step forward from the start of history for each match attempt
_ATTEMPT_RELEVANCY_STEP = timedelta(days=7) _ATTEMPT_RELEVANCY_TIMESTEP = timedelta(days=7)
# Attempts for each of those time periods # Attempts for each of those time periods
_ATTEMPTS_PER_TIME = 3 _ATTEMPTS_PER_TIMESTEP = 3
# Mamum attempts worth taking
_MAX_ATTEMPTS = _ATTEMPTS_PER_TIME*10
logger = logging.getLogger("matching") logger = logging.getLogger("matching")
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)
@ -102,10 +99,9 @@ def attempt_create_groups(matchees: list[Member],
def members_to_groups(matchees: list[Member], def members_to_groups(matchees: list[Member],
hist: history.History = history.History(), hist: history.History = history.History(),
per_group: int = 3, max_attempts: int = _MAX_ATTEMPTS) -> list[list[Member]]: per_group: int = 3) -> list[list[Member]]:
"""Generate the groups from the set of matchees""" """Generate the groups from the set of matchees"""
num_groups = max(len(matchees)//per_group, 1) num_groups = max(len(matchees)//per_group, 1)
attempts = max_attempts
# Only both with the complicated matching if we have a history # Only both with the complicated matching if we have a history
# TODO: When matching takes into account more than history this should change # TODO: When matching takes into account more than history this should change
@ -117,28 +113,27 @@ def members_to_groups(matchees: list[Member],
oldest_relevant_datetime = hist.oldest() oldest_relevant_datetime = hist.oldest()
# Loop until we find a valid set of groups # Loop until we find a valid set of groups
while attempts: attempts = 0
attempts -= 1 while True:
attempts += 1
groups = attempt_create_groups( groups = attempt_create_groups(
matchees, hist, oldest_relevant_datetime, num_groups) matchees, hist, oldest_relevant_datetime, num_groups)
if groups: if groups:
logger.info("Matched groups after %s attempt(s)", logger.info("Matched groups after %s attempt(s)", attempts)
_MAX_ATTEMPTS - attempts)
return groups return groups
# In case we still don't have groups we should progress and # In case we still don't have groups we should progress and
# walk the oldest relevant timestamp forward a week # walk the oldest relevant timestamp forward a week
# Stop bothering if we've gone beyond today # Stop bothering when we finally go beyond today
if attempts % _ATTEMPTS_PER_TIME == 0: if attempts % _ATTEMPTS_PER_TIMESTEP == 0:
oldest_relevant_datetime += _ATTEMPT_RELEVANCY_STEP oldest_relevant_datetime += _ATTEMPT_RELEVANCY_TIMESTEP
if oldest_relevant_datetime > datetime.now(): if oldest_relevant_datetime > datetime.now():
break break
# If we've still failed, just use the simple method # If we've still failed, just use the simple method
logger.info("Fell back to simple groups after %s attempt(s)", logger.info("Fell back to simple groups after %s attempt(s)", attempts)
_MAX_ATTEMPTS - attempts)
return members_to_groups_simple(matchees, num_groups) return members_to_groups_simple(matchees, num_groups)