def save_matches(queue): time.sleep(random.random()) while not queue.empty(): tokens = queue.get() if Team.objects.filter(name=tokens['home_team']).count() == 0: Team(name=tokens['home_team'], wins=0).save() if Team.objects.filter(name=tokens['away_team']).count() == 0: Team(name=tokens['away_team'], wins=0).save() team1_id = Team.objects.filter( name=tokens['home_team']).values('id')[0]['id'] team2_id = Team.objects.filter( name=tokens['away_team']).values('id')[0]['id'] team1 = Team.objects.filter(name=tokens['home_team'])[0] team2 = Team.objects.filter(name=tokens['away_team'])[0] if Match.objects.filter(Q(home_team=team1_id) & Q(away_team=team2_id)).count() == 0: Match(home_team=team1, away_team=team2, home_score=tokens['first_match_home'], away_score=tokens['first_match_away']).save() if Match.objects.filter(home_team=team2).filter( away_team=team1).count() == 0: Match(home_team=team2, away_team=team1, home_score=tokens['second_match_home'], away_score=tokens['second_match_away']).save() winner_name = Match.get_winner(tokens) winner_team = Team.objects.get(name=winner_name) winner_team.wins += 1 winner_team.save()
def start(self): c = int(self.count / 10) for i in range(c): t1 = Team( name='team_{}'.format(i), games=self.count, ) t2 = Team( name='team_{}'.format(i), games=self.count, ) t1.save(using='db1') t2.save(using='db2') for j in range(10): u = User(username='******'.format(j + 10 * i), email='ivan@ivan{}.ru'.format(j + 10 * i)) u.set_password('ivan123') u.first_name = 'ivan{}'.format(j + 10 * i) u.last_name = 'ivanov{}'.format(j + 10 * i) ran_db = random.randint(1, 2) u.id = int(get_pk() + str(ran_db)) print(u.id) u.save(using='db' + str(ran_db)) if ran_db == 1: tu = UserTeam( user=u, team=t1, ) else: tu = UserTeam( user=u, team=t2, ) tu.save(using='db' + str(ran_db)) cc = int(self.count / 100) for i in range(cc): t = Turn(name='turn{}'.format(i)) t.save(using='db1') t.save(using='db2') for j in range(10): m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id) m.save(using='db1') m.save(using='db2') for l in range(10): g = Game(name='game___{}'.format(l + 10 * j + 100 * i), match_id=m.id) ran_db = random.randint(1, 2) g.id = int(get_pk() + str(ran_db)) g.save(using='db' + str(ran_db)) tm = Team.objects.using('db' + str(ran_db)).filter( name='team_{}'.format(j + 10 * i))[0] gt = GameTeam(game=g, team=tm) gt.save(using='db' + str(ran_db))
def handle(self, *args, **options): team_objs = [ Team(name="Team %s" % (i + 1), logo_file="team.jpg", club="Club Name") for i in range(self.no_of_teams) ] Team.objects.bulk_create(team_objs) teams = Team.objects.all() for team in teams: player_objs = [ Player( team=team, first_name="Player", last_name="%s" % (i + 1), image_file="player.jpg", jersey_number=random.randint(i * 5, (i * 5) + 5), country="County Name", ) for i in range(11) ] Player.objects.bulk_create(player_objs)
def populatedb(request): myTeams = ['Real Madrid', 'Barcelona'] myCompetitions = ['La liga', 'English Premier League'] myMarkets = ['Match Odds', 'Half Time'] for market in myMarkets: try: Market.objects.get(market_name=market) print("Encontrado o market " + market) except ObjectDoesNotExist: print("A criar o market " + market) x = Market(market_name=market) x.save() for competition in myCompetitions: try: Competition.objects.get(competition_name=competition) print("Encontrada a competition " + competition) except ObjectDoesNotExist: print("A criar a competition " + competition) x = Competition(competition_name=competition) x.save() for team in myTeams: try: Team.objects.get(team_name=team) print("Encontrada a Team " + team) except ObjectDoesNotExist: print("A criar a team " + team) x = Team(team_name=team) x.save() return HttpResponseRedirect('/Trade/')
def invite(name, leader, tel, mail): inv_code = str(random6()) if Pwd.objects.filter(mail=mail).count() > 0: return None pwd = Pwd(mail=mail, invite_code=inv_code, state=1) pwd.save() team = Team(pwd=pwd, name=name, leader=leader, contact_tel=tel) team.save() return pwd.invite_code
def generate(using, count): for i in range(count): t = Team(name='team{}'.format(count), games=count, admin_id=1) t.save(using=using) for j in range(10): u = User.objects.get(username='******'.format(j + 10 * i)) tu = UserTeam( user=u, team=t, ) tu.save(using=using)
def setUp(self): self.user = get_user_model()(username='******', email='*****@*****.**') self.user.save() self.team = Team(name='team-test', password='******', description='', owner=self.user) self.team.save() self.user.team = self.team self.user.save() self.admin_user = get_user_model()(username='******', email='*****@*****.**') self.admin_user.is_staff = True self.admin_user.save()
def setUp(self): self.user = get_user_model()( username="******", email="*****@*****.**" ) self.user.save() self.team = Team( name="team-test", password="******", description="", owner=self.user ) self.team.save() self.user.team = self.team self.user.save() self.admin_user = get_user_model()( username="******", email="*****@*****.**" ) self.admin_user.is_staff = True self.admin_user.save()
def setUp(self): user = get_user_model()(username='******', email='*****@*****.**') user.save() admin_user = get_user_model()( username='******', email='*****@*****.**') admin_user.is_staff = True admin_user.save() team = Team(name='recalculate-team', owner=user, password='******') team.save() user.team = team user.save() self.user = user self.admin_user = admin_user self.team = team
def createteam(): for i in range(0, len(TEAM)): Team().create_team(name=TEAM[i]) print("Team %s created successfully" % TEAM[i]) for j in range(0, 11): name = "player_%s_%s" % (j, TEAM[i]) coach = False height = float(randrange(60, 70) / 10) score = 0 if j == 0: name = "coach_%s_%s" % (j, TEAM[i]) coach = True score = None Players().create_players(team=TEAM[i], name=name, coach=coach, height=height, score=score) print("Players created successfully")
def populate(): for i in range(15): user = get_user_model()(username=f'scorelist-test{i}', email=f'scorelist-test{i}@example.org') user.save() team = Team(name=f'scorelist-test{i}', password=f'scorelist-test{i}', owner=user) team.points = i * 100 team.leaderboard_points = i * 100 team.save() user.team = team user.points = i * 100 user.leaderboard_points = i * 100 user.save() Score(team=team, user=user, reason='test', points=i * 100).save()
def setUp(self): user = get_user_model()( username="******", email="*****@*****.**" ) user.save() admin_user = get_user_model()( username="******", email="*****@*****.**", ) admin_user.is_staff = True admin_user.save() team = Team(name="recalculate-team", owner=user, password="******") team.save() user.team = team user.save() self.user = user self.admin_user = admin_user self.team = team
def create_team(request, is_commissioner=0, league_id=''): global errors league_id = request.POST.get('leagueId', league_id) team_name = request.POST.get('teamName', '') password = request.POST.get('entryKey', '') errors = [] if not (league_id and team_name): errors.append("<br/> League id and/or team_name is none!") return None l = League.objects.get(league_id=league_id) teams = l.team_set.all() user = request.user if (not is_commissioner) and (l.password) and (password != l.password): errors.append("<br/> - Password did not match!") if l.settings.number_of_teams <= len(teams): errors.append("<br/> - league is already full!") print errors, l.settings.number_of_teams, teams if user in [t.user for t in teams]: errors.append( "<br/> - you (%s) already have a team in this league! click inside the league to know about it." % request.user) print errors, user, [t.user for t in teams] if errors: return None vendor_team_id = generate_random_id(4) vendor_user_id = 'xxyyzz' waiver_priority = 1 division = '' draft_pick_number = get_draft_pick_number(l) t = Team(league=l, user=user, vendor_team_id=vendor_team_id, vendor_user_id=vendor_user_id, team_name=team_name, waiver_priority=waiver_priority, division=division, is_commissioner=is_commissioner, draft_pick_number=draft_pick_number) return t
def start(self): c = int(self.count / 10) for i in range(c): t = Team( name='team{}'.format(i), games=self.count, ) t.save(using=self.using) for j in range(10): u = User(username='******'.format(j + 10 * i), email='ivan@ivan{}.ru'.format(j + 10 * i)) u.set_password('ivan123') u.first_name = 'ivan{}'.format(j + 10 * i) u.last_name = 'ivanon{}'.format(j + 10 * i) u.save(using=self.using) tu = UserTeam( user=u, team=t, ) tu.save(using=self.using) cc = int(self.count / 100) for i in range(cc): t = Turn(name='turn{}'.format(i)) t.save(using=self.using) for j in range(10): m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id) m.save(using=self.using) for l in range(10): g = Game(name='game{}'.format(l + 10 * j + 100 * i), match_id=m.id) g.save(using=self.using) tm = Team.objects.using( self.using).get(name='team{}'.format(j + 10 * i)) print(g.name, t.name) gt = GameTeam(game=g, team=tm) gt.save(using=self.using)
def setUp(self): self.team_id = "1" self.team_name = "India" self.team_image = "India.png" self.team = Team(name=self.team_name, image=self.team_image)
def create(self, name: str, description: str) -> Team: team = Team(name=name, description=description) team.save() return team
def test_create_team(self): team = mixer.blend(Team) Team().create_team(name=team.name) new_Team = Team.objects.filter(name=team.name).first() assert new_Team.name == team.name
def handle(self, *args, **options): print('Creating 10 categories...') for i in range(10): category = Category(name='category-' + str(i), display_order=i, contained_type='test', description='Category ' + str(i)) category.save() print('Creating 100 challenges for each category...') for i in range(10): category = Category.objects.get(name='category-' + str(i)) for j in range(50): challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category, description='An example challenge ' + str(j), flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j, challenge_metadata={}) challenge.save() for j in range(50, 100, 2): challenge = Challenge(name='cat-' + str(i) + '-chal-' + str(j), category=category, description='An example challenge ' + str(j), flag_metadata={'flag': f'ractf{{{j}}}'}, author='dave', auto_unlock=True, score=j, challenge_metadata={}) challenge2 = Challenge(name='cat-' + str(i) + '-chal-' + str(j + 1), category=category, description='An example challenge ' + str(j + 1), flag_metadata={'flag': f'ractf{{{j + 1}}}'}, author='dave', auto_unlock=False, score=j, challenge_metadata={}) challenge2.save() challenge.save() challenge.unlocks.add(challenge2) print('Creating 20000 users with 10000 teams with 100 solves per team...') for i in range(10000): user = get_user_model()(username='******' + str(i), email='user-' + str(i) + '@example.org') user.save() team = Team(name='team-' + str(i), password='******', owner=user) team.save() user2 = get_user_model()(username='******' + str(i) + '-second', email='user-' + str(i) + '*****@*****.**', team=team) user2.save() for j in range(50): challenge = Category.objects.get(name='category-' + str(j % 5))\ .category_challenges.get(name='cat-' + str(j % 5) + '-chal-' + str(j)) points = random.randint(0, 1000) score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True) score.save() solve = Solve(team=team, solved_by=user, challenge=challenge, first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True) solve.save() user.points += points team.points += points user.leaderboard_points += points team.leaderboard_points += points for j in range(50): challenge = Category.objects.get(name='category-' + str(j % 5 + 5))\ .category_challenges.get(name='cat-' + str(j % 5 + 5) + '-chal-' + str(j)) points = random.randint(0, 1000) score = Score(team=team, reason='challenge', points=points, penalty=0, leaderboard=True) score.save() solve = Solve(team=team, solved_by=user2, challenge=challenge, first_blood=challenge.first_blood is None, flag='ractf{}', score=score, correct=True) solve.save() user2.points += points team.points += points user.leaderboard_points += points team.leaderboard_points += points
def setUp(self): category = Category(name='test', display_order=0, contained_type='test', description='') category.save() challenge1 = Challenge(name='test1', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000) challenge2 = Challenge(name='test2', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000, auto_unlock=True) challenge3 = Challenge(name='test3', category=category, description='a', challenge_type='basic', challenge_metadata={}, flag_type='plaintext', flag_metadata={'flag': 'ractf{a}'}, author='dave', score=1000, auto_unlock=False) challenge1.save() challenge2.save() challenge3.save() challenge2.unlocks.add(challenge1) challenge2.save() hint1 = Hint(name='hint1', challenge=challenge1, text='a', penalty=100) hint2 = Hint(name='hint2', challenge=challenge1, text='a', penalty=100) hint3 = Hint(name='hint3', challenge=challenge2, text='a', penalty=100) hint1.save() hint2.save() hint3.save() user = get_user_model()(username='******', email='*****@*****.**') user.save() team = Team(name='team', password='******', owner=user) team.save() user.team = team user.save() user2 = get_user_model()(username='******', email='*****@*****.**') user2.team = team user2.save() user3 = get_user_model()(username='******', email='*****@*****.**') user3.save() team2 = Team(name='team2', password='******', owner=user3) team2.save() user3.team = team2 user3.save() self.user = user self.user2 = user2 self.user3 = user3 self.team = team self.team2 = team2 self.category = category self.challenge1 = challenge1 self.challenge2 = challenge2 self.challenge3 = challenge3 self.hint1 = hint1 self.hint2 = hint2 self.hint3 = hint3