This is a Streamlit dashboard application that analyzes customer order data from a MySQL database.
NEW_ASSIGNMENT/
├── .conda/
├── .streamlit/
├── config/
│ └── config.py
├── data/
│ ├── processed/
│ ├── customers_cleaned.csv
│ └── orders_cleaned.csv
│ └── raw/
│ ├── customers.csv
│ └── order.csv
├── notebooks/
│ └── model.ipynb
├── src/
│ └── app/
│ ├── database_utils.py
│ ├── import_data.py
│ ├── ml_utils.py
│ └── test_db_connection.py
├── .env
├── .gitignore
├── README.md
└── requirements.txt
- Clone this repository:
git clone <repository-url>
cd <repository-name>
- Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
- Create a MySQL database and tables:
CREATE DATABASE your_database;
USE your_database;
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255)
);
CREATE TABLE orders (
id INT PRIMARY KEY,
display_order_id VARCHAR(10),
total_amount DECIMAL(10, 2),
created_at DATETIME,
customer_id INT
);
- Set up environment variables:
Create a
.env
file in the root directory with the following configuration:
DB_HOST=localhost
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
- Run config file:
python config/config.py
- Import initial data:
python src/app/import_data.py
8.Run database_utils file:
python src/utils/database_utils.py
- Check if the DB connection established or not:
python src/utils/test_db_cennection.py
- Run the Streamlit app:
streamlit run src/app/streamlit_app.py
- Date range filtering for orders
- Minimum spend and order count filters
- Top 10 customers visualization
- Revenue over time analysis
- Summary metrics
- Detailed order data table
The application includes a lenear regression model that predicts whether a customer is likely to be a repeat purchaser based on their order history and spending patterns.
src/app/streamlit_app.py
: Main Streamlit applicationsrc/app/database_utils.py
: Database connection and query utilitiessrc/app/ml_utils.py
: Machine learning model implementationsrc/app/import_data.py
: Data import utilitiessrc/app/test_db_connection.py
: Database connection testingconfig/config.py
: Configuration settingsnotebooks/model.ipynb
: Data analysis and LR model include notebookrequirements.txt
: Required Python packages.env
: Environment variables (not tracked in git)
- Use the
notebooks/model.ipynb
for data analysis and feature development - Run tests using:
python -m pytest tests/
- Update requirements using:
pip freeze > requirements.txt
- Make sure to properly secure your database credentials using the
.env
file - Never commit sensitive information to the repository
- For development, use the provided test database connection utility
- Check logs directory for any error messages during data import
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request