0% found this document useful (0 votes)
6 views4 pages

MK

Uploaded by

suzumetojirama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

MK

Uploaded by

suzumetojirama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import mysql.

connector
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import turtle as tt
from sqlalchemy import create_engine

# Connect to the MySQL database using SQLAlchemy


def connect_to_database():
# Use SQLAlchemy to create a connection engine
engine =
create_engine("mysql+mysqlconnector://root:muskan2006@localhost/rail_1")
return engine

# Function to load data from MySQL into Pandas DataFrames


def load_data():
engine = connect_to_database()
journey_details = pd.read_sql("SELECT * FROM journey_details", engine)
passenger_details = pd.read_sql("SELECT * FROM passenger_details", engine)
booking_details = pd.read_sql("SELECT * FROM booking_details", engine)
payment_details = pd.read_sql("SELECT * FROM payment_details", engine)
return journey_details, passenger_details, booking_details, payment_details

# Function to display all available trains


def display_trains(journey_details):
print("Available Trains:")
print(journey_details)

# Function to book a ticket


def book_ticket(journey_details):
passenger_name = input("Enter your name: ")
train_no = int(input("Enter train number: "))
train = journey_details[journey_details['train_no'] == train_no]
if not train.empty:
print(f"Booking confirmed for {passenger_name} on {train.iloc[0]
['train_name']}")
else:
print("Train not found!")

# Function to view all passengers


def view_passengers(passenger_details):
print("Passenger Details:")
print(passenger_details)

# Function to cancel a booked ticket


def cancel_ticket():
connection = mysql.connector.connect(
host="localhost",
user="root",
password="muskan2006",
database="rail_1"
)
cursor = connection.cursor()
pnr_no = int(input("Enter the PNR number of the ticket to cancel: "))

# Check if the booking exists


cursor.execute(f"SELECT * FROM booking_details WHERE pnr_no = {pnr_no}")
booking = cursor.fetchone()
if booking:
cursor.execute(f"DELETE FROM booking_details WHERE pnr_no = {pnr_no}")
connection.commit()
print(f"Booking with PNR number {pnr_no} has been successfully canceled.")
else:
print("Booking not found!")

connection.close()

# Function to plot seat availability using a pie chart


def plot_seat_availability():
labels = ['AC3', 'Sleeper', 'AC2']
sizes = [10, 15, 5]
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)
plt.title("Seat Availability")
plt.show()

# Function to plot train names in bar chart


def plot_class_wise_sale():
conn = connect_to_database()
query = "select bd.class, sum(pd.total_fare) total_fare from booking_details bd
inner join payment_details pd on bd.pnr_no = pd.pnr_no group by bd.class;"
data = pd.read_sql(query, conn)
plt.bar(data["class"], data["total_fare"])
plt.title("Class Wise Sale Bar Chart")
plt.xlabel("Class")
plt.ylabel("Total Sale")
plt.show()

# Function to calculate the average ticket fare using NumPy


def calculate_average_price(payment_details):
average_fare = np.mean(payment_details['total_fare'])
print(f"Average Ticket Fare: {average_fare}")

# Function to plot ticket fares using a line graph


def plot_ticket_prices(payment_details):
ticket_indices = range(len(payment_details['ticket_fare']))
plt.scatter(ticket_indices, payment_details['ticket_fare'], color='green')
plt.title("Ticket Fare Prices")
plt.xlabel("Ticket Index")
plt.ylabel("Fare")
plt.show()

# Function to display booking information


def display_booking_info(booking_details):
print("Booking Information:")
print(booking_details)

# Function to draw a colorful railway track using Turtle


def draw_railway_track():
screen = tt.Screen()
screen.bgcolor("lightblue")
pen = tt.Turtle()
pen.speed(1)
pen.color("black")
for _ in range(10):
pen.forward(100)
pen.right(90)
pen.forward(10)
pen.right(90)
pen.forward(100)
pen.left(90)
pen.forward(10)
pen.left(90)
tt.done()

# Main menu loop


def main_menu():
print("1. Aakriti (CLASS XII-B) Role: Writing Responsibilities: aakriti handled
the writing part of the project...")
print("2. Muskan (CLASS XII-B) Role: Coding and Output Responsibilities: muskan
was responsible for writing the code and generating the output for the project...")
print("3. Abhinav (CLASS XII-B) Role: Editing Responsibilities: abhinav took on
the editing tasks...")
print("\n 🌟🌟🌟🌟🌟🌟 🙏🏼 WELCOME TO Railway Reservation System 🙏🏼 🌟🌟🌟🌟🌟🌟 \
n")

# Load data from MySQL


journey_details, passenger_details, booking_details, payment_details =
load_data()

while True:
print("\nMenu:")
print("1. Display All Trains")
print("2. Book a Ticket")
print("3. View All Passengers")
print("4. Plot Seat Availability")
print("5. Plot Class Wise Total Sale (Bar Chart)")
print("6. Calculate Average Ticket Fare")
print("7. Plot Ticket Prices")
print("8. Display Booking Information")
print("9. Cancel a Booked Ticket")
print("10. Draw Railway Track")
print("11. Exit")

choice = int(input("Enter your choice: "))


if choice == 1:
display_trains(journey_details)
elif choice == 2:
book_ticket(journey_details)
elif choice == 3:
view_passengers(passenger_details)
elif choice == 4:
plot_seat_availability()
elif choice == 5:
plot_class_wise_sale()
elif choice == 6:
calculate_average_price(payment_details)
elif choice == 7:
plot_ticket_prices(payment_details)
elif choice == 8:
display_booking_info(booking_details)
elif choice == 9:
cancel_ticket()
elif choice == 10:
draw_railway_track()
elif choice == 11:
print("Exiting... Thank you for using the Railway Reservation System!")
break
else:
print("Invalid choice! Please try again.")

# Run the main menu


main_menu()

You might also like