Skip to content

A Python command-line application for train ticket booking and management using a MySQL database. It allows users to book and cancel tickets, and features a password-protected admin panel to manage train data and visualize passenger statistics like gender, age, and seat availability with Matplotlib.

Notifications You must be signed in to change notification settings

VanshTandel90/Python-Train-Monitoring-and-Visualization-with-MySQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Train Monitoring and Visualization with MySQL

This project is a command-line-based train ticket booking and monitoring system built with Python and MySQL. It provides a user interface for booking and canceling tickets and a password-protected admin interface for managing the railway network and visualizing data with matplotlib.

Features

👤 User Features

  • Book Tickets: Users can book tickets for available trains. The system checks for seat availability (both AC and General classes) and updates the booking status in real-time.
  • Waiting List: If seats are full, the system automatically places users on a waiting list (up to a maximum of two).
  • Cancel Tickets: Users can cancel their booked tickets using their unique ticket ID. The system then automatically confirms a ticket for the next person on the waiting list, if applicable.

🔐 Admin Features

The admin interface is password-protected and offers several management and visualization tools:

  • Add New Trains: Admins can add new trains to the database, including details like train number, name, source, destination, and ticket fares.
  • View Train & Passenger Lists: View detailed, formatted lists of all trains in the network and all booked passengers.
  • Data Visualization:
    • Gender Distribution: Generate a pie chart showing the gender distribution of passengers for a specific train on a given date.
    • Seat Availability: View a bar chart displaying the availability of AC and General seats for a selected train across its scheduled dates.
    • Age Distribution: Create a histogram to visualize the age distribution of all passengers across the network.

Technologies Used

  • Backend: Python
  • Database: MySQL
  • Libraries:
    • mysql-connector-python for connecting to and interacting with the MySQL database.
    • matplotlib for generating data visualizations and plots.

Setup and Installation

Prerequisites

  • Python 3.x
  • MySQL Server

1. Database Setup

First, you need to set up the database and tables.

  1. Open your MySQL client (e.g., MySQL Workbench, or the command-line client).

  2. Run the SQL script provided in the sql.txt file to create the railway_network database, define the table structures (trainList, available_days, train_status, passenger), and insert initial sample data.

    -- Snippet from sql.txt
    create database railway_network;
    use railway_network;
    
    create table trainList (
        trainNumber varchar(10) primary key,
        trainName char(50),
        train_source char(30),
        train_destination char(30),
        AC_ticket_fair float4,
        GEN_ticket_fair float4
    );
    -- ... and so on for the other tables.

2. Python Environment

Next, set up your Python environment.

  1. Clone the repository or download the project files.
  2. Install the required Python packages. You can install them using pip:
    pip install mysql-connector-python matplotlib

3. Database Connection

Make sure to update the database connection details in Train Network.py to match your MySQL setup. The default password is set to 1234.

# In Train Network.py
connection=mysql.connector.connect(host='localhost',user='root',passwd='1234',
                                   database='railway_network')

How to Run the Application

Execute the main Python script from your terminal to start the application:

python "Train Network.py"

You will be greeted with a main menu where you can choose your desired action.

Main Menu

1: Book a ticket
2: Cancel Ticket
3: Admin Interface
4: Exit
Choice:

Admin Interface

To access the admin panel, select option 3 and enter the password (default is 1234).

--------------------
1: Add a new train
2: Train List
3: Passengers List
4: Gender Chart
5: Seat Availability
6: Age Distribution
7: Exit admin interface
--------------------
Enter your choice:

About

A Python command-line application for train ticket booking and management using a MySQL database. It allows users to book and cancel tickets, and features a password-protected admin panel to manage train data and visualize passenger statistics like gender, age, and seat availability with Matplotlib.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages