-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_flights_script.py
More file actions
76 lines (64 loc) · 2.71 KB
/
debug_flights_script.py
File metadata and controls
76 lines (64 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import django
from datetime import datetime, timedelta
import random
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'flight_simulator.settings')
django.setup()
from flights.repositories import FlightRepository
from flights.models import Flight
def debug_flights():
repo = FlightRepository()
flights = repo.find_all()
print(f"Total Flights in DB: {len(flights)}")
print(f"Total Flights in DB: {len(flights)}")
print("Seeding flights...")
seed_flights(repo)
def seed_flights(repo):
origins = ['JFK', 'LHR', 'LAX', 'SFO', 'DXB', 'SIN', 'HND', 'CDG']
destinations = ['JFK', 'LHR', 'LAX', 'SFO', 'DXB', 'SIN', 'HND', 'CDG']
airlines = ['AA', 'BA', 'DL', 'EK', 'SQ', 'JL', 'AF']
new_flights = []
start_date = datetime.now()
for i in range(30):
current_date = start_date + timedelta(days=i)
for hour in [9, 14, 19]:
departure = current_date.replace(hour=hour, minute=0, second=0, microsecond=0)
arrival = departure + timedelta(hours=7)
flight = Flight(
flight_id=f"FL_JFK_LHR_{i}_{hour}",
flight_number=f"BA{random.randint(100, 999)}",
airline_code="BA",
origin="JFK",
destination="LHR",
departure_time=departure,
arrival_time=arrival,
base_price=random.randint(400, 900),
total_seats=300,
available_seats=random.randint(100, 300)
)
new_flights.append(flight)
for _ in range(5):
origin = random.choice(origins)
dest = random.choice([d for d in destinations if d != origin])
hour = random.randint(6, 22)
minute = random.choice([0, 15, 30, 45])
departure = current_date.replace(hour=hour, minute=minute, second=0, microsecond=0)
duration_hours = random.randint(2, 14)
arrival = departure + timedelta(hours=duration_hours)
flight = Flight(
flight_id=f"FL{random.randint(10000, 99999)}",
flight_number=f"{random.choice(airlines)}{random.randint(100, 999)}",
airline_code=random.choice(airlines),
origin=origin,
destination=dest,
departure_time=departure,
arrival_time=arrival,
base_price=random.randint(200, 1500),
total_seats=200,
available_seats=random.randint(50, 200)
)
new_flights.append(flight)
repo.insert_many(new_flights)
print(f"Seeded {len(new_flights)} flights.")
if __name__ == "__main__":
debug_flights()