A clean, 4-layer production-style pipeline for clickstream ingestion, transformation, and learning collapse detection.
streaming_pipeline/
├── core/ # ML Logic & Feature Engineering
├── ingest/ # Data Source Connectors (Simulated & DB)
├── stream/ # Spark Streaming & Transformation Engine
├── output/ # Centralized Results (Predictions, Features)
└── run.py # Unified Entry Point
- Python 3.8+
- Apache Spark 3.5.0+ (for full features)
- Java 8/11 (for Spark)
pip install -r requirements.txtRun the pipeline using the unified launcher:
Windows:
.\run_demo.bat --mode <mode>Linux/Mac:
./run_demo.sh --mode <mode>simulate: Runs end-to-end demo with generated synthetic data.database: Pulls real clickstream data from your production database.stream: Starts the real-time Spark Structured Streaming engine.
- Ingest: Raw events from
ingest/simulator.pyoringest/database.py. - Transform: Timestamps converted to relative course days in
stream/transformer.py. - Core: Features engineered in
core/behavior_model.pyand passed tocore/collapse_detector.py. - Output: Results saved to
output/predictions.csv.
- Database: Set
DATABASE_URLenvironment variable for real data extraction. - Spark: Ensure
SPARK_HOMEis set for streaming and distributed processing.
After running, check the output/ directory:
raw_simulated.csv: Raw events generated.predictions/: KMeans cluster assignments and risk labels.