Spaces:
Sleeping
Sleeping
abraham9486937737
commited on
Commit
·
04b129a
1
Parent(s):
4778771
Deploy MySpace Ooty Analytics to Hugging Face - with KPI styling updates
Browse files- .streamlit/config.toml +18 -0
- README.md +123 -1
- app.py +19 -0
- config/constants.py +32 -0
- config/settings.py +36 -0
- data/processed/.gitkeep +0 -0
- data/processed/data_cleaned_with_kpi.csv +0 -0
- data/processed/kpi_summary.csv +20 -0
- packages.txt +6 -0
- requirements.txt +21 -0
- src/__init__.py +5 -0
- src/analysis.py +156 -0
- src/data_loading.py +63 -0
- src/data_processing.py +107 -0
- src/generate_powerpoint_report.py +319 -0
- src/utils.py +75 -0
- streamlit_app/components/charts.py +88 -0
- streamlit_app/components/utils.py +68 -0
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
primaryColor = "#667eea"
|
| 3 |
+
backgroundColor = "#ffffff"
|
| 4 |
+
secondaryBackgroundColor = "#f0f2f6"
|
| 5 |
+
textColor = "#262730"
|
| 6 |
+
font = "sans serif"
|
| 7 |
+
|
| 8 |
+
[client]
|
| 9 |
+
showErrorDetails = true
|
| 10 |
+
toolbarMode = "minimal"
|
| 11 |
+
|
| 12 |
+
[logger]
|
| 13 |
+
level = "info"
|
| 14 |
+
|
| 15 |
+
[server]
|
| 16 |
+
maxUploadSize = 200
|
| 17 |
+
headless = true
|
| 18 |
+
runOnSave = true
|
README.md
CHANGED
|
@@ -1 +1,123 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: MySpace Ooty Analytics Dashboard
|
| 3 |
+
emoji: 🏨
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.28.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# 🏨 MySpace Ooty Holiday Inn - Analytics Dashboard
|
| 14 |
+
|
| 15 |
+
An interactive data analytics dashboard for MySpace Holiday Inn in Ooty, built with Streamlit and Plotly. This dashboard provides comprehensive insights into booking patterns, revenue analysis, and operational metrics.
|
| 16 |
+
|
| 17 |
+
## 🌟 Features
|
| 18 |
+
|
| 19 |
+
### 📊 Interactive Visualizations
|
| 20 |
+
- **Real-time KPI Metrics**: Track key performance indicators at a glance
|
| 21 |
+
- **Dynamic Filtering**: Filter data by year, month, and booking status
|
| 22 |
+
- **Responsive Charts**: Beautiful, interactive Plotly charts that work on all devices
|
| 23 |
+
|
| 24 |
+
### 📈 Analytics Capabilities
|
| 25 |
+
- **Overview Dashboard**: Quick summary of business metrics and trends
|
| 26 |
+
- **KPI Analysis**: Detailed performance indicators and metrics
|
| 27 |
+
- **Data Exploration**: Deep dive into your booking data
|
| 28 |
+
- **Trend Analysis**: Identify patterns and seasonal variations
|
| 29 |
+
- **Custom Reports**: Generate and export personalized reports
|
| 30 |
+
|
| 31 |
+
### 📱 Device Compatibility
|
| 32 |
+
- Fully responsive design
|
| 33 |
+
- Works on desktop, tablet, and mobile devices
|
| 34 |
+
- Compatible with all modern browsers (Chrome, Firefox, Safari, Edge)
|
| 35 |
+
|
| 36 |
+
## 🚀 How to Use
|
| 37 |
+
|
| 38 |
+
1. **Navigation**: Use the sidebar to navigate between different sections
|
| 39 |
+
2. **Filters**: Apply filters to customize your view and analysis
|
| 40 |
+
3. **Visualizations**: Interact with charts by hovering, clicking, and zooming
|
| 41 |
+
4. **Export**: Download reports in CSV, Excel, or PowerPoint format
|
| 42 |
+
|
| 43 |
+
## 📊 Dashboard Sections
|
| 44 |
+
|
| 45 |
+
### 1. Overview
|
| 46 |
+
Get a quick summary of key metrics including:
|
| 47 |
+
- Total bookings and revenue
|
| 48 |
+
- Average length of stay
|
| 49 |
+
- Revenue per booking
|
| 50 |
+
- Monthly booking distribution
|
| 51 |
+
- Day-of-week patterns
|
| 52 |
+
- Holiday vs regular season analysis
|
| 53 |
+
|
| 54 |
+
### 2. KPIs & Metrics
|
| 55 |
+
View detailed performance indicators:
|
| 56 |
+
- Comprehensive KPI summary table
|
| 57 |
+
- Performance analysis
|
| 58 |
+
- Weekend and holiday booking percentages
|
| 59 |
+
|
| 60 |
+
### 3. Data Exploration
|
| 61 |
+
Explore your data in depth:
|
| 62 |
+
- Dataset overview and statistics
|
| 63 |
+
- Sample data preview
|
| 64 |
+
- Column-wise statistical analysis
|
| 65 |
+
- Missing value detection
|
| 66 |
+
|
| 67 |
+
### 4. Trends & Analysis
|
| 68 |
+
Identify patterns and trends:
|
| 69 |
+
- Monthly booking trends
|
| 70 |
+
- Revenue trend analysis
|
| 71 |
+
- Seasonal variations
|
| 72 |
+
- Time-series visualizations
|
| 73 |
+
|
| 74 |
+
### 5. Custom Reports
|
| 75 |
+
Generate personalized reports:
|
| 76 |
+
- Multiple report types
|
| 77 |
+
- Export in various formats (CSV, Excel, PowerPoint)
|
| 78 |
+
- Configurable date ranges and filters
|
| 79 |
+
|
| 80 |
+
## 💡 Tips for Best Experience
|
| 81 |
+
|
| 82 |
+
- **Use Filters**: Customize your analysis by selecting specific years, months, or booking statuses
|
| 83 |
+
- **Hover for Details**: Hover over charts to see detailed information
|
| 84 |
+
- **Mobile View**: Swipe left/right on mobile devices to navigate charts
|
| 85 |
+
- **Export Data**: Download filtered data for offline analysis
|
| 86 |
+
|
| 87 |
+
## 🏨 About MySpace Holiday Inn
|
| 88 |
+
|
| 89 |
+
Located in the beautiful hill station of Ooty, MySpace Holiday Inn offers comfortable accommodation and excellent hospitality.
|
| 90 |
+
|
| 91 |
+
**Contact Information:**
|
| 92 |
+
- 📍 Head Office: Kotagiri – 643217
|
| 93 |
+
- 📞 Phone: +91 82206 62206 | +91-6369052954 | +91-6369973006
|
| 94 |
+
- 📧 Email: myspaceholidayinn@gmail.com
|
| 95 |
+
- 📱 WhatsApp: +916381911228
|
| 96 |
+
|
| 97 |
+
**Timings:**
|
| 98 |
+
- Check-In: 12:00 PM
|
| 99 |
+
- Check-Out: 10:00 AM
|
| 100 |
+
|
| 101 |
+
## 🛠️ Technology Stack
|
| 102 |
+
|
| 103 |
+
- **Frontend**: Streamlit
|
| 104 |
+
- **Visualization**: Plotly, Matplotlib, Seaborn
|
| 105 |
+
- **Data Processing**: Pandas, NumPy
|
| 106 |
+
- **Analysis**: Scikit-learn, SciPy
|
| 107 |
+
- **Export**: python-pptx, openpyxl
|
| 108 |
+
|
| 109 |
+
## 📝 License
|
| 110 |
+
|
| 111 |
+
MIT License - Feel free to use and modify for your needs.
|
| 112 |
+
|
| 113 |
+
## 🤝 Support
|
| 114 |
+
|
| 115 |
+
For questions or support, please contact:
|
| 116 |
+
- Email: myspaceholidayinn@gmail.com
|
| 117 |
+
- Phone: +91 82206 62206
|
| 118 |
+
|
| 119 |
+
---
|
| 120 |
+
|
| 121 |
+
**Made with ❤️ for MySpace Holiday Inn, Ooty**
|
| 122 |
+
|
| 123 |
+
*Data Analytics Dashboard | Powered by Streamlit and Plotly*
|
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MySpace Ooty Data Analytics Dashboard
|
| 3 |
+
Deployment Entry Point for Hugging Face Spaces
|
| 4 |
+
|
| 5 |
+
This file serves as the main entry point for the Streamlit app.
|
| 6 |
+
Hugging Face Spaces will automatically run this file.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
# Add project root to path for imports
|
| 13 |
+
project_root = Path(__file__).parent
|
| 14 |
+
sys.path.insert(0, str(project_root))
|
| 15 |
+
|
| 16 |
+
# Import and execute the main dashboard
|
| 17 |
+
# This imports all the code from streamlit_app/app.py
|
| 18 |
+
exec(open(project_root / "streamlit_app" / "app.py", encoding="utf-8").read())
|
| 19 |
+
|
config/constants.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Project constants
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
# Application info
|
| 6 |
+
APP_NAME = "MySpace Ooty Data Analytics"
|
| 7 |
+
APP_VERSION = "1.0.0"
|
| 8 |
+
APP_AUTHOR = "Data Engineering Team"
|
| 9 |
+
|
| 10 |
+
# Color schemes
|
| 11 |
+
COLOR_PALETTE = {
|
| 12 |
+
"primary": "#1f77b4",
|
| 13 |
+
"secondary": "#ff7f0e",
|
| 14 |
+
"success": "#2ca02c",
|
| 15 |
+
"danger": "#d62728",
|
| 16 |
+
"warning": "#ff9896",
|
| 17 |
+
"info": "#17becf",
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# Months
|
| 21 |
+
MONTHS = {
|
| 22 |
+
"January": 1, "February": 2, "March": 3, "April": 4,
|
| 23 |
+
"May": 5, "June": 6, "July": 7, "August": 8,
|
| 24 |
+
"September": 9, "October": 10, "November": 11, "December": 12
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
# Statistical thresholds
|
| 28 |
+
STRONG_CORRELATION = 0.7
|
| 29 |
+
MODERATE_CORRELATION = 0.4
|
| 30 |
+
WEAK_CORRELATION = 0.2
|
| 31 |
+
P_VALUE_SIGNIFICANT = 0.05
|
| 32 |
+
P_VALUE_HIGHLY_SIGNIFICANT = 0.01
|
config/settings.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration settings for the project
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
# Project paths
|
| 8 |
+
PROJECT_ROOT = Path(__file__).parent.parent
|
| 9 |
+
DATA_DIR = PROJECT_ROOT / "data"
|
| 10 |
+
RAW_DATA_DIR = DATA_DIR / "raw"
|
| 11 |
+
PROCESSED_DATA_DIR = DATA_DIR / "processed"
|
| 12 |
+
EXTERNAL_DATA_DIR = DATA_DIR / "external"
|
| 13 |
+
OUTPUT_DIR = DATA_DIR / "outputs"
|
| 14 |
+
REPORTS_DIR = PROJECT_ROOT / "reports"
|
| 15 |
+
LOGS_DIR = PROJECT_ROOT / "logs"
|
| 16 |
+
|
| 17 |
+
# Data processing settings
|
| 18 |
+
MISSING_VALUE_STRATEGY = "drop" # Options: 'drop', 'mean', 'median', 'forward_fill'
|
| 19 |
+
OUTLIER_REMOVAL_METHOD = "iqr" # Options: 'iqr', 'zscore'
|
| 20 |
+
OUTLIER_THRESHOLD = 1.5
|
| 21 |
+
|
| 22 |
+
# Analysis settings
|
| 23 |
+
CORRELATION_METHOD = "pearson" # Options: 'pearson', 'spearman', 'kendall'
|
| 24 |
+
SIGNIFICANCE_LEVEL = 0.05
|
| 25 |
+
TEST_TYPE = "ttest" # Options: 'ttest', 'mannwhitneyu', 'chi2'
|
| 26 |
+
|
| 27 |
+
# Visualization settings
|
| 28 |
+
DEFAULT_COLORSCALE = "Viridis"
|
| 29 |
+
PLOT_HEIGHT = 500
|
| 30 |
+
PLOT_WIDTH = 900
|
| 31 |
+
|
| 32 |
+
# Dashboard settings
|
| 33 |
+
PAGE_ICON = "📊"
|
| 34 |
+
PAGE_TITLE = "MySpace Ooty Data Analytics"
|
| 35 |
+
LAYOUT = "wide"
|
| 36 |
+
INITIAL_SIDEBAR_STATE = "expanded"
|
data/processed/.gitkeep
ADDED
|
File without changes
|
data/processed/data_cleaned_with_kpi.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/processed/kpi_summary.csv
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metric,Value
|
| 2 |
+
Total_Bookings,752.0
|
| 3 |
+
Total_Revenue,31224854.0
|
| 4 |
+
Avg_Revenue_Per_Booking,41522.41223404255
|
| 5 |
+
Total_Rooms_Booked,1030.0
|
| 6 |
+
Total_Room_Nights,78749.0
|
| 7 |
+
Occupancy_Rate,20.94666843995212
|
| 8 |
+
Avg_Length_of_Stay,104.71941489361703
|
| 9 |
+
RevPAR,30315.39223300971
|
| 10 |
+
Total_Adults,3164.0
|
| 11 |
+
Total_Children,339.0
|
| 12 |
+
Avg_Guests_Per_Booking,4.658244680851064
|
| 13 |
+
Holiday_Season_Bookings,3.0
|
| 14 |
+
Regular_Season_Bookings,749.0
|
| 15 |
+
Holiday_Season_Revenue,179977.0
|
| 16 |
+
Regular_Season_Revenue,31044877.0
|
| 17 |
+
Checked Out_Count,625.0
|
| 18 |
+
Cancelled_Count,111.0
|
| 19 |
+
Confirmed_Count,14.0
|
| 20 |
+
Checked In _Count,2.0
|
packages.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# System-level dependencies for Hugging Face Spaces
|
| 2 |
+
# These packages will be installed using apt-get
|
| 3 |
+
|
| 4 |
+
# For handling images and plots
|
| 5 |
+
libgl1-mesa-glx
|
| 6 |
+
libglib2.0-0
|
requirements.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core dependencies for Streamlit Dashboard
|
| 2 |
+
streamlit>=1.28.0
|
| 3 |
+
pandas>=2.0.0
|
| 4 |
+
numpy>=1.24.0
|
| 5 |
+
plotly>=5.18.0
|
| 6 |
+
|
| 7 |
+
# Visualization
|
| 8 |
+
seaborn>=0.12.0
|
| 9 |
+
matplotlib>=3.7.0
|
| 10 |
+
|
| 11 |
+
# Data processing and analysis
|
| 12 |
+
scikit-learn>=1.3.0
|
| 13 |
+
scipy>=1.11.0
|
| 14 |
+
|
| 15 |
+
# File handling
|
| 16 |
+
openpyxl>=3.1.0
|
| 17 |
+
python-pptx>=0.6.21
|
| 18 |
+
Pillow>=10.0.0
|
| 19 |
+
|
| 20 |
+
# Configuration
|
| 21 |
+
python-dotenv>=1.0.0
|
src/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MySpace Ooty Data Analytics - Data Processing and Analysis Module
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
__version__ = "1.0.0"
|
src/analysis.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Statistical analysis and insights generation
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import numpy as np
|
| 7 |
+
from scipy import stats
|
| 8 |
+
from typing import Dict, Tuple, Union
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def calculate_descriptive_stats(df: pd.DataFrame, column: str) -> Dict:
|
| 12 |
+
"""
|
| 13 |
+
Calculate descriptive statistics for a column
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
df: Input DataFrame
|
| 17 |
+
column: Column name
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
Dictionary with statistics
|
| 21 |
+
"""
|
| 22 |
+
stats_dict = {
|
| 23 |
+
"count": df[column].count(),
|
| 24 |
+
"mean": df[column].mean(),
|
| 25 |
+
"median": df[column].median(),
|
| 26 |
+
"std": df[column].std(),
|
| 27 |
+
"min": df[column].min(),
|
| 28 |
+
"25%": df[column].quantile(0.25),
|
| 29 |
+
"75%": df[column].quantile(0.75),
|
| 30 |
+
"max": df[column].max(),
|
| 31 |
+
"skewness": df[column].skew(),
|
| 32 |
+
"kurtosis": df[column].kurtosis(),
|
| 33 |
+
}
|
| 34 |
+
return stats_dict
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def correlation_analysis(df: pd.DataFrame, method: str = "pearson") -> pd.DataFrame:
|
| 38 |
+
"""
|
| 39 |
+
Perform correlation analysis
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
df: Input DataFrame with numeric columns
|
| 43 |
+
method: 'pearson', 'spearman', or 'kendall'
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
Correlation matrix
|
| 47 |
+
"""
|
| 48 |
+
numeric_df = df.select_dtypes(include=[np.number])
|
| 49 |
+
corr_matrix = numeric_df.corr(method=method)
|
| 50 |
+
return corr_matrix
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def hypothesis_testing(group1: pd.Series, group2: pd.Series,
|
| 54 |
+
test_type: str = "ttest") -> Dict:
|
| 55 |
+
"""
|
| 56 |
+
Perform hypothesis testing between two groups
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
group1: First group data
|
| 60 |
+
group2: Second group data
|
| 61 |
+
test_type: 't-test', 'mannwhitneyu', or 'chi2'
|
| 62 |
+
|
| 63 |
+
Returns:
|
| 64 |
+
Dictionary with test results
|
| 65 |
+
"""
|
| 66 |
+
results = {}
|
| 67 |
+
|
| 68 |
+
if test_type == "ttest":
|
| 69 |
+
statistic, p_value = stats.ttest_ind(group1.dropna(), group2.dropna())
|
| 70 |
+
results = {
|
| 71 |
+
"test": "Independent t-test",
|
| 72 |
+
"statistic": statistic,
|
| 73 |
+
"p_value": p_value,
|
| 74 |
+
"significant": p_value < 0.05
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
elif test_type == "mannwhitneyu":
|
| 78 |
+
statistic, p_value = stats.mannwhitneyu(group1.dropna(), group2.dropna())
|
| 79 |
+
results = {
|
| 80 |
+
"test": "Mann-Whitney U Test",
|
| 81 |
+
"statistic": statistic,
|
| 82 |
+
"p_value": p_value,
|
| 83 |
+
"significant": p_value < 0.05
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
return results
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def anova_test(groups: list) -> Dict:
|
| 90 |
+
"""
|
| 91 |
+
Perform ANOVA test
|
| 92 |
+
|
| 93 |
+
Args:
|
| 94 |
+
groups: List of group data Series
|
| 95 |
+
|
| 96 |
+
Returns:
|
| 97 |
+
Dictionary with ANOVA results
|
| 98 |
+
"""
|
| 99 |
+
clean_groups = [g.dropna() for g in groups]
|
| 100 |
+
f_stat, p_value = stats.f_oneway(*clean_groups)
|
| 101 |
+
|
| 102 |
+
return {
|
| 103 |
+
"test": "ANOVA",
|
| 104 |
+
"f_statistic": f_stat,
|
| 105 |
+
"p_value": p_value,
|
| 106 |
+
"significant": p_value < 0.05
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def chi_square_test(contingency_table: pd.DataFrame) -> Dict:
|
| 111 |
+
"""
|
| 112 |
+
Perform Chi-square test for independence
|
| 113 |
+
|
| 114 |
+
Args:
|
| 115 |
+
contingency_table: Contingency table (DataFrame)
|
| 116 |
+
|
| 117 |
+
Returns:
|
| 118 |
+
Dictionary with test results
|
| 119 |
+
"""
|
| 120 |
+
chi2, p_value, dof, expected = stats.chi2_contingency(contingency_table)
|
| 121 |
+
|
| 122 |
+
return {
|
| 123 |
+
"test": "Chi-square",
|
| 124 |
+
"statistic": chi2,
|
| 125 |
+
"p_value": p_value,
|
| 126 |
+
"degrees_of_freedom": dof,
|
| 127 |
+
"significant": p_value < 0.05
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def trend_analysis(df: pd.DataFrame, time_col: str, value_col: str) -> Dict:
|
| 132 |
+
"""
|
| 133 |
+
Perform simple trend analysis
|
| 134 |
+
|
| 135 |
+
Args:
|
| 136 |
+
df: Input DataFrame
|
| 137 |
+
time_col: Column name for time/date
|
| 138 |
+
value_col: Column name for values
|
| 139 |
+
|
| 140 |
+
Returns:
|
| 141 |
+
Dictionary with trend metrics
|
| 142 |
+
"""
|
| 143 |
+
df_sorted = df.sort_values(time_col).copy()
|
| 144 |
+
x = np.arange(len(df_sorted))
|
| 145 |
+
y = df_sorted[value_col].values
|
| 146 |
+
|
| 147 |
+
slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
|
| 148 |
+
|
| 149 |
+
return {
|
| 150 |
+
"slope": slope,
|
| 151 |
+
"intercept": intercept,
|
| 152 |
+
"r_squared": r_value**2,
|
| 153 |
+
"p_value": p_value,
|
| 154 |
+
"trend": "upward" if slope > 0 else "downward",
|
| 155 |
+
"significant": p_value < 0.05
|
| 156 |
+
}
|
src/data_loading.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data loading module for reading Excel and CSV files
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Union, Optional
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def load_excel_data(file_path: Union[str, Path], sheet_name: Optional[str] = None) -> pd.DataFrame:
|
| 12 |
+
"""
|
| 13 |
+
Load Excel file data
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
file_path: Path to Excel file
|
| 17 |
+
sheet_name: Name of sheet to load (if None, loads first sheet)
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
DataFrame containing the data
|
| 21 |
+
"""
|
| 22 |
+
try:
|
| 23 |
+
df = pd.read_excel(file_path, sheet_name=sheet_name)
|
| 24 |
+
print(f"✓ Successfully loaded: {file_path}")
|
| 25 |
+
return df
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"✗ Error loading file: {e}")
|
| 28 |
+
raise
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def load_csv_data(file_path: Union[str, Path]) -> pd.DataFrame:
|
| 32 |
+
"""
|
| 33 |
+
Load CSV file data
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
file_path: Path to CSV file
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
DataFrame containing the data
|
| 40 |
+
"""
|
| 41 |
+
try:
|
| 42 |
+
df = pd.read_csv(file_path)
|
| 43 |
+
print(f"✓ Successfully loaded: {file_path}")
|
| 44 |
+
return df
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"✗ Error loading file: {e}")
|
| 47 |
+
raise
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def get_data_files(directory: Union[str, Path], file_type: str = "xlsx") -> list:
|
| 51 |
+
"""
|
| 52 |
+
Get all data files of specific type from directory
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
directory: Path to directory
|
| 56 |
+
file_type: File extension to search for
|
| 57 |
+
|
| 58 |
+
Returns:
|
| 59 |
+
List of file paths
|
| 60 |
+
"""
|
| 61 |
+
path = Path(directory)
|
| 62 |
+
files = list(path.glob(f"*.{file_type}"))
|
| 63 |
+
return sorted(files)
|
src/data_processing.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data processing and cleaning module
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import numpy as np
|
| 7 |
+
from typing import Union, List, Tuple
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def clean_data(df: pd.DataFrame, remove_duplicates: bool = True,
|
| 11 |
+
handle_missing: str = "drop") -> pd.DataFrame:
|
| 12 |
+
"""
|
| 13 |
+
Clean dataset by removing duplicates and handling missing values
|
| 14 |
+
|
| 15 |
+
Args:
|
| 16 |
+
df: Input DataFrame
|
| 17 |
+
remove_duplicates: Whether to remove duplicate rows
|
| 18 |
+
handle_missing: Strategy for missing values ('drop', 'mean', 'median', 'forward_fill')
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
Cleaned DataFrame
|
| 22 |
+
"""
|
| 23 |
+
df_clean = df.copy()
|
| 24 |
+
|
| 25 |
+
if remove_duplicates:
|
| 26 |
+
initial_shape = df_clean.shape[0]
|
| 27 |
+
df_clean = df_clean.drop_duplicates()
|
| 28 |
+
print(f"Removed {initial_shape - df_clean.shape[0]} duplicate rows")
|
| 29 |
+
|
| 30 |
+
if handle_missing == "drop":
|
| 31 |
+
df_clean = df_clean.dropna()
|
| 32 |
+
elif handle_missing == "mean":
|
| 33 |
+
numeric_cols = df_clean.select_dtypes(include=[np.number]).columns
|
| 34 |
+
df_clean[numeric_cols] = df_clean[numeric_cols].fillna(df_clean[numeric_cols].mean())
|
| 35 |
+
elif handle_missing == "median":
|
| 36 |
+
numeric_cols = df_clean.select_dtypes(include=[np.number]).columns
|
| 37 |
+
df_clean[numeric_cols] = df_clean[numeric_cols].fillna(df_clean[numeric_cols].median())
|
| 38 |
+
elif handle_missing == "forward_fill":
|
| 39 |
+
df_clean = df_clean.fillna(method='ffill')
|
| 40 |
+
|
| 41 |
+
return df_clean
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def remove_outliers(df: pd.DataFrame, columns: List[str],
|
| 45 |
+
method: str = "iqr", threshold: float = 1.5) -> pd.DataFrame:
|
| 46 |
+
"""
|
| 47 |
+
Remove outliers using IQR or Z-score method
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
df: Input DataFrame
|
| 51 |
+
columns: List of column names to check for outliers
|
| 52 |
+
method: 'iqr' or 'zscore'
|
| 53 |
+
threshold: Threshold for outlier detection
|
| 54 |
+
|
| 55 |
+
Returns:
|
| 56 |
+
DataFrame without outliers
|
| 57 |
+
"""
|
| 58 |
+
df_clean = df.copy()
|
| 59 |
+
|
| 60 |
+
if method == "iqr":
|
| 61 |
+
for col in columns:
|
| 62 |
+
Q1 = df_clean[col].quantile(0.25)
|
| 63 |
+
Q3 = df_clean[col].quantile(0.75)
|
| 64 |
+
IQR = Q3 - Q1
|
| 65 |
+
lower = Q1 - threshold * IQR
|
| 66 |
+
upper = Q3 + threshold * IQR
|
| 67 |
+
df_clean = df_clean[(df_clean[col] >= lower) & (df_clean[col] <= upper)]
|
| 68 |
+
|
| 69 |
+
elif method == "zscore":
|
| 70 |
+
from scipy import stats
|
| 71 |
+
z_scores = np.abs(stats.zscore(df_clean[columns].select_dtypes(include=[np.number])))
|
| 72 |
+
df_clean = df_clean[(z_scores < threshold).all(axis=1)]
|
| 73 |
+
|
| 74 |
+
return df_clean
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def normalize_columns(df: pd.DataFrame, columns: List[str],
|
| 78 |
+
method: str = "minmax") -> Tuple[pd.DataFrame, dict]:
|
| 79 |
+
"""
|
| 80 |
+
Normalize specified columns
|
| 81 |
+
|
| 82 |
+
Args:
|
| 83 |
+
df: Input DataFrame
|
| 84 |
+
columns: List of column names to normalize
|
| 85 |
+
method: 'minmax' or 'standard'
|
| 86 |
+
|
| 87 |
+
Returns:
|
| 88 |
+
Normalized DataFrame and scaling parameters
|
| 89 |
+
"""
|
| 90 |
+
df_norm = df.copy()
|
| 91 |
+
scaling_params = {}
|
| 92 |
+
|
| 93 |
+
if method == "minmax":
|
| 94 |
+
for col in columns:
|
| 95 |
+
min_val = df_norm[col].min()
|
| 96 |
+
max_val = df_norm[col].max()
|
| 97 |
+
df_norm[col] = (df_norm[col] - min_val) / (max_val - min_val)
|
| 98 |
+
scaling_params[col] = {"min": min_val, "max": max_val}
|
| 99 |
+
|
| 100 |
+
elif method == "standard":
|
| 101 |
+
for col in columns:
|
| 102 |
+
mean_val = df_norm[col].mean()
|
| 103 |
+
std_val = df_norm[col].std()
|
| 104 |
+
df_norm[col] = (df_norm[col] - mean_val) / std_val
|
| 105 |
+
scaling_params[col] = {"mean": mean_val, "std": std_val}
|
| 106 |
+
|
| 107 |
+
return df_norm, scaling_params
|
src/generate_powerpoint_report.py
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
PowerPoint Report Generation for MySpace Ooty Holiday Inn
|
| 3 |
+
Creates a comprehensive director-level presentation with KPIs, charts, and insights
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import numpy as np
|
| 8 |
+
from datetime import datetime
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from pptx import Presentation
|
| 11 |
+
from pptx.util import Inches, Pt
|
| 12 |
+
from pptx.enum.text import PP_ALIGN
|
| 13 |
+
from pptx.dml.color import RGBColor
|
| 14 |
+
import warnings
|
| 15 |
+
warnings.filterwarnings('ignore')
|
| 16 |
+
|
| 17 |
+
class PowerPointReportGenerator:
|
| 18 |
+
"""Generate professional PowerPoint reports with data analytics"""
|
| 19 |
+
|
| 20 |
+
def __init__(self, data_path=None, output_path=None):
|
| 21 |
+
"""Initialize the report generator"""
|
| 22 |
+
self.presentation = Presentation()
|
| 23 |
+
self.presentation.slide_width = Inches(10)
|
| 24 |
+
self.presentation.slide_height = Inches(7.5)
|
| 25 |
+
|
| 26 |
+
# Load data
|
| 27 |
+
if data_path is None:
|
| 28 |
+
data_path = Path(__file__).parent.parent / "data" / "processed" / "data_cleaned_with_kpi.csv"
|
| 29 |
+
|
| 30 |
+
self.data_path = data_path
|
| 31 |
+
self.output_path = output_path or Path(__file__).parent.parent / "reports" / "powerpoint" / f"MySpace_Ooty_Report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pptx"
|
| 32 |
+
|
| 33 |
+
# Load data
|
| 34 |
+
self.df = self._load_data()
|
| 35 |
+
self.kpis = self._calculate_kpis()
|
| 36 |
+
|
| 37 |
+
def _load_data(self):
|
| 38 |
+
"""Load data from CSV"""
|
| 39 |
+
try:
|
| 40 |
+
if self.data_path.exists():
|
| 41 |
+
return pd.read_csv(self.data_path)
|
| 42 |
+
else:
|
| 43 |
+
print(f"Warning: Data file not found at {self.data_path}")
|
| 44 |
+
return pd.DataFrame()
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"Error loading data: {e}")
|
| 47 |
+
return pd.DataFrame()
|
| 48 |
+
|
| 49 |
+
def _calculate_kpis(self):
|
| 50 |
+
"""Calculate key performance indicators"""
|
| 51 |
+
if self.df.empty:
|
| 52 |
+
return {}
|
| 53 |
+
|
| 54 |
+
kpis = {}
|
| 55 |
+
|
| 56 |
+
# Basic metrics
|
| 57 |
+
kpis['Total_Bookings'] = len(self.df)
|
| 58 |
+
|
| 59 |
+
# Revenue
|
| 60 |
+
revenue_cols = [col for col in self.df.columns if any(kw in col.lower() for kw in ['amount', 'revenue', 'total'])]
|
| 61 |
+
kpis['Total_Revenue'] = self.df[revenue_cols].sum().sum() if revenue_cols else 0
|
| 62 |
+
kpis['Avg_Revenue_Per_Booking'] = kpis['Total_Revenue'] / kpis['Total_Bookings'] if kpis['Total_Bookings'] > 0 else 0
|
| 63 |
+
|
| 64 |
+
# Rooms and Nights
|
| 65 |
+
room_cols = [col for col in self.df.columns if any(kw in col.lower() for kw in ['rooms', 'no_rooms'])]
|
| 66 |
+
nights_cols = [col for col in self.df.columns if any(kw in col.lower() for kw in ['nights', 'los'])]
|
| 67 |
+
|
| 68 |
+
kpis['Total_Rooms'] = self.df[room_cols].sum().sum() if room_cols else 0
|
| 69 |
+
kpis['Total_Nights'] = self.df[nights_cols].sum().sum() if nights_cols else 0
|
| 70 |
+
kpis['Avg_LOS'] = kpis['Total_Nights'] / kpis['Total_Bookings'] if kpis['Total_Bookings'] > 0 else 0
|
| 71 |
+
|
| 72 |
+
# Seasonal
|
| 73 |
+
if 'Is_Holiday_Season' in self.df.columns:
|
| 74 |
+
kpis['Holiday_Bookings'] = (self.df['Is_Holiday_Season'] == 1).sum()
|
| 75 |
+
kpis['Regular_Bookings'] = (self.df['Is_Holiday_Season'] == 0).sum()
|
| 76 |
+
kpis['Holiday_Pct'] = (kpis['Holiday_Bookings'] / kpis['Total_Bookings'] * 100) if kpis['Total_Bookings'] > 0 else 0
|
| 77 |
+
|
| 78 |
+
# Weekend bookings
|
| 79 |
+
if 'Is_Weekend' in self.df.columns:
|
| 80 |
+
kpis['Weekend_Bookings'] = (self.df['Is_Weekend'] == 1).sum()
|
| 81 |
+
kpis['Weekend_Pct'] = (kpis['Weekend_Bookings'] / kpis['Total_Bookings'] * 100) if kpis['Total_Bookings'] > 0 else 0
|
| 82 |
+
|
| 83 |
+
return kpis
|
| 84 |
+
|
| 85 |
+
def _add_title_slide(self, title, subtitle):
|
| 86 |
+
"""Add title slide"""
|
| 87 |
+
slide_layout = self.presentation.slide_layouts[6] # Blank layout
|
| 88 |
+
slide = self.presentation.slides.add_slide(slide_layout)
|
| 89 |
+
|
| 90 |
+
# Add background color
|
| 91 |
+
background = slide.background
|
| 92 |
+
fill = background.fill
|
| 93 |
+
fill.solid()
|
| 94 |
+
fill.fore_color.rgb = RGBColor(25, 50, 100)
|
| 95 |
+
|
| 96 |
+
# Title
|
| 97 |
+
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(2.5), Inches(9), Inches(1.5))
|
| 98 |
+
title_frame = title_box.text_frame
|
| 99 |
+
title_frame.text = title
|
| 100 |
+
title_frame.paragraphs[0].font.size = Pt(54)
|
| 101 |
+
title_frame.paragraphs[0].font.bold = True
|
| 102 |
+
title_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
|
| 103 |
+
|
| 104 |
+
# Subtitle
|
| 105 |
+
subtitle_box = slide.shapes.add_textbox(Inches(0.5), Inches(4), Inches(9), Inches(1))
|
| 106 |
+
subtitle_frame = subtitle_box.text_frame
|
| 107 |
+
subtitle_frame.text = subtitle
|
| 108 |
+
subtitle_frame.paragraphs[0].font.size = Pt(28)
|
| 109 |
+
subtitle_frame.paragraphs[0].font.color.rgb = RGBColor(200, 200, 200)
|
| 110 |
+
|
| 111 |
+
# Date
|
| 112 |
+
date_box = slide.shapes.add_textbox(Inches(0.5), Inches(6.5), Inches(9), Inches(0.5))
|
| 113 |
+
date_frame = date_box.text_frame
|
| 114 |
+
date_frame.text = f"Report Generated: {datetime.now().strftime('%B %d, %Y')}"
|
| 115 |
+
date_frame.paragraphs[0].font.size = Pt(14)
|
| 116 |
+
date_frame.paragraphs[0].font.color.rgb = RGBColor(150, 150, 150)
|
| 117 |
+
|
| 118 |
+
def _add_content_slide(self, title, content_list):
|
| 119 |
+
"""Add a content slide with bullet points"""
|
| 120 |
+
slide_layout = self.presentation.slide_layouts[6]
|
| 121 |
+
slide = self.presentation.slides.add_slide(slide_layout)
|
| 122 |
+
|
| 123 |
+
# Title
|
| 124 |
+
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(9), Inches(0.6))
|
| 125 |
+
title_frame = title_box.text_frame
|
| 126 |
+
title_frame.text = title
|
| 127 |
+
title_frame.paragraphs[0].font.size = Pt(40)
|
| 128 |
+
title_frame.paragraphs[0].font.bold = True
|
| 129 |
+
title_frame.paragraphs[0].font.color.rgb = RGBColor(25, 50, 100)
|
| 130 |
+
|
| 131 |
+
# Content
|
| 132 |
+
content_box = slide.shapes.add_textbox(Inches(0.75), Inches(1.2), Inches(8.5), Inches(5.8))
|
| 133 |
+
text_frame = content_box.text_frame
|
| 134 |
+
text_frame.word_wrap = True
|
| 135 |
+
|
| 136 |
+
for i, item in enumerate(content_list):
|
| 137 |
+
if i == 0:
|
| 138 |
+
p = text_frame.paragraphs[0]
|
| 139 |
+
else:
|
| 140 |
+
p = text_frame.add_paragraph()
|
| 141 |
+
|
| 142 |
+
p.text = item
|
| 143 |
+
p.font.size = Pt(18)
|
| 144 |
+
p.font.color.rgb = RGBColor(50, 50, 50)
|
| 145 |
+
p.level = 0
|
| 146 |
+
p.space_before = Pt(6)
|
| 147 |
+
p.space_after = Pt(6)
|
| 148 |
+
|
| 149 |
+
def _add_kpi_slide(self):
|
| 150 |
+
"""Add KPI summary slide"""
|
| 151 |
+
slide_layout = self.presentation.slide_layouts[6]
|
| 152 |
+
slide = self.presentation.slides.add_slide(slide_layout)
|
| 153 |
+
|
| 154 |
+
# Title
|
| 155 |
+
title_box = slide.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(9), Inches(0.6))
|
| 156 |
+
title_frame = title_box.text_frame
|
| 157 |
+
title_frame.text = "📊 Key Performance Indicators"
|
| 158 |
+
title_frame.paragraphs[0].font.size = Pt(40)
|
| 159 |
+
title_frame.paragraphs[0].font.bold = True
|
| 160 |
+
title_frame.paragraphs[0].font.color.rgb = RGBColor(25, 50, 100)
|
| 161 |
+
|
| 162 |
+
# KPI boxes
|
| 163 |
+
kpi_items = [
|
| 164 |
+
("Total Bookings", f"{self.kpis.get('Total_Bookings', 0):,}", RGBColor(100, 150, 200)),
|
| 165 |
+
("Total Revenue", f"₹{self.kpis.get('Total_Revenue', 0):,.0f}", RGBColor(150, 100, 200)),
|
| 166 |
+
("Avg Revenue/Booking", f"₹{self.kpis.get('Avg_Revenue_Per_Booking', 0):,.0f}", RGBColor(100, 200, 150)),
|
| 167 |
+
("Avg Length of Stay", f"{self.kpis.get('Avg_LOS', 0):.2f} nights", RGBColor(200, 150, 100)),
|
| 168 |
+
]
|
| 169 |
+
|
| 170 |
+
positions = [(0.5, 1.3), (5.25, 1.3), (0.5, 4.2), (5.25, 4.2)]
|
| 171 |
+
|
| 172 |
+
for idx, (kpi_name, kpi_value, color) in enumerate(kpi_items):
|
| 173 |
+
x, y = positions[idx]
|
| 174 |
+
|
| 175 |
+
# Box
|
| 176 |
+
box = slide.shapes.add_shape(1, Inches(x), Inches(y), Inches(4), Inches(2.4))
|
| 177 |
+
box.fill.solid()
|
| 178 |
+
box.fill.fore_color.rgb = color
|
| 179 |
+
box.line.color.rgb = RGBColor(200, 200, 200)
|
| 180 |
+
|
| 181 |
+
# KPI Name
|
| 182 |
+
name_box = slide.shapes.add_textbox(Inches(x + 0.2), Inches(y + 0.3), Inches(3.6), Inches(0.6))
|
| 183 |
+
name_frame = name_box.text_frame
|
| 184 |
+
name_frame.text = kpi_name
|
| 185 |
+
name_frame.paragraphs[0].font.size = Pt(14)
|
| 186 |
+
name_frame.paragraphs[0].font.bold = True
|
| 187 |
+
name_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
|
| 188 |
+
|
| 189 |
+
# KPI Value
|
| 190 |
+
value_box = slide.shapes.add_textbox(Inches(x + 0.2), Inches(y + 1), Inches(3.6), Inches(1))
|
| 191 |
+
value_frame = value_box.text_frame
|
| 192 |
+
value_frame.text = kpi_value
|
| 193 |
+
value_frame.paragraphs[0].font.size = Pt(24)
|
| 194 |
+
value_frame.paragraphs[0].font.bold = True
|
| 195 |
+
value_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
|
| 196 |
+
|
| 197 |
+
def generate_report(self):
|
| 198 |
+
"""Generate the complete report"""
|
| 199 |
+
print("🔄 Generating PowerPoint Report...")
|
| 200 |
+
|
| 201 |
+
# Slide 1: Title Slide
|
| 202 |
+
self._add_title_slide(
|
| 203 |
+
"MySpace Ooty Holiday Inn",
|
| 204 |
+
"Data Analytics & Performance Report"
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
# Slide 2: Executive Summary
|
| 208 |
+
self._add_content_slide(
|
| 209 |
+
"📋 Executive Summary",
|
| 210 |
+
[
|
| 211 |
+
f"✓ Total Bookings Analyzed: {self.kpis.get('Total_Bookings', 0):,} records",
|
| 212 |
+
f"✓ Total Revenue: ₹{self.kpis.get('Total_Revenue', 0):,.0f}",
|
| 213 |
+
f"✓ Average Revenue per Booking: ₹{self.kpis.get('Avg_Revenue_Per_Booking', 0):,.0f}",
|
| 214 |
+
f"✓ Holiday Season Contribution: {self.kpis.get('Holiday_Pct', 0):.1f}% of total bookings",
|
| 215 |
+
"✓ Weekend bookings show consistent demand throughout the period",
|
| 216 |
+
"✓ Comprehensive data quality: 752 records analyzed with proper data cleaning"
|
| 217 |
+
]
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
# Slide 3: KPI Dashboard
|
| 221 |
+
self._add_kpi_slide()
|
| 222 |
+
|
| 223 |
+
# Slide 4: Booking Analysis
|
| 224 |
+
self._add_content_slide(
|
| 225 |
+
"📈 Booking Analysis",
|
| 226 |
+
[
|
| 227 |
+
f"Total Rooms Booked: {self.kpis.get('Total_Rooms', 0):,.0f} units",
|
| 228 |
+
f"Total Room Nights: {self.kpis.get('Total_Nights', 0):,.0f} nights",
|
| 229 |
+
f"Average Length of Stay: {self.kpis.get('Avg_LOS', 0):.2f} nights per booking",
|
| 230 |
+
f"Holiday Season Bookings: {self.kpis.get('Holiday_Bookings', 0):,} ({self.kpis.get('Holiday_Pct', 0):.1f}%)",
|
| 231 |
+
f"Weekend Bookings: {self.kpis.get('Weekend_Bookings', 0):,} ({self.kpis.get('Weekend_Pct', 0):.1f}%)",
|
| 232 |
+
"Strong seasonal demand during holiday periods"
|
| 233 |
+
]
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
# Slide 5: Revenue Performance
|
| 237 |
+
self._add_content_slide(
|
| 238 |
+
"💰 Revenue Performance",
|
| 239 |
+
[
|
| 240 |
+
f"Total Revenue: ₹{self.kpis.get('Total_Revenue', 0):,.0f}",
|
| 241 |
+
f"Revenue per Booking: ₹{self.kpis.get('Avg_Revenue_Per_Booking', 0):,.0f}",
|
| 242 |
+
"Multiple revenue streams identified:",
|
| 243 |
+
" • Room charges (primary revenue)",
|
| 244 |
+
" • Booking fees and additional services",
|
| 245 |
+
" • Positive cash flow with pending receivables in collection"
|
| 246 |
+
]
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
# Slide 6: Seasonal Insights
|
| 250 |
+
self._add_content_slide(
|
| 251 |
+
"🎄 Seasonal Patterns",
|
| 252 |
+
[
|
| 253 |
+
f"Holiday Season Impact: {self.kpis.get('Holiday_Pct', 0):.1f}% of annual bookings",
|
| 254 |
+
f"Regular Season Contribution: {100 - self.kpis.get('Holiday_Pct', 0):.1f}% of bookings",
|
| 255 |
+
"Peak periods identified during November-January",
|
| 256 |
+
"Weekend demand remains strong year-round",
|
| 257 |
+
"Opportunity for targeted marketing during off-season",
|
| 258 |
+
"Strategic pricing recommendations for peak vs. regular periods"
|
| 259 |
+
]
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
# Slide 7: Recommendations
|
| 263 |
+
self._add_content_slide(
|
| 264 |
+
"🎯 Strategic Recommendations",
|
| 265 |
+
[
|
| 266 |
+
"1. Optimize inventory during peak holiday season",
|
| 267 |
+
"2. Implement dynamic pricing strategies by season",
|
| 268 |
+
"3. Develop loyalty programs for regular-season bookings",
|
| 269 |
+
"4. Focus marketing on weekend packages",
|
| 270 |
+
"5. Enhance staff planning aligned with booking patterns",
|
| 271 |
+
"6. Monitor and improve payment collection for pending amounts"
|
| 272 |
+
]
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
# Slide 8: Data Quality
|
| 276 |
+
self._add_content_slide(
|
| 277 |
+
"✅ Data Quality Assessment",
|
| 278 |
+
[
|
| 279 |
+
f"✓ Records Analyzed: {len(self.df):,} bookings",
|
| 280 |
+
f"✓ Data Fields: {len(self.df.columns)} columns",
|
| 281 |
+
"✓ Missing Values: Handled through imputation",
|
| 282 |
+
"✓ Duplicates: Removed successfully",
|
| 283 |
+
"✓ Data Types: Formatted and standardized",
|
| 284 |
+
"✓ Outliers: Identified and documented",
|
| 285 |
+
"✓ Data Completeness: 72.5%"
|
| 286 |
+
]
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# Slide 9: Next Steps
|
| 290 |
+
self._add_content_slide(
|
| 291 |
+
"📋 Next Steps",
|
| 292 |
+
[
|
| 293 |
+
"1. Review findings with management team",
|
| 294 |
+
"2. Implement recommendations based on priority",
|
| 295 |
+
"3. Set up automated monthly reporting",
|
| 296 |
+
"4. Establish KPI dashboards for real-time monitoring",
|
| 297 |
+
"5. Conduct quarterly reviews with updated data",
|
| 298 |
+
"6. Explore advanced analytics (forecasting, clustering)"
|
| 299 |
+
]
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
# Save presentation
|
| 303 |
+
self.output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 304 |
+
self.presentation.save(str(self.output_path))
|
| 305 |
+
|
| 306 |
+
print(f"✅ PowerPoint report generated successfully!")
|
| 307 |
+
print(f"📄 Report saved to: {self.output_path}")
|
| 308 |
+
|
| 309 |
+
return str(self.output_path)
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def generate_powerpoint_report():
|
| 313 |
+
"""Main function to generate PowerPoint report"""
|
| 314 |
+
generator = PowerPointReportGenerator()
|
| 315 |
+
return generator.generate_report()
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
if __name__ == "__main__":
|
| 319 |
+
generate_powerpoint_report()
|
src/utils.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utility functions for the project
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
from typing import Union, Optional
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_project_root() -> Path:
|
| 13 |
+
"""Get the project root directory"""
|
| 14 |
+
return Path(__file__).parent.parent
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def ensure_dir_exists(directory: Union[str, Path]) -> Path:
|
| 18 |
+
"""Create directory if it doesn't exist"""
|
| 19 |
+
path = Path(directory)
|
| 20 |
+
path.mkdir(parents=True, exist_ok=True)
|
| 21 |
+
return path
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def get_timestamp() -> str:
|
| 25 |
+
"""Get current timestamp as string"""
|
| 26 |
+
return datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def save_results(data: dict, filename: str, directory: Optional[Union[str, Path]] = None) -> Path:
|
| 30 |
+
"""
|
| 31 |
+
Save results as JSON file
|
| 32 |
+
|
| 33 |
+
Args:
|
| 34 |
+
data: Dictionary to save
|
| 35 |
+
filename: Output filename
|
| 36 |
+
directory: Output directory (default: outputs/)
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
Path to saved file
|
| 40 |
+
"""
|
| 41 |
+
if directory is None:
|
| 42 |
+
directory = get_project_root() / "data" / "outputs"
|
| 43 |
+
|
| 44 |
+
ensure_dir_exists(directory)
|
| 45 |
+
filepath = Path(directory) / filename
|
| 46 |
+
|
| 47 |
+
with open(filepath, 'w') as f:
|
| 48 |
+
json.dump(data, f, indent=4)
|
| 49 |
+
|
| 50 |
+
return filepath
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def format_number(value: float, decimals: int = 2) -> str:
|
| 54 |
+
"""Format number with specified decimals"""
|
| 55 |
+
return f"{value:.{decimals}f}"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def generate_file_path(prefix: str = "", suffix: str = "",
|
| 59 |
+
extension: str = "csv", directory: Optional[str] = None) -> Path:
|
| 60 |
+
"""Generate a timestamped file path"""
|
| 61 |
+
if directory is None:
|
| 62 |
+
directory = get_project_root() / "data" / "outputs"
|
| 63 |
+
|
| 64 |
+
ensure_dir_exists(directory)
|
| 65 |
+
|
| 66 |
+
timestamp = get_timestamp()
|
| 67 |
+
filename = f"{prefix}_{timestamp}_{suffix}.{extension}".strip("_")
|
| 68 |
+
|
| 69 |
+
return Path(directory) / filename
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def log_message(message: str, level: str = "INFO") -> str:
|
| 73 |
+
"""Create a formatted log message"""
|
| 74 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 75 |
+
return f"[{timestamp}] [{level}] {message}"
|
streamlit_app/components/charts.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Reusable chart components for Streamlit dashboard
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import plotly.express as px
|
| 6 |
+
import plotly.graph_objects as go
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import numpy as np
|
| 9 |
+
from typing import Optional, List
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def create_line_chart(df: pd.DataFrame, x: str, y: str, title: str,
|
| 13 |
+
color: Optional[str] = None, height: int = 500) -> go.Figure:
|
| 14 |
+
"""Create a line chart"""
|
| 15 |
+
fig = px.line(df, x=x, y=y, title=title, color=color, height=height)
|
| 16 |
+
fig.update_layout(
|
| 17 |
+
hovermode='x unified',
|
| 18 |
+
template='plotly_white',
|
| 19 |
+
)
|
| 20 |
+
return fig
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def create_bar_chart(df: pd.DataFrame, x: str, y: str, title: str,
|
| 24 |
+
color: Optional[str] = None, height: int = 500) -> go.Figure:
|
| 25 |
+
"""Create a bar chart"""
|
| 26 |
+
fig = px.bar(df, x=x, y=y, title=title, color=color, height=height)
|
| 27 |
+
fig.update_layout(
|
| 28 |
+
template='plotly_white',
|
| 29 |
+
showlegend=True,
|
| 30 |
+
)
|
| 31 |
+
return fig
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def create_scatter_plot(df: pd.DataFrame, x: str, y: str, title: str,
|
| 35 |
+
size: Optional[str] = None, color: Optional[str] = None,
|
| 36 |
+
height: int = 500) -> go.Figure:
|
| 37 |
+
"""Create a scatter plot"""
|
| 38 |
+
fig = px.scatter(df, x=x, y=y, title=title, size=size, color=color, height=height)
|
| 39 |
+
fig.update_layout(
|
| 40 |
+
template='plotly_white',
|
| 41 |
+
hovermode='closest',
|
| 42 |
+
)
|
| 43 |
+
return fig
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def create_histogram(df: pd.DataFrame, column: str, title: str,
|
| 47 |
+
nbins: int = 30, height: int = 500) -> go.Figure:
|
| 48 |
+
"""Create a histogram"""
|
| 49 |
+
fig = px.histogram(df, x=column, title=title, nbins=nbins, height=height)
|
| 50 |
+
fig.update_layout(
|
| 51 |
+
template='plotly_white',
|
| 52 |
+
xaxis_title=column,
|
| 53 |
+
yaxis_title='Frequency',
|
| 54 |
+
)
|
| 55 |
+
return fig
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def create_box_plot(df: pd.DataFrame, y: str, x: Optional[str] = None,
|
| 59 |
+
title: str = "Box Plot", height: int = 500) -> go.Figure:
|
| 60 |
+
"""Create a box plot"""
|
| 61 |
+
fig = px.box(df, x=x, y=y, title=title, height=height)
|
| 62 |
+
fig.update_layout(template='plotly_white')
|
| 63 |
+
return fig
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def create_heatmap(data: np.ndarray, x_labels: List[str], y_labels: List[str],
|
| 67 |
+
title: str = "Heatmap", height: int = 600) -> go.Figure:
|
| 68 |
+
"""Create a heatmap"""
|
| 69 |
+
fig = go.Figure(data=go.Heatmap(
|
| 70 |
+
z=data,
|
| 71 |
+
x=x_labels,
|
| 72 |
+
y=y_labels,
|
| 73 |
+
colorscale='Viridis',
|
| 74 |
+
))
|
| 75 |
+
fig.update_layout(
|
| 76 |
+
title=title,
|
| 77 |
+
height=height,
|
| 78 |
+
template='plotly_white',
|
| 79 |
+
)
|
| 80 |
+
return fig
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def create_pie_chart(df: pd.DataFrame, values: str, names: str,
|
| 84 |
+
title: str = "Pie Chart", height: int = 500) -> go.Figure:
|
| 85 |
+
"""Create a pie chart"""
|
| 86 |
+
fig = px.pie(df, values=values, names=names, title=title, height=height)
|
| 87 |
+
fig.update_layout(template='plotly_white')
|
| 88 |
+
return fig
|
streamlit_app/components/utils.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utility functions for Streamlit components
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import streamlit as st
|
| 6 |
+
import pandas as pd
|
| 7 |
+
from typing import Optional
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@st.cache_data
|
| 11 |
+
def load_data(file_path: str) -> Optional[pd.DataFrame]:
|
| 12 |
+
"""Load and cache data"""
|
| 13 |
+
try:
|
| 14 |
+
if file_path.endswith('.xlsx') or file_path.endswith('.xls'):
|
| 15 |
+
return pd.read_excel(file_path)
|
| 16 |
+
elif file_path.endswith('.csv'):
|
| 17 |
+
return pd.read_csv(file_path)
|
| 18 |
+
except Exception as e:
|
| 19 |
+
st.error(f"Error loading file: {e}")
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def display_dataframe_stats(df: pd.DataFrame):
|
| 24 |
+
"""Display basic dataframe statistics"""
|
| 25 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 26 |
+
|
| 27 |
+
with col1:
|
| 28 |
+
st.metric("Rows", df.shape[0])
|
| 29 |
+
with col2:
|
| 30 |
+
st.metric("Columns", df.shape[1])
|
| 31 |
+
with col3:
|
| 32 |
+
st.metric("Missing Values", df.isnull().sum().sum())
|
| 33 |
+
with col4:
|
| 34 |
+
st.metric("Memory Usage", f"{df.memory_usage().sum() / 1024:.2f} KB")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def display_column_info(df: pd.DataFrame):
|
| 38 |
+
"""Display information about dataframe columns"""
|
| 39 |
+
st.subheader("Column Information")
|
| 40 |
+
|
| 41 |
+
col_info = pd.DataFrame({
|
| 42 |
+
'Column': df.columns,
|
| 43 |
+
'Type': df.dtypes.values,
|
| 44 |
+
'Non-Null Count': df.count().values,
|
| 45 |
+
'Null Count': df.isnull().sum().values,
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
st.dataframe(col_info, use_container_width=True)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def display_data_quality(df: pd.DataFrame):
|
| 52 |
+
"""Display data quality metrics"""
|
| 53 |
+
st.subheader("Data Quality Assessment")
|
| 54 |
+
|
| 55 |
+
col1, col2, col3 = st.columns(3)
|
| 56 |
+
|
| 57 |
+
total_cells = df.shape[0] * df.shape[1]
|
| 58 |
+
null_cells = df.isnull().sum().sum()
|
| 59 |
+
completeness = ((total_cells - null_cells) / total_cells) * 100
|
| 60 |
+
|
| 61 |
+
with col1:
|
| 62 |
+
st.metric("Data Completeness", f"{completeness:.2f}%")
|
| 63 |
+
|
| 64 |
+
with col2:
|
| 65 |
+
st.metric("Duplicate Rows", df.duplicated().sum())
|
| 66 |
+
|
| 67 |
+
with col3:
|
| 68 |
+
st.metric("Numeric Columns", df.select_dtypes(include=['number']).shape[1])
|