"""Database seeding script for Team Tryouts application. This module provides functions to seed the database with sample data including users, tryouts, teams, evaluations, and player disponibilities. """ from sqlalchemy import text from extensions import db, hash_password from models import User, Tryout, TryoutRegistration, Evaluation, Team, TeamMember, OrgTeam, PlayerDisponibility, UserGamertag from datetime import datetime, timedelta, time import random def seed_database(): """Seed the database with sample data for development and testing. Creates sample users with different roles (president, manager, coach, player, scout), organization teams, tryouts, registrations, evaluations, and player disponibilities. All existing data is cleared before seeding. The function creates: - 7 admin users (president, 2 managers, 3 coaches, 1 scout) - 10 player users with E-Sports profiles - 4 organization teams - 4 tryouts - Registrations and evaluations - Player disponibilities for match scheduling """ # Clear existing data db.session.execute(text('DELETE FROM player_disponibilities')) db.session.execute(text('DELETE FROM match_participants')) db.session.execute(text('DELETE FROM matches')) db.session.execute(text('DELETE FROM team_members')) db.session.execute(text('DELETE FROM teams')) db.session.execute(text('DELETE FROM evaluations')) db.session.execute(text('DELETE FROM tryout_registrations')) db.session.execute(text('DELETE FROM tryouts')) db.session.execute(text('DELETE FROM org_teams')) db.session.execute(text('DELETE FROM user_gamertags')) db.session.execute(text('DELETE FROM users')) db.session.commit() # Create users with different roles users_data = [ {'username': 'president', 'password': 'password', 'role': 'president', 'full_name': 'Sarah Johnson', 'email': 'sarah@teampro.com', 'phone': '555-0101'}, {'username': 'manager1', 'password': 'password', 'role': 'manager', 'full_name': 'Mike Williams', 'email': 'mike@teampro.com', 'phone': '555-0102'}, {'username': 'manager2', 'password': 'password', 'role': 'manager', 'full_name': 'Emily Davis', 'email': 'emily@teampro.com', 'phone': '555-0103'}, {'username': 'coach1', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Thompson', 'email': 'coach.t@teampro.com', 'phone': '555-0104'}, {'username': 'coach2', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Martinez', 'email': 'coach.m@teampro.com', 'phone': '555-0105'}, {'username': 'coach3', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Anderson', 'email': 'coach.a@teampro.com', 'phone': '555-0106'}, {'username': 'scout1', 'password': 'password', 'role': 'scout', 'full_name': 'Alex Rivera', 'email': 'alex@teampro.com', 'phone': '555-0107'}, ] # Create players with E-Sports profile data (gamertags per game) player_data = [ {'username': 'jplayer1', 'full_name': 'nordjan', 'email': 'nordjan27@gmail.com', 'games': 'Valorant,Counter-Strike 2, Rainbow Six Siege, Rocket League, Overwatch 2', 'gamertags': {'Valorant': 'nordjan#bad', 'Counter-Strike 2': 'nordjan', 'Rainbow Six Siege': 'n0rd-vpn', 'Rocket League': 'nordjiano'}, 'discord': 'nordjan', 'league_os': 'https://leagueos.gg/player/nordjan'}, {'username': 'jplayer2', 'full_name': 'Emma Garcia', 'email': 'emma@email.com', 'games': 'League of Legends,Valorant', 'gamertags': {'League of Legends': 'emmagarcia_lol', 'Valorant': 'emmagarcia_val'}, 'discord': 'EmmaG#4452', 'league_os': 'https://leagueos.gg/player/emmagarcia'}, {'username': 'jplayer3', 'full_name': 'Liam Brown', 'email': 'liam@email.com', 'games': 'Apex Legends,Fortnite', 'gamertags': {'Apex Legends': 'liambrown_apex', 'platform': 'PC', 'Fortnite': 'liambrown_fn', 'platform_fn': 'PC'}, 'discord': 'LiamB#8103', 'league_os': 'https://leagueos.gg/player/liambrown'}, {'username': 'jplayer4', 'full_name': 'Sophia Lee', 'email': 'sophia@email.com', 'games': 'Overwatch 2,Valorant', 'gamertags': {'Overwatch 2': 'sophialee_ow', 'platform_ow': 'PC', 'Valorant': 'sophialee_val'}, 'discord': 'SophiaL#3327', 'league_os': 'https://leagueos.gg/player/sophialee'}, {'username': 'jplayer5', 'full_name': 'Noah Taylor', 'email': 'noah@email.com', 'games': 'Counter-Strike 2,Rainbow Six Siege', 'gamertags': {'Counter-Strike 2': 'noahtaylor_cs', 'Rainbow Six Siege': 'noahtaylor_r6', 'platform_r6': 'PC'}, 'discord': 'NoahT#6614', 'league_os': 'https://leagueos.gg/player/noahtaylor'}, {'username': 'jplayer6', 'full_name': 'Olivia Martin', 'email': 'olivia@email.com', 'games': 'Rocket League,Fortnite', 'gamertags': {'Rocket League': 'oliviamartin_rl', 'platform_rl': 'PC', 'Fortnite': 'oliviamartin_fn', 'platform_fn': 'PC'}, 'discord': 'OliviaM#2298', 'league_os': 'https://leagueos.gg/player/oliviamartin'}, {'username': 'jplayer7', 'full_name': 'Ethan Clark', 'email': 'ethan@email.com', 'games': 'Valorant,Apex Legends', 'gamertags': {'Valorant': 'ethanclark_val', 'Apex Legends': 'ethanclark_apex', 'platform_apex': 'PC'}, 'discord': 'EthanC#7743', 'league_os': 'https://leagueos.gg/player/ethanclark'}, {'username': 'jplayer8', 'full_name': 'Ava White', 'email': 'ava@email.com', 'games': 'League of Legends,Counter-Strike 2', 'gamertags': {'League of Legends': 'avawhite_lol', 'Counter-Strike 2': 'avawhite_cs'}, 'discord': 'AvaW#5561', 'league_os': 'https://leagueos.gg/player/avawhite'}, {'username': 'jplayer9', 'full_name': 'Mason Hall', 'email': 'mason@email.com', 'games': 'Call of Duty,Rocket League', 'gamertags': {'Call of Duty': 'masonhall_cod', 'platform_cod': 'PC', 'Rocket League': 'masonhall_rl', 'platform_rl': 'PC'}, 'discord': 'MasonH#1189', 'league_os': 'https://leagueos.gg/player/masonhall'}, {'username': 'jplayer10', 'full_name': 'Isabella Adams', 'email': 'isabella@email.com', 'games': 'Overwatch 2,Dota 2', 'gamertags': {'Overwatch 2': 'isabellaadams_ow', 'platform_ow': 'PC', 'Dota 2': 'isabellaadams_dota'}, 'discord': 'IsabellaA#4437', 'league_os': 'https://leagueos.gg/player/isabellaadams'}, ] for i, data in enumerate(player_data, start=10): users_data.append({ 'username': data['username'], 'password': 'password', 'role': 'player', 'full_name': data['full_name'], 'email': data['email'], 'phone': f'555-01{i:02d}', 'games': data['games'], 'gamertags': data.get('gamertags', {}), 'discord_username': data['discord'], 'league_os_profile': data['league_os'] }) users = [] for data in users_data: hashed_pw = hash_password(data['password']) user = User( username=data['username'], password_hash=hashed_pw, role=data['role'], full_name=data['full_name'], email=data['email'], phone=data.get('phone', ''), games=data.get('games'), discord_username=data.get('discord_username'), league_os_profile=data.get('league_os_profile') ) db.session.add(user) users.append(user) db.session.commit() print(f"[OK] Created {len(users)} users") # Map users for easy access user_map = {u.username: u for u in users} president = user_map['president'] manager1 = user_map['manager1'] manager2 = user_map['manager2'] coaches = [user_map['coach1'], user_map['coach2'], user_map['coach3']] scout = user_map['scout1'] players = [user_map[f'jplayer{i}'] for i in range(1, 11)] # Create gamertags for players gamertag_data = [ {'user': users[7], 'game': 'Valorant', 'gamertag': 'jameswilson_val'}, {'user': users[7], 'game': 'Counter-Strike 2', 'gamertag': 'jameswilson_cs'}, {'user': users[8], 'game': 'League of Legends', 'gamertag': 'emmagarcia_lol'}, {'user': users[8], 'game': 'Valorant', 'gamertag': 'emmagarcia_val'}, {'user': users[9], 'game': 'Apex Legends', 'gamertag': 'liambrown_apex', 'platform': 'PC'}, {'user': users[9], 'game': 'Fortnite', 'gamertag': 'liambrown_fn', 'platform': 'PC'}, {'user': users[10], 'game': 'Overwatch 2', 'gamertag': 'sophialee_ow', 'platform': 'PC'}, {'user': users[10], 'game': 'Valorant', 'gamertag': 'sophialee_val'}, {'user': users[11], 'game': 'Counter-Strike 2', 'gamertag': 'noahtaylor_cs'}, {'user': users[11], 'game': 'Rainbow Six Siege', 'gamertag': 'noahtaylor_r6', 'platform': 'Ubisoft'}, {'user': users[12], 'game': 'Rocket League', 'gamertag': 'oliviamartin_rl', 'platform': 'Epic'}, {'user': users[12], 'game': 'Fortnite', 'gamertag': 'oliviamartin_fn', 'platform': 'PC'}, {'user': users[13], 'game': 'Valorant', 'gamertag': 'ethanclark_val'}, {'user': users[13], 'game': 'Apex Legends', 'gamertag': 'ethanclark_apex', 'platform': 'PC'}, {'user': users[14], 'game': 'League of Legends', 'gamertag': 'avawhite_lol'}, {'user': users[14], 'game': 'Counter-Strike 2', 'gamertag': 'avawhite_cs'}, {'user': users[15], 'game': 'Call of Duty', 'gamertag': 'masonhall_cod', 'platform': 'PC'}, {'user': users[15], 'game': 'Rocket League', 'gamertag': 'masonhall_rl', 'platform': 'Epic'}, {'user': users[16], 'game': 'Overwatch 2', 'gamertag': 'isabellaadams_ow', 'platform': 'PC'}, {'user': users[16], 'game': 'Dota 2', 'gamertag': 'isabellaadams_dota'}, ] for gt in gamertag_data: gamertag = UserGamertag( user_id=gt['user'].id, game=gt['game'], gamertag=gt['gamertag'], platform=gt.get('platform') ) db.session.add(gamertag) db.session.commit() print(f"[OK] Created {len(gamertag_data)} user gamertags") # Create Organization Teams (OrgTeams) org_teams_data = [ {'name': 'Rocket League main', 'coach': coaches[0], 'creator': president}, {'name': 'CS2', 'coach': coaches[1], 'creator': president}, {'name': 'Valorant', 'coach': coaches[2], 'creator': president}, {'name': 'Rocket League acad', 'coach': None, 'creator': manager1}, ] org_teams = [] for data in org_teams_data: ot = OrgTeam( name=data['name'], coach_id=data['coach'].id if data['coach'] else None, created_by=data['creator'].id ) db.session.add(ot) org_teams.append(ot) db.session.commit() print(f"[OK] Created {len(org_teams)} organization teams") # Create tryouts tryouts_data = [ {'title': 'Rocket Leauge Tryouts', 'game': 'Rocket League', 'date': datetime.utcnow(), 'location': 'En ligne', 'description': 'Tryouts for the spring competitive season. All positions welcome.', 'status': 'in_progress', 'creator': manager1, 'target_team': org_teams[0]}, {'title': 'CS2 Tryouts', 'game': 'Counter-Strike 2', 'date': datetime.utcnow() + timedelta(days=4), 'location': 'En ligne', 'description': 'Trials for the fall select team. High skill level required.', 'status': 'upcoming', 'creator': manager1, 'target_team': org_teams[3]}, {'title': 'Valorant Tryouts', 'game': 'Valorant', 'date': datetime.utcnow() - timedelta(days=2), 'location': 'En ligne', 'description': 'Séléction pour l\'équipe de Valorant', 'status': 'in_progress', 'creator': manager2, 'target_team': org_teams[2]}, ] tryouts = [] for data in tryouts_data: t = Tryout( title=data['title'], game=data['game'], date=data['date'].date(), location=data['location'], description=data['description'], status=data['status'], max_players=15, created_by=data['creator'].id, target_org_team_id=data['target_team'].id if data['target_team'] else None ) db.session.add(t) tryouts.append(t) db.session.commit() print(f"[OK] Created {len(tryouts)} tryouts") # Register players for tryouts registrations_data = [ (tryouts[0], players[:3]), (tryouts[1], players[3:5]), (tryouts[2], players) ] regs = [] for tryout, player_list in registrations_data: for player in player_list: reg = TryoutRegistration( tryout_id=tryout.id, player_id=player.id, status=random.choice(['registered', 'attended', 'attended', 'no_show']) ) db.session.add(reg) regs.append(reg) db.session.commit() print(f"[OK] Created {len(regs)} registrations") # Create evaluations (for in_progress and completed tryouts) eval_data = [] # Spring tryout (Rocket League) - some evaluations rl_positions = ['None needed', 'None', 'N/A'] for player in players[:8]: for coach in coaches: if random.random() > 0.3: mecanics = random.randint(4, 10) cohesion = random.randint(4, 10) communication = random.randint(3, 10) gamesense = random.randint(5, 10) versatility = random.randint(5, 10) discipline = random.randint(4, 10) analysis = random.randint(4, 10) sport_ethics = random.randint(5, 10) mental = random.randint(5, 10) overall = round((mecanics + cohesion + communication + gamesense + versatility + discipline + analysis + sport_ethics + mental) / 9, 1) eval_entry = Evaluation( tryout_id=tryouts[0].id, player_id=player.id, evaluator_id=coach.id, mecanics_score=mecanics, cohesion_score=cohesion, communication_score=communication, gamesense_score=gamesense, versatility_score=versatility, discipline_score=discipline, analysis_score=analysis, sport_ethics_score=sport_ethics, mental_score=mental, overall_score=overall, comments=f"{'Great' if overall > 7 else 'Good'} performance. {'Shows promise.' if overall > 6 else 'Needs improvement in some areas.'}", position_recommendation=random.choice(rl_positions) ) db.session.add(eval_entry) eval_data.append(eval_entry) # Completed tryout (Valorant) - full evaluations val_positions = ['Controller', 'Initiator', 'Duelist', 'Sentinel'] for player in players[:6]: for coach in coaches[:2]: mecanics = random.randint(3, 10) cohesion = random.randint(3, 10) communication = random.randint(3, 10) gamesense = random.randint(4, 10) versatility = random.randint(4, 10) discipline = random.randint(3, 10) analysis = random.randint(3, 10) sport_ethics = random.randint(4, 10) mental = random.randint(4, 10) overall = round((mecanics + cohesion + communication + gamesense + versatility + discipline + analysis + sport_ethics + mental) / 9, 1) eval_entry = Evaluation( tryout_id=tryouts[2].id, player_id=player.id, evaluator_id=coach.id, mecanics_score=mecanics, cohesion_score=cohesion, communication_score=communication, gamesense_score=gamesense, versatility_score=versatility, discipline_score=discipline, analysis_score=analysis, sport_ethics_score=sport_ethics, mental_score=mental, overall_score=overall, comments=f"{'Excellent' if overall > 8 else 'Solid'} display of skills during the camp.", position_recommendation=random.choice(val_positions) ) db.session.add(eval_entry) eval_data.append(eval_entry) db.session.commit() print(f"[OK] Created {len(eval_data)} evaluations") # Create teams for the completed tryout (tryout-specific teams) team1 = Team(tryout_id=tryouts[2].id, name='Alpha Team', created_by=president.id) team2 = Team(tryout_id=tryouts[2].id, name='Bravo Team', created_by=president.id) db.session.add(team1) db.session.add(team2) db.session.commit() # Assign players to teams (Valorant tryout uses Valorant positions) val_positions = ['Controller', 'Initiator', 'Duelist', 'Sentinel'] team_members_data = [ (team1.id, players[0].id, random.choice(val_positions)), (team1.id, players[1].id, random.choice(val_positions)), (team1.id, players[2].id, random.choice(val_positions)), (team1.id, players[3].id, random.choice(val_positions)), (team2.id, players[4].id, random.choice(val_positions)), (team2.id, players[5].id, random.choice(val_positions)), ] for team_id, player_id, position in team_members_data: tm = TeamMember(team_id=team_id, player_id=player_id, position=position) db.session.add(tm) db.session.commit() print("[OK] Created 2 tryout-specific teams with player assignments") # Assign players to organization teams org_team_assignments = [ (org_teams[0], players[0]), (org_teams[0], players[1]), (org_teams[0], players[2]), (org_teams[1], players[3]), (org_teams[1], players[4]), (org_teams[1], players[5]), (org_teams[2], players[6]), (org_teams[2], players[7]), ] for org_team, player in org_team_assignments: player.team_id = org_team.id db.session.commit() # Create sample disponibilities for players # Time slots from 5pm to 11pm (stored as 17:00-23:00) time_slots = [(17, 0), (17, 30), (18, 0), (18, 30), (19, 0), (19, 30), (20, 0), (20, 30), (21, 0), (21, 30), (22, 0), (22, 30), (23, 0)] disponibilities = [] for player in players: # Each player gets random disponibilities for day in range(7): # All days of the week num_slots = random.randint(3, 8) chosen_slots = random.sample(time_slots, min(num_slots, len(time_slots))) for hour, minute in chosen_slots: start_time = time(hour, minute) # End time is start_time + 30 minutes end_minute = minute + 30 end_hour = hour if end_minute >= 60: end_minute -= 60 end_hour += 1 end_time = time(end_hour, end_minute) d = PlayerDisponibility( player_id=player.id, day_of_week=day, start_time=start_time, end_time=end_time ) db.session.add(d) disponibilities.append(d) db.session.commit() print(f"[OK] Created {len(disponibilities)} player disponibilities") print("\n[SUCCESS] Database seeded successfully!") print("\n=== Login Credentials ===") print("President: username='president', password='password'") print("Manager: username='manager1', password='password'") print("Coach: username='coach1', password='password' (assigned to Varsity)") print("Coach: username='coach2', password='password' (assigned to Junior Varsity)") print("Coach: username='coach3', password='password' (assigned to U14 Development)") print("Player: username='jplayer1', password='password'") print("Scout: username='scout1', password='password'") if __name__ == '__main__': from app import create_app app = create_app() with app.app_context(): seed_database()