8acfb436f3f1b1faa396fd76e7c9c943924c4ac9
- Added `/load-data` endpoint to load transaction data from either a database or a CSV file. - Updated `SalaryAnalyticsPipeline` and `DataLoader` to support loading from CSV. - Implemented data validation and error handling for loading processes. - Revised README to include new data loading instructions and workflow steps. - Added checks to ensure data is loaded before running analysis endpoints.
Salary Analytics
A comprehensive salary analytics system that analyzes transaction data to identify salary earners, predict future salaries, and generate detailed reports.
Features
-
Transaction Analysis
- Keyword-based salary transaction identification
- Consistent amount transaction analysis
- Transaction type analysis
- Hypothesis overlap visualization
-
Salary Earner Classification
- Verified salary earners identification
- Likely salary earners identification
- High earner detection
- Salary pattern analysis
-
Machine Learning
- Salary prediction models
- Separate models for consistent and inconsistent earners
- Feature engineering
- Model evaluation metrics
-
Reporting
- CSV reports generation
- Visualization plots
- High earner details
- Salary earner statistics
Architecture
The project is organized into the following modules:
salary_analytics/
├── __init__.py
├── config.py # Configuration settings
├── data_loader.py # Database connection and data loading
├── keyword_analyzer.py # Keyword-based analysis
├── consistent_amount_analyzer.py # Consistent amount analysis
├── transaction_type_analyzer.py # Transaction type analysis
├── salary_earner_analyzer.py # Salary earner analysis
├── salary_predictor.py # Machine learning models
├── main.py # Main pipeline
└── api.py # FastAPI endpoints
Configuration
The system can be configured through environment variables or the config.py file:
# Database Configuration
DB_CONFIG = {
"user": "db_user",
"password": "your_secure_password",
"name": "salary_db",
"port": "5432",
"host": "localhost"
}
# Model Configuration
MODEL_CONFIG = {
"cv_threshold": 0.10,
"min_transactions": 3,
"threshold": 0.7,
"high_earner_threshold": 10000
}
Usage
Using the API
- Start the API server:
uvicorn salary_analytics.api:app --reload
- Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
-
Basic Endpoints
GET /: Welcome messageGET /health: Health check
-
Data Loading
POST /load-data: Load transaction data- Parameters:
source: Data source ('db' or 'csv')file: CSV file (required if source is 'csv')
- Example:
# Load from database curl -X POST "http://localhost:8000/load-data?source=db" # Load from CSV curl -X POST "http://localhost:8000/load-data?source=csv" -F "file=@path/to/your/file.csv"
- Parameters:
-
Analysis Endpoints
POST /analyze/keyword: Run keyword analysisPOST /analyze/consistent-amount: Run consistent amount analysisPOST /analyze/transaction-type: Run transaction type analysis
-
Report Generation
POST /generate/reports: Generate all reportsGET /download/{report_type}: Download specific reports- Available types:
high_earners: High earner detailslikely_earners: Likely salary earnersfinal_table: Final analysis tableconsistent_plot: Consistent earners plotinconsistent_plot: Inconsistent earners plothypothesis_plot: Hypothesis overlap plot
- Available types:
-
Model Training
POST /train/models: Train prediction models
-
Pipeline
POST /run/pipeline: Run complete pipeline
Workflow
- Start the API server
- Load data using the
/load-dataendpoint - Run any of the analysis endpoints
- Generate and download reports as needed
Note: All analysis endpoints require data to be loaded first. If you try to run any analysis without loading data, you'll receive a 400 error with a message to load data first.
Docker Deployment
- Build the Docker image:
docker-compose build
- Run the container:
docker-compose up
The API will be available at http://localhost:8000
Output Structure
output/
├── csv/
│ ├── high_earner_details.csv
│ ├── likely_salary_earner.csv
│ └── final_table.csv
└── plots/
├── consistent_earners_predictions.png
├── inconsistent_earners_predictions.png
└── hypothesis_overlap.png
Description
Languages
HTML
53.1%
Jupyter Notebook
44.6%
Python
2.3%