Example #1
0
    def create_games(n=20, site_sport=None, round_start_times=False):
        # site_sport, created = SiteSport.objects.get_or_create(name=sport)
        dt_now = timezone.now()
        unix_ts = int(
            dt_now.strftime('%s'))  # unix timestamp as srid ... not bad
        games = []
        ssm = SiteSportManager()
        season_model_class = ssm.get_season_class(site_sport)

        # dum_srid        = '%s'%site_sport
        # dum_season_year = 2016
        # dum_season_type = 'reg'
        # dum_season, created = season_model_class.objects.get_or_create(srid=dum_srid,
        #                             season_year=dum_season_year, season_type=dum_season_type)

        for x in range(0, n):
            game = Dummy.create_game(srid='%s' % (unix_ts + x),
                                     site_sport=site_sport,
                                     round_start_times=round_start_times)
            # game.season = dum_season # cant be null
            game.start = game.start + timedelta(
                minutes=x)  # stagger each game by 1 minute
            game.save()
            games.append(game)

        return games
Example #2
0
    def create_game(srid=None,
                    status='scheduled',
                    away=None,
                    home=None,
                    site_sport=None,
                    round_start_times=False):
        # site_sport, created = SiteSport.objects.get_or_create(name=sport)

        ssm = SiteSportManager()
        season_model_class = ssm.get_season_class(site_sport)
        dum_srid = '%s' % site_sport
        dum_season_year = 2016
        dum_season_type = 'reg'
        dum_season, created = season_model_class.objects.get_or_create(
            srid=dum_srid,
            season_year=dum_season_year,
            season_type=dum_season_type,
        )

        if srid is None:
            srid = "srid-%s" % int(round(time.time() * 1000)),
        if away is None:
            away = Dummy.create_team(alias='AWAY', site_sport=site_sport)
        if home is None:
            home = Dummy.create_team(alias='HOME', site_sport=site_sport)

        dt_now = timezone.now()
        if round_start_times:
            # zero out the seconds and microseconds!
            dt_now = dt_now.replace(dt_now.year, dt_now.month, dt_now.day,
                                    dt_now.hour, dt_now.minute, 0, 0)

        if site_sport is None:
            game = GameChild()
        else:
            ssm = SiteSportManager()
            game_model = ssm.get_game_class(site_sport)
            game = game_model()

        game.season = dum_season  # cant be None
        game.srid = srid
        game.start = dt_now
        game.status = status

        game.away = away
        game.home = home

        game.save()
        return game