Skip to content

marcprogcode/interhackBCN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Smart Demand Signals

Inibsa · Interhack BCN 2026

Hero Image - Project Banner

Python FastAPI MongoDB Docker Pandas

Smart Demand Signals is an advanced business intelligence and predictive analytics solution designed for Inibsa. It transforms five years of transactional data from 7,000 dental clinics into real-time, actionable alerts. By differentiating between high-frequency recurring purchases and technical pattern shifts, the system empowers sales teams to anticipate needs, capture missing demand, and mitigate churn risk.


🌟 Key Features

🧠 Dual-Track Prioritization Engine

The core analytical brain treats different product dynamics with surgical precision:

Engine Logic Visualization

  • Commodities (Recurring): Uses Inter-Purchase Time (IPT) analysis and 85th percentile peak tracking to detect exactly when a client is overdue. Includes automated seasonality adjustments (e.g., August downturns).
  • Technical Products (Variable): Focuses on volume-drop detection (>50% shifts) and pattern deterioration, identifying abandonment risks before they happen.

📊 Multi-Dimensional Scoring Framework

Alerts are not just flags; they are prioritized using a weighted model:

Scoring Model Weighting

  • Value (LTV): Prioritizes high-impact clients based on historical spend.
  • Urgency: Logarithmic scaling of overdue days to highlight critical windows.
  • Recoverability: A "cliff" penalty system that recognizes when a client is likely already lost.
  • Potential Bonus: Cross-references internal data with external potential to target "promiscuous" clients.
  • Confidence: Reliability score based on the length and consistency of the client's history.

🔌 Real-Time API & Persistence

  • FastAPI Backend: High-performance asynchronous API for fetching alerts.
  • MongoDB Integration: Persistent storage for alert statuses and historical snapshots.
  • Auto-Sync: Smart logic that triggers an engine recalculation if the data is stale (>20 mins).
  • Status Management: Track work-in-progress, completed, and discarded alerts.

API Documentation Preview

🔍 Transparent Interpretability

Every alert includes an Interpretability_JSON payload, allowing frontends to visualize:

  • Historical purchase timelines.
  • Dynamic "Soft Trigger" vs. "Hard Overdue" thresholds.
  • The exact formula components that led to the final score.

🏗️ Technical Architecture

graph TD
    subgraph Data Layer
        CSV[(Raw CSV/XLSX)]
        DB[(MongoDB)]
    end

    subgraph Analytical Engine
        PE[Prioritization Engine]
        DL[Data Loader]
        PE --> DL
        DL --> CSV
    end

    subgraph Presentation & API
        API[FastAPI Server]
        API --> DB
        API --> PE
    end

    subgraph Output
        UI[Retention Dashboard]
        API --> UI
    end
Loading

🛠️ Tech Stack

  • Language: Python 3.11+
  • Web Framework: FastAPI / Uvicorn
  • Database: MongoDB
  • Analysis: Pandas, NumPy, OpenPyXL
  • Visualization: Matplotlib, Seaborn
  • Ops: Docker, Pydantic

🚀 Getting Started

1. Prerequisites

  • Python 3.11 or higher.
  • MongoDB running locally (port 27017).

2. Installation

# Clone the repository
git clone https://github.com/marcprogcode/interhackBCN.git
cd interhackBCN

# Install dependencies
pip install -r requirements.txt

3. Running the Solution

To start the API and trigger the first data load:

python src/api.py

The server will be available at http://localhost:8000. You can explore the interactive documentation at /docs.

4. Docker Deployment

docker build -t demand-signals .
docker run -p 8000:8000 -e MONGO_URI="mongodb://host.docker.internal:27017/" demand-signals

🧪 Simulation & Testing

The project includes a suite of retroactive testing tools to validate the engine's performance on historical data:

Visual Analytics Demo

  • src/retroactive_sim.py: Runs a day-by-day simulation over a past period.
  • src/large_scale_test.py: Performance benchmarking.
  • src/visualize_alerts.py: Generates high-fidelity dark-themed plots for alert verification.

📂 Project Structure

  • src/: Main source code.
    • prioritization_engine.py: Core logic for alert generation.
    • api.py: FastAPI implementation & MongoDB orchestration.
    • data_loader.py: Data ingestion, cleaning, and normalization.
    • visualize_alerts.py: Matplotlib visualization suite for alerts.
    • retroactive_sim.py: Time-travel simulation for historical validation.
    • analyze_clients.py: Exploratory data analysis (LTV & Tenure).
    • large_scale_test.py: Performance & reliability benchmarking.
    • refresh_db.py: Manual trigger for full database recalculation.
  • data/: Input datasets.
  • docs/: Detailed API and technical documentation.
  • plots/: Generated visual reports.
  • outputs/: Daily alert exports and CSV logs.

📄 License

This project was developed for the Interhack BCN 2026 Hackathon. All rights reserved by Inibsa and the development team.

About

Back-end for the InterhackBCN competition. Calculates optimal time to contact clients to prevent churn.

Topics

Resources

Stars

Watchers

Forks

Contributors