254 lines
13 KiB
Python
254 lines
13 KiB
Python
from extensions import db, hash_password
|
|
from models import User, Tryout, TryoutRegistration, Evaluation, Team, TeamMember, OrgTeam
|
|
from datetime import datetime, timedelta
|
|
import random
|
|
from sqlalchemy import text
|
|
|
|
def seed_database():
|
|
# Clear existing data
|
|
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 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
|
|
player_data = [
|
|
{'username': 'jplayer1', 'full_name': 'James Wilson', 'email': '[email protected]', 'games': 'Valorant,Counter-Strike 2', 'trn': 'jameswilson_tr', 'discord': 'JamesW#7291', 'league_os': 'https://leagueos.gg/player/jameswilson'},
|
|
{'username': 'jplayer2', 'full_name': 'Emma Garcia', 'email': '[email protected]', 'games': 'League of Legends,Valorant', 'trn': 'emmagarcia_gg', 'discord': 'EmmaG#4452', 'league_os': 'https://leagueos.gg/player/emmagarcia'},
|
|
{'username': 'jplayer3', 'full_name': 'Liam Brown', 'email': '[email protected]', 'games': 'Apex Legends,Fortnite', 'trn': 'liambrown_fn', 'discord': 'LiamB#8103', 'league_os': 'https://leagueos.gg/player/liambrown'},
|
|
{'username': 'jplayer4', 'full_name': 'Sophia Lee', 'email': '[email protected]', 'games': 'Overwatch 2,Valorant', 'trn': 'sophialee_ow', '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', 'trn': 'noahtaylor_r6', 'discord': 'NoahT#6614', 'league_os': 'https://leagueos.gg/player/noahtaylor'},
|
|
{'username': 'jplayer6', 'full_name': 'Olivia Martin', 'email': '[email protected]', 'games': 'Rocket League,Fortnite', 'trn': 'oliviamartin_rl', 'discord': 'OliviaM#2298', 'league_os': 'https://leagueos.gg/player/oliviamartin'},
|
|
{'username': 'jplayer7', 'full_name': 'Ethan Clark', 'email': '[email protected]', 'games': 'Valorant,Apex Legends', 'trn': 'ethanclark_val', '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', 'trn': 'avawhite_lol', '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', 'trn': 'masonhall_cod', 'discord': 'MasonH#1189', 'league_os': 'https://leagueos.gg/player/masonhall'},
|
|
{'username': 'jplayer10', 'full_name': 'Isabella Adams', 'email': '[email protected]', 'games': 'Overwatch 2,Dota 2', 'trn': 'isabellaadams_ow', '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'], 'trn_username': data['trn'],
|
|
'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'),
|
|
trn_username=data.get('trn_username'),
|
|
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"✓ 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 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"✓ 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"✓ 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"✓ 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"✓ 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("✓ 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()
|
|
print("✓ Assigned players to organization teams")
|
|
|
|
print("\n🎉 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__':
|
|
seed_database() |