ajout des disponibilités de joueurs et ajouts d'un tableau qui montre les dispo des joueurs lors de la création d'un match

This commit is contained in:
cedrick2711
2026-07-14 18:46:45 -04:00
parent 4e7ecf0ab9
commit b19d5db8db
17 changed files with 1706 additions and 218 deletions
+51 -13
View File
@@ -1,11 +1,15 @@
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
from extensions import db, hash_password
from models import User, Tryout, TryoutRegistration, Evaluation, Team, TeamMember, OrgTeam, PlayerDisponibility
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'))
@@ -67,7 +71,7 @@ def seed_database():
users.append(user)
db.session.commit()
print(f" Created {len(users)} users")
print(f"[OK] Created {len(users)} users")
# Map users for easy access
user_map = {u.username: u for u in users}
@@ -96,7 +100,7 @@ def seed_database():
db.session.add(ot)
org_teams.append(ot)
db.session.commit()
print(f" Created {len(org_teams)} organization teams")
print(f"[OK] Created {len(org_teams)} organization teams")
# Create tryouts
tryouts_data = [
@@ -121,7 +125,7 @@ def seed_database():
db.session.add(t)
tryouts.append(t)
db.session.commit()
print(f" Created {len(tryouts)} tryouts")
print(f"[OK] Created {len(tryouts)} tryouts")
# Register players for tryouts
registrations_data = [
@@ -142,7 +146,7 @@ def seed_database():
db.session.add(reg)
regs.append(reg)
db.session.commit()
print(f" Created {len(regs)} registrations")
print(f"[OK] Created {len(regs)} registrations")
# Create evaluations (for in_progress and completed tryouts)
eval_data = []
@@ -200,7 +204,7 @@ def seed_database():
eval_data.append(eval_entry)
db.session.commit()
print(f" Created {len(eval_data)} evaluations")
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)
@@ -222,7 +226,7 @@ def seed_database():
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")
print("[OK] Created 2 tryout-specific teams with player assignments")
# Assign players to organization teams
org_team_assignments = [
@@ -238,9 +242,40 @@ def seed_database():
for org_team, player in org_team_assignments:
player.team_id = org_team.id
db.session.commit()
print("✓ Assigned players to organization teams")
# 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🎉 Database seeded successfully!")
print("\n[SUCCESS] Database seeded successfully!")
print("\n=== Login Credentials ===")
print("President: username='president', password='password'")
print("Manager: username='manager1', password='password'")
@@ -251,4 +286,7 @@ def seed_database():
print("Scout: username='scout1', password='password'")
if __name__ == '__main__':
seed_database()
from app import create_app
app = create_app()
with app.app_context():
seed_database()