Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Os 400 workshop #424

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
876 changes: 876 additions & 0 deletions workshops/open-source-l400/05_dream_destination_with_crewai.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
344 changes: 344 additions & 0 deletions workshops/open-source-l400/prep_sql_data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,344 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting Faker\n",
" Downloading Faker-30.0.0-py3-none-any.whl.metadata (15 kB)\n",
"Requirement already satisfied: python-dateutil>=2.4 in /Users/jagdsoni/Desktop/TFC/code/bedrock-oss-workshop/.venv/lib/python3.11/site-packages (from Faker) (2.9.0.post0)\n",
"Requirement already satisfied: six>=1.5 in /Users/jagdsoni/Desktop/TFC/code/bedrock-oss-workshop/.venv/lib/python3.11/site-packages (from python-dateutil>=2.4->Faker) (1.16.0)\n",
"Downloading Faker-30.0.0-py3-none-any.whl (1.8 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m19.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hInstalling collected packages: Faker\n",
"Successfully installed Faker-30.0.0\n"
]
}
],
"source": [
"!pip install Faker"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sample data has been generated and inserted into the SQLite database.\n"
]
}
],
"source": [
"import random\n",
"from datetime import datetime, timedelta\n",
"from faker import Faker\n",
"import sqlite3\n",
"import math\n",
"\n",
"# Initialize Faker\n",
"fake = Faker()\n",
"\n",
"# Get today's date\n",
"today = datetime.now().date()\n",
"\n",
"# City data with coordinates (latitude, longitude)\n",
"city_data = {\n",
" \"New York\": (40.7128, -74.0060),\n",
" \"Los Angeles\": (34.0522, -118.2437),\n",
" \"Chicago\": (41.8781, -87.6298),\n",
" \"Las Vegas\": (36.1699, -115.1398),\n",
" \"San Francisco\": (37.7749, -122.4194),\n",
" \"Orlando\": (28.5383, -81.3792),\n",
" \"Miami\": (25.7617, -80.1918),\n",
" \"Washington\": (38.9072, -77.0369),\n",
" \"New Orleans\": (29.9511, -90.0715),\n",
" \"Boston\": (42.3601, -71.0589),\n",
" \"Seattle\": (47.6062, -122.3321),\n",
" \"San Diego\": (32.7157, -117.1611),\n",
" \"Honolulu\": (21.3069, -157.8583),\n",
" \"Nashville\": (36.1627, -86.7816),\n",
" \"Denver\": (39.7392, -104.9903),\n",
" \"Austin\": (30.2672, -97.7431),\n",
" \"Philadelphia\": (39.9526, -75.1652),\n",
" \"Atlanta\": (33.7490, -84.3880),\n",
" \"San Antonio\": (29.4241, -98.4936),\n",
" \"Portland\": (45.5155, -122.6789),\n",
" \"Paris\": (48.8566, 2.3522),\n",
" \"London\": (51.5074, -0.1278),\n",
" \"Rome\": (41.9028, 12.4964),\n",
" \"Barcelona\": (41.3851, 2.1734),\n",
" \"Amsterdam\": (52.3676, 4.9041),\n",
" \"Berlin\": (52.5200, 13.4050),\n",
" \"Vienna\": (48.2082, 16.3738),\n",
" \"Prague\": (50.0755, 14.4378),\n",
" \"Venice\": (45.4408, 12.3155),\n",
" \"Florence\": (43.7696, 11.2558),\n",
" \"Istanbul\": (41.0082, 28.9784),\n",
" \"Madrid\": (40.4168, -3.7038),\n",
" \"Lisbon\": (38.7223, -9.1393),\n",
" \"Dublin\": (53.3498, -6.2603),\n",
" \"Budapest\": (47.4979, 19.0402),\n",
" \"Athens\": (37.9838, 23.7275),\n",
" \"Edinburgh\": (55.9533, -3.1883),\n",
" \"Copenhagen\": (55.6761, 12.5683),\n",
" \"Stockholm\": (59.3293, 18.0686),\n",
" \"Brussels\": (50.8503, 4.3517),\n",
" \"Zurich\": (47.3769, 8.5417),\n",
" \"Milan\": (45.4642, 9.1900),\n",
" \"Munich\": (48.1351, 11.5820),\n",
" \"Seville\": (37.3891, -5.9845),\n",
"}\n",
"\n",
"\n",
"def calculate_distance(lat1, lon1, lat2, lon2):\n",
" R = 6371 # Earth's radius in kilometers\n",
"\n",
" lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])\n",
" dlat = lat2 - lat1\n",
" dlon = lon2 - lon1\n",
"\n",
" a = (\n",
" math.sin(dlat / 2) ** 2\n",
" + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2\n",
" )\n",
" c = 2 * math.asin(math.sqrt(a))\n",
" distance = R * c\n",
"\n",
" return distance\n",
"\n",
"\n",
"def calculate_flight_duration(distance):\n",
" # Assume average speed of 800 km/h and add 30 minutes for takeoff and landing\n",
" duration_hours = distance / 800\n",
" duration_minutes = int(duration_hours * 60) + 30\n",
" return timedelta(minutes=duration_minutes)\n",
"\n",
"\n",
"def calculate_flight_price(distance):\n",
" # Base price of $50 plus $0.1 per km\n",
" base_price = 50\n",
" price_per_km = 0.1\n",
" return round(base_price + (distance * price_per_km), 2)\n",
"\n",
"\n",
"def generate_user(user_id):\n",
" name = fake.name()\n",
" age = random.randint(18, 80)\n",
" home_location = random.choice(list(city_data.keys()))\n",
"\n",
" return (user_id, name, age, home_location)\n",
"\n",
"\n",
"def generate_flight_booking(booking_id, user_id, user_name):\n",
" origin = random.choice(list(city_data.keys()))\n",
" destination = random.choice([city for city in city_data.keys() if city != origin])\n",
"\n",
" origin_coords = city_data[origin]\n",
" dest_coords = city_data[destination]\n",
"\n",
" distance = calculate_distance(\n",
" origin_coords[0], origin_coords[1], dest_coords[0], dest_coords[1]\n",
" )\n",
" flight_duration = calculate_flight_duration(distance)\n",
" price = calculate_flight_price(distance)\n",
"\n",
" # Generate a random booking date within the next 15 days\n",
" booking_date = today + timedelta(days=random.randint(0, 14))\n",
"\n",
" # Generate departure date between 1 and 30 days after the booking date\n",
" departure_date = booking_date + timedelta(days=random.randint(1, 30))\n",
"\n",
" # Generate departure time\n",
" departure_time = f\"{random.randint(0, 23):02d}:{random.randint(0, 59):02d}\"\n",
"\n",
" # Calculate arrival date and time\n",
" departure_datetime = datetime.combine(\n",
" departure_date, datetime.strptime(departure_time, \"%H:%M\").time()\n",
" )\n",
" arrival_datetime = departure_datetime + flight_duration\n",
"\n",
" return (\n",
" booking_id,\n",
" user_id,\n",
" user_name,\n",
" origin,\n",
" destination,\n",
" price,\n",
" int(flight_duration.total_seconds() // 60), # Convert to minutes\n",
" departure_date.strftime(\"%Y-%m-%d\"),\n",
" departure_time,\n",
" arrival_datetime.strftime(\"%Y-%m-%d\"),\n",
" arrival_datetime.strftime(\"%H:%M\"),\n",
" round(distance, 2),\n",
" booking_date.strftime(\"%Y-%m-%d\"),\n",
" )\n",
"\n",
"\n",
"def generate_hotel_booking(booking_id, user_id, user_name):\n",
" city = random.choice(list(city_data.keys()))\n",
" hotel_name = fake.company() + \" Hotel\"\n",
" check_in_date = fake.date_between(start_date=\"+1d\", end_date=\"+60d\")\n",
" nights = random.randint(1, 14)\n",
" check_out_date = check_in_date + timedelta(days=nights)\n",
" price_per_night = round(random.uniform(50, 500), 2)\n",
" total_price = round(price_per_night * nights, 2)\n",
" num_guests = random.randint(1, 4)\n",
" room_type = random.choice([\"Single\", \"Double\", \"Suite\", \"Deluxe\"])\n",
"\n",
" return (\n",
" booking_id,\n",
" user_id,\n",
" user_name,\n",
" city,\n",
" hotel_name,\n",
" check_in_date.strftime(\"%Y-%m-%d\"),\n",
" check_out_date.strftime(\"%Y-%m-%d\"),\n",
" nights,\n",
" price_per_night,\n",
" total_price,\n",
" num_guests,\n",
" room_type,\n",
" )\n",
"\n",
"\n",
"def create_database():\n",
" conn = sqlite3.connect(\"travel_bookings.db\")\n",
" cursor = conn.cursor()\n",
"\n",
" cursor.execute(\n",
" \"\"\"\n",
" CREATE TABLE IF NOT EXISTS users (\n",
" user_id INTEGER PRIMARY KEY,\n",
" name TEXT,\n",
" age INTEGER,\n",
" home_location TEXT\n",
" )\n",
" \"\"\"\n",
" )\n",
"\n",
" cursor.execute(\n",
" \"\"\"\n",
" CREATE TABLE IF NOT EXISTS flight_bookings (\n",
" booking_id INTEGER PRIMARY KEY,\n",
" user_id INTEGER,\n",
" user_name TEXT,\n",
" origin TEXT,\n",
" destination TEXT,\n",
" price REAL,\n",
" flight_duration INTEGER,\n",
" departure_date TEXT,\n",
" departure_time TEXT,\n",
" arrival_date TEXT,\n",
" arrival_time TEXT,\n",
" distance REAL,\n",
" booking_date TEXT,\n",
" FOREIGN KEY (user_id) REFERENCES users (user_id)\n",
" )\n",
" \"\"\"\n",
" )\n",
"\n",
" cursor.execute(\n",
" \"\"\"\n",
" CREATE TABLE IF NOT EXISTS hotel_bookings (\n",
" booking_id INTEGER PRIMARY KEY,\n",
" user_id INTEGER,\n",
" user_name TEXT,\n",
" city TEXT,\n",
" hotel_name TEXT,\n",
" check_in_date TEXT,\n",
" check_out_date TEXT,\n",
" nights INTEGER,\n",
" price_per_night REAL,\n",
" total_price REAL,\n",
" num_guests INTEGER,\n",
" room_type TEXT,\n",
" FOREIGN KEY (user_id) REFERENCES users (user_id)\n",
" )\n",
" \"\"\"\n",
" )\n",
"\n",
" conn.commit()\n",
" return conn, cursor\n",
"\n",
"\n",
"def insert_sample_data(\n",
" conn, cursor, num_users, num_flight_bookings, num_hotel_bookings\n",
"):\n",
" # Generate and insert user data\n",
" users = [generate_user(i + 1) for i in range(num_users)]\n",
" cursor.executemany(\n",
" \"\"\"\n",
" INSERT INTO users (user_id, name, age, home_location)\n",
" VALUES (?, ?, ?, ?)\n",
" \"\"\",\n",
" users,\n",
" )\n",
"\n",
" # Generate and insert flight bookings\n",
" for i in range(num_flight_bookings):\n",
" user = random.choice(users)\n",
" flight_booking = generate_flight_booking(i + 1, user[0], user[1])\n",
" cursor.execute(\n",
" \"\"\"\n",
" INSERT INTO flight_bookings (booking_id, user_id, user_name, origin, destination, price, flight_duration, departure_date, departure_time, arrival_date, arrival_time, distance, booking_date)\n",
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n",
" \"\"\",\n",
" flight_booking,\n",
" )\n",
"\n",
" # Generate and insert hotel bookings\n",
" for i in range(num_hotel_bookings):\n",
" user = random.choice(users)\n",
" hotel_booking = generate_hotel_booking(i + 1, user[0], user[1])\n",
" cursor.execute(\n",
" \"\"\"\n",
" INSERT INTO hotel_bookings (booking_id, user_id, user_name, city, hotel_name, check_in_date, check_out_date, nights, price_per_night, total_price, num_guests, room_type)\n",
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n",
" \"\"\",\n",
" hotel_booking,\n",
" )\n",
"\n",
" conn.commit()\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" conn, cursor = create_database()\n",
" insert_sample_data(\n",
" conn, cursor, num_users=500, num_flight_bookings=1000, num_hotel_bookings=1000\n",
" )\n",
" conn.close()\n",
" print(\"Sample data has been generated and inserted into the SQLite database.\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}