Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__/
*.pyc
*.pyo
*.pyd
.pytest_cache/
.DS_Store
.env
node_modules/
dist/
build/
Binary file removed balancer/__pycache__/core.cpython-311.pyc
Binary file not shown.
Binary file not shown.
13 changes: 8 additions & 5 deletions balancer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
from typing import List, Dict, Any, Optional
import uuid

# --- Constants ---

CRITICAL_LOW_DAYS = 15
TARGET_STOCK_DAYS = 30
BASE_OVERSTOCK_DAYS = 90

# --- Data Structures ---

class InventoryItem:
Expand Down Expand Up @@ -37,7 +43,7 @@ def calculate_bmi(item: InventoryItem) -> float:
return 9999.0 # Effectively infinite stock if no burn
return item.current_stock / item.daily_burn_rate

def calculate_dynamic_threshold(expiry_date: datetime.date, current_date: datetime.date, base_threshold_days: int = 90) -> float:
def calculate_dynamic_threshold(expiry_date: datetime.date, current_date: datetime.date, base_threshold_days: int = BASE_OVERSTOCK_DAYS) -> float:
"""
Calculates the dynamic overstock threshold based on expiry pressure.
Formula: Threshold_dynamic = Threshold_base * (Months_to_Expiry / 12)
Expand Down Expand Up @@ -65,9 +71,6 @@ def detect_imbalances(clinics: List[Clinic], current_date: datetime.date) -> Lis
shortages: Dict[str, List[Dict]] = {}
surpluses: Dict[str, List[Dict]] = {}

CRITICAL_LOW_DAYS = 15
BASE_OVERSTOCK_DAYS = 90

# 1. Identify Imbalances
for clinic in clinics:
for item in clinic.inventory:
Expand All @@ -76,7 +79,7 @@ def detect_imbalances(clinics: List[Clinic], current_date: datetime.date) -> Lis

# Check for Shortage
if doi < CRITICAL_LOW_DAYS:
needed_qty = int((30 * item.daily_burn_rate) - item.current_stock)
needed_qty = int((TARGET_STOCK_DAYS * item.daily_burn_rate) - item.current_stock)
if needed_qty > 0:
if item.sku not in shortages: shortages[item.sku] = []
shortages[item.sku].append({
Expand Down