Esempio n. 1
0
def build_games():
    if Game.objects.count():
        print('Already loaded games')
        return

    game_ids = Play.objects.distinct('gameid')
    counter = 0
    for game_id in game_ids:
        if not game_id:
            continue
        plays = Play.objects.filter(gameid=game_id).order_by('clock')
        game = Game(
            gameid=game_id,
            home=plays[0].home,
            away=plays[0].away,
            season=plays[0].season,
            date=plays[0].date
        )
        game.save()
        for play in plays:
            game.update(push__plays=play)
        if plays.count() < 50:
            print('Game has less than 50 plays')
            print(game.__repr__())
        counter += 1
        if counter % 25 == 0:
            print('Added ' + str(counter) + ' games')
Esempio n. 2
0
def build_season():
    if Season.objects.count():
        print('Already loaded seasons')
        return

    seasons = Game.objects.distinct('season')
    for team in Team.objects():
        print("Parsing " + team.name)
        for season in seasons:
            games = Game.objects(Q(home=team) | Q(away=team)).filter(season=season)
            doc = Season(
                team=team,
                season=season
            )
            doc.save()
            for game in games:
                doc.update(push__games=game)

            if games.count() < 16:
                print('Season has less than 16 games')
                print(season.__repr__())