A simple Python script that tracks business metrics and flags potential issues.
Monitors key performance indicators (KPIs) from a CSV file and alerts you when:
- Revenue drops significantly
- Profit margin falls too low
- Active users decline
No dashboards, no web apps. Just clear terminal output showing your metrics and any problems.
- Load data - Reads CSV with date, revenue, costs, profit, and active users
- Calculate KPIs - Computes profit margin, revenue growth, user growth
- Check alerts - Compares against configurable thresholds
- Print report - Shows period-by-period metrics and flags issues
Install dependencies:
pip install -r requirements.txtRun with a file path:
python kpi_monitor.py sample_kpi_data.csvOr run and enter the path when prompted:
python kpi_monitor.pyYour CSV should have these columns:
date- Date in YYYY-MM-DD formatrevenue- Total revenue for the periodcosts- Total costs for the periodprofit- Net profit (revenue - costs)active_users- Number of active users
Example:
date,revenue,costs,profit,active_users
2024-01-01,100000,70000,30000,5000
2024-02-01,105000,72000,33000,5100
2024-03-01,98000,71000,27000,4950Test the script with sample data:
python sample_data_generator.pyThis creates sample_kpi_data.csv with 12 months of data including some intentional issues to trigger alerts.
Edit the top of kpi_monitor.py to adjust alert thresholds:
REVENUE_DROP_THRESHOLD = 10 # Alert if revenue drops more than 10%
MIN_PROFIT_MARGIN = 15 # Alert if profit margin falls below 15%
USER_DECLINE_THRESHOLD = 5 # Alert if active users drop more than 5%📅 Period: 2024-06-01
--------------------------------------------------------------------------------
Revenue: $ 85,234.50 (-15.2%)
Costs: $ 59,664.15
Profit: $ 25,570.35
Profit Margin: 30.0%
Active Users: 5,234 (+2.1%)
🚨 ALERTS:
⚠️ REVENUE DROP: Revenue decreased by 15.2% ($100,276 → $85,235)
This is a simple monitoring tool with real constraints:
- No forecasting - Only looks at historical data, doesn't predict future
- No anomaly detection - Uses fixed thresholds, not statistical methods
- No data validation - Assumes clean, complete data
- No visualization - Text output only, no charts or graphs
- No database support - CSV files only
- No notifications - Prints to terminal, doesn't send emails/Slack messages
- Simple period comparison - Only compares consecutive periods
- No seasonality handling - Doesn't account for seasonal patterns
If I continue this project, I might add:
- Export alerts to a log file
- Email/Slack notifications when alerts trigger
- Support for multiple KPI files
- Visualization with matplotlib (simple charts)
- Moving averages for trend analysis
- Year-over-year comparisons
- Configurable alert rules via config file
- Database support (SQLite, PostgreSQL)
- More KPIs (customer acquisition cost, churn rate, etc.)
I wanted to:
- Learn basic business analytics with Python
- Practice working with time-series data
- Build something practical for monitoring
- Keep it simple enough to understand and modify
MIT - Use this however you want.