Ejemplo n.º 1
0
def create_new_season(current_season, end_date):

    # New season.
    logger.info("detected season change")

    # New season date is not super important, ladders around break will end up in correct season, so
    # set it to today + 1 day.
    season = current_season

    season.end_date = end_date
    season.save()
    logger.info("set end date %s on season %d" % (season.end_date, season.id))

    next_season = season.get_next()
    next_season.start_date = end_date + timedelta(days=1)
    next_season.year = next_season.start_date.year
    next_season.number = 1 if next_season.year != season.year else season.number + 1
    next_season.name = "%d Season %d" % (next_season.year, next_season.number)
    next_season.save()
    logger.info("set start data %s, year, name and number on season %d" %
                (next_season.start_date, next_season.id))

    next_next_season = Season(id=next_season.id + 1,
                              start_date=None,
                              end_date=None,
                              year=0,
                              number=0,
                              name='',
                              version=Version.LOTV)
    next_next_season.save()
    logger.info("created empty season %d" % next_next_season.id)

    # Fixing rankings if they ended up with data time after season end.

    rankings = Ranking.objects.filter(
        season=season,
        status__in=(Ranking.COMPLETE_WITH_DATA, Ranking.COMPLETE_WITOUT_DATA),
        data_time__gte=season.end_time()).order_by('-id')

    for i, ranking in enumerate(rankings):
        ranking.data_time = season.end_time() - timedelta(seconds=i)
        ranking.save()
        logger.info(
            "changed data_time to %s for ranking %d since it was after season break"
            % (ranking.data_time, ranking.id))

    # Warn about the event to make monitoring send eamil.

    logger.warning(
        "season break detected, current is now season %d, start_date %s" %
        (next_season.id, next_season.start_date))
Ejemplo n.º 2
0
 def create_season(self, **kwargs):
     kwargs = merge_args(
         {
             'id': 16,
             'start_date': '2013-11-11',
             'end_date': '2014-01-03',
             'name': '2013 Season 6',
             'year': 2013,
             'number': 6,
             'version': Version.HOTS
         }, **kwargs)
     try:
         self.get(Season, id=kwargs['id'])
         raise AssertionError("Season with id %d already exists." %
                              kwargs['id'])
     except Season.DoesNotExist:
         pass
     self.season = Season(**kwargs)
     self.season.save()
     return self.season