Files
team-tryouts/seed.py
T

347 lines
18 KiB
Python

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():
# 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': '[email protected]', 'phone': '555-0101'},
{'username': 'manager1', 'password': 'password', 'role': 'manager', 'full_name': 'Mike Williams', 'email': '[email protected]', 'phone': '555-0102'},
{'username': 'manager2', 'password': 'password', 'role': 'manager', 'full_name': 'Emily Davis', 'email': '[email protected]', 'phone': '555-0103'},
{'username': 'coach1', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Thompson', 'email': '[email protected]', 'phone': '555-0104'},
{'username': 'coach2', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Martinez', 'email': '[email protected]', 'phone': '555-0105'},
{'username': 'coach3', 'password': 'password', 'role': 'coach', 'full_name': 'Coach Anderson', 'email': '[email protected]', 'phone': '555-0106'},
{'username': 'scout1', 'password': 'password', 'role': 'scout', 'full_name': 'Alex Rivera', 'email': '[email protected]', 'phone': '555-0107'},
]
# Create players with E-Sports profile data (gamertags per game)
player_data = [
{'username': 'jplayer1', 'full_name': 'James Wilson', 'email': '[email protected]', 'games': 'Valorant,Counter-Strike 2',
'gamertags': {'Valorant': 'jameswilson_val', 'Counter-Strike 2': 'jameswilson_cs'},
'discord': 'JamesW#7291', 'league_os': 'https://leagueos.gg/player/jameswilson'},
{'username': 'jplayer2', 'full_name': 'Emma Garcia', 'email': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': '[email protected]', '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': 'Varsity', 'coach': coaches[0], 'creator': president},
{'name': 'Junior Varsity', 'coach': coaches[1], 'creator': president},
{'name': 'U14 Development', 'coach': coaches[2], 'creator': president},
{'name': 'Select Team', 'coach': None, 'creator': president},
]
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': 'Spring Season Tryouts', 'date': datetime.utcnow() - timedelta(days=5), 'location': 'Main Stadium', 'description': 'Tryouts for the spring competitive season. All positions welcome.', 'status': 'in_progress', 'creator': manager1, 'target_team': org_teams[0]},
{'title': 'Fall Select Team Trials', 'date': datetime.utcnow() + timedelta(days=20), 'location': 'Training Center', 'description': 'Trials for the fall select team. High skill level required.', 'status': 'upcoming', 'creator': manager1, 'target_team': org_teams[3]},
{'title': 'Youth Development Camp', 'date': datetime.utcnow() - timedelta(days=20), 'location': 'Community Field', 'description': 'Development camp for younger players to showcase their skills.', 'status': 'completed', 'creator': manager2, 'target_team': org_teams[2]},
{'title': 'Winter Indoor Showcase', 'date': datetime.utcnow() - timedelta(days=2), 'location': 'Indoor Arena', 'description': 'Indoor showcase event for scouting and team selection.', 'status': 'in_progress', 'creator': manager2, 'target_team': org_teams[1]},
]
tryouts = []
for data in tryouts_data:
t = Tryout(
title=data['title'],
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[:8]),
(tryouts[1], players),
(tryouts[2], players[:6]),
(tryouts[3], players[2:9]),
]
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'])
)
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 - some evaluations
for player in players[:8]:
for coach in coaches:
if random.random() > 0.3:
speed = random.randint(4, 10)
agility = random.randint(4, 10)
technique = random.randint(3, 10)
teamwork = random.randint(5, 10)
attitude = random.randint(5, 10)
overall = round((speed + agility + technique + teamwork + attitude) / 5, 1)
positions = ['Forward', 'Midfield', 'Defense', 'Goalie', 'Wing', 'Center']
eval_entry = Evaluation(
tryout_id=tryouts[0].id,
player_id=player.id,
evaluator_id=coach.id,
speed_score=speed,
agility_score=agility,
technique_score=technique,
teamwork_score=teamwork,
attitude_score=attitude,
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(positions)
)
db.session.add(eval_entry)
eval_data.append(eval_entry)
# Completed tryout - full evaluations
for player in players[:6]:
for coach in coaches[:2]:
speed = random.randint(3, 10)
agility = random.randint(3, 10)
technique = random.randint(3, 10)
teamwork = random.randint(4, 10)
attitude = random.randint(4, 10)
overall = round((speed + agility + technique + teamwork + attitude) / 5, 1)
positions = ['Forward', 'Midfield', 'Defense', 'Goalie', 'Wing', 'Center']
eval_entry = Evaluation(
tryout_id=tryouts[2].id,
player_id=player.id,
evaluator_id=coach.id,
speed_score=speed,
agility_score=agility,
technique_score=technique,
teamwork_score=teamwork,
attitude_score=attitude,
overall_score=overall,
comments=f"{'Excellent' if overall > 8 else 'Solid'} display of skills during the camp.",
position_recommendation=random.choice(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
team_members_data = [
(team1.id, players[0].id, 'Forward'),
(team1.id, players[1].id, 'Midfield'),
(team1.id, players[2].id, 'Defense'),
(team1.id, players[3].id, 'Goalie'),
(team2.id, players[4].id, 'Midfield'),
(team2.id, players[5].id, 'Forward'),
]
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()