#!/usr/bin/env python3 """ Literature-Informed Warehouse & Inventory Management Dataset ============================================================== Each record = ONE warehouse/store observation for ONE commodity category during ONE monthly reporting period. Sources: [1] USAID GHSC-PSM. Warehouse management best practices. Storage conditions, inventory accuracy, order fulfilment. [2] WHO (2014). Good storage and distribution practices. Temperature, humidity, pest control, FEFO compliance. [3] JSI/SIAPS. Strengthening pharmaceutical supply chains. Inventory accuracy, stock record discrepancies. [4] UNICEF Supply Division. Warehouse capacity assessments. Only 40-60% of SSA warehouses meet WHO GDP standards. """ import numpy as np import pandas as pd import argparse import os COMMODITY_CATEGORIES = [ ('essential_medicines', 'ambient', 'high', 0.35), ('ARVs', 'ambient', 'high', 0.15), ('vaccines', 'cold_chain_2_8C', 'critical', 0.08), ('laboratory_reagents', 'cold_chain_2_8C', 'medium', 0.05), ('contraceptives', 'ambient', 'medium', 0.08), ('malaria_commodities', 'ambient', 'high', 0.10), ('IV_fluids', 'ambient', 'high', 0.05), ('PPE_IPC_supplies', 'ambient', 'medium', 0.04), ('surgical_supplies', 'ambient', 'medium', 0.03), ('nutrition_commodities', 'ambient', 'medium', 0.03), ('medical_devices_consumables', 'ambient', 'low', 0.02), ('controlled_substances', 'secure_ambient', 'critical', 0.02), ] INVENTORY_ISSUES = [ 'stock_record_discrepancy', 'expired_stock', 'damaged_goods', 'theft_pilferage', 'pest_infestation', 'temperature_excursion', 'overstocking', 'understocking', 'FEFO_not_followed', 'receiving_error', 'dispatch_error', ] SCENARIOS = { 'national_central_medical_store': { 'warehouse_level': 'national_CMS', 'warehouse_size_sqm': 5000, 'has_WMS': True, 'has_temperature_monitoring': True, 'has_generator_backup': True, 'has_pest_control': True, 'has_security_system': True, 'staff_count': 40, 'inventory_accuracy_rate': 0.82, 'order_fulfilment_rate': 0.78, 'wastage_rate': 0.08, 'storage_conditions_adequate': 0.75, 'fefo_compliance': 0.70, 'stock_record_up_to_date': 0.80, 'capacity_utilisation': 0.85, }, 'regional_warehouse': { 'warehouse_level': 'regional_warehouse', 'warehouse_size_sqm': 1500, 'has_WMS': False, 'has_temperature_monitoring': False, 'has_generator_backup': False, 'has_pest_control': False, 'has_security_system': False, 'staff_count': 12, 'inventory_accuracy_rate': 0.55, 'order_fulfilment_rate': 0.52, 'wastage_rate': 0.18, 'storage_conditions_adequate': 0.42, 'fefo_compliance': 0.35, 'stock_record_up_to_date': 0.45, 'capacity_utilisation': 0.65, }, 'district_store': { 'warehouse_level': 'district_store', 'warehouse_size_sqm': 200, 'has_WMS': False, 'has_temperature_monitoring': False, 'has_generator_backup': False, 'has_pest_control': False, 'has_security_system': False, 'staff_count': 3, 'inventory_accuracy_rate': 0.28, 'order_fulfilment_rate': 0.30, 'wastage_rate': 0.30, 'storage_conditions_adequate': 0.15, 'fefo_compliance': 0.10, 'stock_record_up_to_date': 0.15, 'capacity_utilisation': 0.40, }, } def generate_dataset(n=10000, seed=42, scenario='regional_warehouse'): rng = np.random.default_rng(seed) sc = SCENARIOS[scenario] records = [] n_cat = len(COMMODITY_CATEGORIES) for idx in range(n): rec = {'id': idx + 1} rec['warehouse_level'] = sc['warehouse_level'] rec['warehouse_id'] = f"WH_{rng.integers(1, 100):04d}" rec['warehouse_size_sqm'] = max(20, int(rng.normal( sc['warehouse_size_sqm'], sc['warehouse_size_sqm'] * 0.3))) rec['region_type'] = rng.choice(['urban', 'peri_urban', 'rural'], p=[0.05, 0.15, 0.80] if scenario == 'district_store' else ([0.60, 0.25, 0.15] if scenario == 'national_central_medical_store' else [0.25, 0.40, 0.35])) rec['has_WMS'] = 1 if sc['has_WMS'] else (1 if rng.random() < 0.05 else 0) rec['has_temperature_monitoring'] = 1 if sc['has_temperature_monitoring'] else ( 1 if rng.random() < 0.08 else 0) rec['has_generator_backup'] = 1 if sc['has_generator_backup'] else ( 1 if rng.random() < 0.10 else 0) rec['has_pest_control'] = 1 if sc['has_pest_control'] else ( 1 if rng.random() < 0.08 else 0) rec['has_security_system'] = 1 if sc['has_security_system'] else ( 1 if rng.random() < 0.05 else 0) rec['staff_count'] = max(1, int(rng.poisson(sc['staff_count']))) rec['staff_trained_gdp'] = 1 if rng.random() < ( 0.70 if scenario == 'national_central_medical_store' else (0.25 if scenario == 'regional_warehouse' else 0.05)) else 0 cat_idx = idx % n_cat cat = COMMODITY_CATEGORIES[cat_idx] rec['commodity_category'] = cat[0] rec['storage_requirement'] = cat[1] rec['criticality'] = cat[2] rec['volume_share_pct'] = cat[3] * 100 rec['year'] = rng.choice([2021, 2022, 2023, 2024], p=[0.15, 0.25, 0.30, 0.30]) rec['month'] = rng.integers(1, 13) rec['storage_conditions_adequate'] = 1 if rng.random() < sc['storage_conditions_adequate'] else 0 if cat[1] in ('cold_chain_2_8C',) and not rec['has_temperature_monitoring']: rec['storage_conditions_adequate'] = 1 if rng.random() < 0.10 else 0 if cat[1] == 'secure_ambient' and not rec['has_security_system']: rec['storage_conditions_adequate'] = 1 if rng.random() < 0.15 else 0 rec['inventory_accuracy_pct'] = round(np.clip( rng.normal(sc['inventory_accuracy_rate'] * 100, 12), 10, 100), 1) rec['stock_record_up_to_date'] = 1 if rng.random() < sc['stock_record_up_to_date'] else 0 rec['fefo_compliance'] = 1 if rng.random() < sc['fefo_compliance'] else 0 rec['order_fulfilment_rate_pct'] = round(np.clip( rng.normal(sc['order_fulfilment_rate'] * 100, 15), 5, 100), 1) rec['orders_received_month'] = max(0, int(rng.poisson( 50 if scenario == 'national_central_medical_store' else (15 if scenario == 'regional_warehouse' else 5)))) rec['orders_fulfilled_complete'] = max(0, min(rec['orders_received_month'], int(rec['orders_received_month'] * rec['order_fulfilment_rate_pct'] / 100))) rec['orders_backordered'] = rec['orders_received_month'] - rec['orders_fulfilled_complete'] rec['wastage_rate_pct'] = round(np.clip( rng.normal(sc['wastage_rate'] * 100, 5), 0.5, 50), 1) rec['expired_stock_value_usd'] = max(0, round(rng.exponential( 5000 if scenario == 'national_central_medical_store' else (1000 if scenario == 'regional_warehouse' else 100)), 0)) rec['damaged_goods_value_usd'] = max(0, round(rng.exponential( 500 if scenario == 'national_central_medical_store' else (200 if scenario == 'regional_warehouse' else 30)), 0)) rec['capacity_utilisation_pct'] = round(np.clip( rng.normal(sc['capacity_utilisation'] * 100, 15), 5, 110), 1) rec['overflow_to_other_space'] = 1 if rec['capacity_utilisation_pct'] > 95 else 0 rec['temperature_excursion_month'] = 0 if cat[1] in ('cold_chain_2_8C',): rec['temperature_excursion_month'] = max(0, int(rng.poisson( 0.5 if scenario == 'national_central_medical_store' else (2 if scenario == 'regional_warehouse' else 5)))) rec['pest_damage_reported'] = 1 if rng.random() < ( 0.03 if scenario == 'national_central_medical_store' else (0.12 if scenario == 'regional_warehouse' else 0.25)) else 0 rec['theft_reported'] = 1 if rng.random() < ( 0.02 if scenario == 'national_central_medical_store' else (0.05 if scenario == 'regional_warehouse' else 0.10)) else 0 rec['inventory_issue'] = 'none' if rec['inventory_accuracy_pct'] < 80 or rec['wastage_rate_pct'] > 15: if scenario == 'district_store': issue_p = [0.15, 0.18, 0.08, 0.08, 0.05, 0.05, 0.08, 0.12, 0.10, 0.05, 0.06] elif scenario == 'regional_warehouse': issue_p = [0.15, 0.15, 0.08, 0.05, 0.08, 0.08, 0.10, 0.10, 0.08, 0.06, 0.07] else: issue_p = [0.12, 0.10, 0.08, 0.05, 0.05, 0.05, 0.15, 0.10, 0.10, 0.10, 0.10] rec['inventory_issue'] = rng.choice(INVENTORY_ISSUES, p=issue_p) rec['stockout_at_warehouse'] = 1 if rng.random() < ( 0.10 if scenario == 'national_central_medical_store' else (0.30 if scenario == 'regional_warehouse' else 0.55)) else 0 rec['facilities_affected_by_stockout'] = 0 if rec['stockout_at_warehouse']: rec['facilities_affected_by_stockout'] = max(0, int(rng.exponential( 20 if scenario == 'national_central_medical_store' else (8 if scenario == 'regional_warehouse' else 2)))) rec['report_submitted'] = 1 if rng.random() < ( 0.90 if scenario == 'national_central_medical_store' else (0.50 if scenario == 'regional_warehouse' else 0.15)) else 0 records.append(rec) df = pd.DataFrame(records) print(f"\n{'='*65}") print(f"Warehouse & Inventory — {scenario} (n={n}, seed={seed})") print(f"{'='*65}") print(f" Inventory accuracy: {df['inventory_accuracy_pct'].mean():.1f}%") print(f" Order fulfilment: {df['order_fulfilment_rate_pct'].mean():.1f}%") print(f" Wastage rate: {df['wastage_rate_pct'].mean():.1f}%") print(f" Storage adequate: {df['storage_conditions_adequate'].mean()*100:.1f}%") print(f" FEFO compliance: {df['fefo_compliance'].mean()*100:.1f}%") return df if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--all-scenarios', action='store_true') parser.add_argument('--n', type=int, default=10000) parser.add_argument('--seed', type=int, default=42) args = parser.parse_args() os.makedirs('data', exist_ok=True) if args.all_scenarios: for sc in SCENARIOS: df = generate_dataset(n=args.n, seed=args.seed, scenario=sc) df.to_csv(os.path.join('data', f'warehouse_{sc}.csv'), index=False) print(f" -> Saved\n") else: df = generate_dataset(n=args.n, seed=args.seed) df.to_csv(os.path.join('data', 'warehouse_regional_warehouse.csv'), index=False)