Datasets:
Add dataset files
Browse files- README.md +77 -0
- data/sct_opaque_uncontrolled.csv +0 -0
- data/sct_partial_visibility.csv +0 -0
- data/sct_serialized_track_trace.csv +0 -0
- generate_dataset.py +195 -0
- requirements.txt +3 -0
- validate_dataset.py +106 -0
- validation_report.png +3 -0
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
- tabular-regression
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- healthcare
|
| 10 |
+
- medicine-quality
|
| 11 |
+
- supply-chain
|
| 12 |
+
- track-and-trace
|
| 13 |
+
- serialization
|
| 14 |
+
- diversion
|
| 15 |
+
- GS1
|
| 16 |
+
- pharmaceutical
|
| 17 |
+
- sub-saharan-africa
|
| 18 |
+
- lmic
|
| 19 |
+
pretty_name: "Supply Chain Integrity & Track-and-Trace (Serialization, Diversion, SF Entry)"
|
| 20 |
+
size_categories:
|
| 21 |
+
- 10K<n<100K
|
| 22 |
+
configs:
|
| 23 |
+
- config_name: serialized_track_trace
|
| 24 |
+
data_files: data/sct_serialized_track_trace.csv
|
| 25 |
+
- config_name: partial_visibility
|
| 26 |
+
data_files: data/sct_partial_visibility.csv
|
| 27 |
+
default: true
|
| 28 |
+
- config_name: opaque_uncontrolled
|
| 29 |
+
data_files: data/sct_opaque_uncontrolled.csv
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
# Supply Chain Integrity & Track-and-Trace Dataset
|
| 33 |
+
|
| 34 |
+
## Abstract
|
| 35 |
+
|
| 36 |
+
**30,000 simulated medicine shipment observations** (10,000 per scenario) across three supply chain visibility levels. Variables include serialization, authentication, temperature monitoring, GPS tracking, intermediary count, diversion, tampering, SF product entry, and recall. Three scenarios: serialized (90% serialized, 3% SF), partial visibility (16% serialized, 23% SF), opaque (1% serialized, 69% SF).
|
| 37 |
+
|
| 38 |
+
**This dataset is entirely simulated. It must not be used for supply chain or regulatory decisions.**
|
| 39 |
+
|
| 40 |
+
## Validation
|
| 41 |
+
|
| 42 |
+
<p align="center">
|
| 43 |
+
<img src="validation_report.png" alt="Validation Report" width="100%">
|
| 44 |
+
</p>
|
| 45 |
+
|
| 46 |
+
## Usage
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
from datasets import load_dataset
|
| 50 |
+
dataset = load_dataset("electricsheepafrica/supply-chain-track-trace", "partial_visibility")
|
| 51 |
+
df = dataset["train"].to_pandas()
|
| 52 |
+
print(df.groupby('serialized')['sf_product_detected'].mean())
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## References
|
| 56 |
+
|
| 57 |
+
1. WHO (2024). Complex supply chains and SF medicines.
|
| 58 |
+
2. GS1 Healthcare. Pharmaceutical serialization standards.
|
| 59 |
+
3. AU/AMRH. Track-and-trace pilots in Africa.
|
| 60 |
+
4. EU Falsified Medicines Directive.
|
| 61 |
+
5. USAID GHSC-PSM. Supply chain visibility tools.
|
| 62 |
+
|
| 63 |
+
## Citation
|
| 64 |
+
|
| 65 |
+
```bibtex
|
| 66 |
+
@dataset{esa_sct_2025,
|
| 67 |
+
title = {Supply Chain Integrity and Track-and-Trace Dataset},
|
| 68 |
+
author = {{Electric Sheep Africa}},
|
| 69 |
+
year = {2025},
|
| 70 |
+
publisher = {Hugging Face},
|
| 71 |
+
url = {https://huggingface.co/datasets/electricsheepafrica/supply-chain-track-trace}
|
| 72 |
+
}
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## License
|
| 76 |
+
|
| 77 |
+
[CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
|
data/sct_opaque_uncontrolled.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/sct_partial_visibility.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/sct_serialized_track_trace.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Literature-Informed Supply Chain Integrity & Track-and-Trace Dataset
|
| 4 |
+
=====================================================================
|
| 5 |
+
|
| 6 |
+
Each record = ONE medicine shipment/consignment assessed for integrity.
|
| 7 |
+
|
| 8 |
+
Sources (v2.0):
|
| 9 |
+
[1] WHO (2024). Complex supply chains with multiple intermediaries
|
| 10 |
+
increase risk of product tampering and substitution.
|
| 11 |
+
[2] GS1 Healthcare. Global standards for pharmaceutical serialization
|
| 12 |
+
and track-and-trace. GTIN, SSCC, 2D barcodes.
|
| 13 |
+
[3] African Union/AMRH. Track-and-trace pilots in East Africa,
|
| 14 |
+
Nigeria, Ghana. Mobile verification systems (mPedigree, Sproxil).
|
| 15 |
+
[4] EU Falsified Medicines Directive. End-to-end serialization model.
|
| 16 |
+
Only ~5 African countries have mandatory serialization.
|
| 17 |
+
[5] USAID GHSC-PSM. Supply chain visibility tools for donor-funded
|
| 18 |
+
medicines. Temperature monitoring, GPS tracking.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import numpy as np
|
| 22 |
+
import pandas as pd
|
| 23 |
+
import argparse
|
| 24 |
+
import os
|
| 25 |
+
|
| 26 |
+
SUPPLY_CHAIN_STAGES = [
|
| 27 |
+
'manufacturer', 'primary_wholesaler', 'regional_distributor',
|
| 28 |
+
'clearing_agent_port', 'central_medical_store', 'regional_store',
|
| 29 |
+
'district_store', 'health_facility', 'retail_pharmacy',
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
PRODUCT_TYPES = [
|
| 33 |
+
('essential_medicine', 'tablet', 0.35),
|
| 34 |
+
('antimalarial_ACT', 'tablet', 0.15),
|
| 35 |
+
('antibiotic', 'capsule', 0.12),
|
| 36 |
+
('ARV', 'tablet', 0.08),
|
| 37 |
+
('vaccine', 'vial', 0.08),
|
| 38 |
+
('injectable', 'ampoule', 0.07),
|
| 39 |
+
('oral_liquid', 'bottle', 0.05),
|
| 40 |
+
('controlled_substance', 'tablet', 0.03),
|
| 41 |
+
('medical_device', 'unit', 0.04),
|
| 42 |
+
('biological', 'vial', 0.03),
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
SCENARIOS = {
|
| 46 |
+
'serialized_track_trace': {
|
| 47 |
+
'system': 'full_serialization',
|
| 48 |
+
'serialization_coverage': 0.90,
|
| 49 |
+
'authentication_rate': 0.85,
|
| 50 |
+
'diversion_rate': 0.02,
|
| 51 |
+
'tampering_detected': 0.01,
|
| 52 |
+
'temperature_monitoring': 0.80,
|
| 53 |
+
'GPS_tracking': 0.70,
|
| 54 |
+
'sf_entry_rate': 0.03,
|
| 55 |
+
'transit_days_mean': 15,
|
| 56 |
+
'intermediary_count_mean': 3,
|
| 57 |
+
},
|
| 58 |
+
'partial_visibility': {
|
| 59 |
+
'system': 'partial_visibility',
|
| 60 |
+
'serialization_coverage': 0.15,
|
| 61 |
+
'authentication_rate': 0.20,
|
| 62 |
+
'diversion_rate': 0.08,
|
| 63 |
+
'tampering_detected': 0.04,
|
| 64 |
+
'temperature_monitoring': 0.25,
|
| 65 |
+
'GPS_tracking': 0.15,
|
| 66 |
+
'sf_entry_rate': 0.12,
|
| 67 |
+
'transit_days_mean': 30,
|
| 68 |
+
'intermediary_count_mean': 5,
|
| 69 |
+
},
|
| 70 |
+
'opaque_uncontrolled': {
|
| 71 |
+
'system': 'opaque',
|
| 72 |
+
'serialization_coverage': 0.01,
|
| 73 |
+
'authentication_rate': 0.02,
|
| 74 |
+
'diversion_rate': 0.20,
|
| 75 |
+
'tampering_detected': 0.10,
|
| 76 |
+
'temperature_monitoring': 0.03,
|
| 77 |
+
'GPS_tracking': 0.02,
|
| 78 |
+
'sf_entry_rate': 0.30,
|
| 79 |
+
'transit_days_mean': 60,
|
| 80 |
+
'intermediary_count_mean': 8,
|
| 81 |
+
},
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def generate_dataset(n=10000, seed=42, scenario='partial_visibility'):
|
| 86 |
+
rng = np.random.default_rng(seed)
|
| 87 |
+
sc = SCENARIOS[scenario]
|
| 88 |
+
records = []
|
| 89 |
+
n_prod = len(PRODUCT_TYPES)
|
| 90 |
+
|
| 91 |
+
for idx in range(n):
|
| 92 |
+
rec = {'id': idx + 1}
|
| 93 |
+
rec['system'] = sc['system']
|
| 94 |
+
rec['shipment_id'] = f"SCT_{rng.integers(1, 5000):05d}"
|
| 95 |
+
|
| 96 |
+
prod = PRODUCT_TYPES[rng.choice(n_prod, p=[p[2] for p in PRODUCT_TYPES])]
|
| 97 |
+
rec['product_type'] = prod[0]
|
| 98 |
+
rec['dosage_form'] = prod[1]
|
| 99 |
+
|
| 100 |
+
rec['origin_country'] = rng.choice(
|
| 101 |
+
['India', 'China', 'Europe', 'local_SSA', 'USA', 'South_Africa'],
|
| 102 |
+
p=[0.40, 0.18, 0.10, 0.12, 0.05, 0.15])
|
| 103 |
+
rec['destination_country'] = rng.choice(
|
| 104 |
+
['Nigeria', 'Kenya', 'Tanzania', 'Ghana', 'Ethiopia',
|
| 105 |
+
'DRC', 'Uganda', 'Cameroon', 'Senegal', 'Mozambique'],
|
| 106 |
+
p=[0.15, 0.12, 0.10, 0.10, 0.10, 0.08, 0.08, 0.08, 0.10, 0.09])
|
| 107 |
+
|
| 108 |
+
rec['intermediary_count'] = max(1, int(rng.poisson(sc['intermediary_count_mean'])))
|
| 109 |
+
rec['transit_days'] = max(1, int(rng.exponential(sc['transit_days_mean'] * 0.6)))
|
| 110 |
+
rec['storage_handoffs'] = max(1, min(rec['intermediary_count'], int(rng.poisson(3))))
|
| 111 |
+
|
| 112 |
+
rec['serialized'] = 1 if rng.random() < sc['serialization_coverage'] else 0
|
| 113 |
+
rec['barcode_2D'] = 1 if rec['serialized'] and rng.random() < 0.85 else 0
|
| 114 |
+
rec['GTIN_assigned'] = 1 if rec['serialized'] else (1 if rng.random() < 0.10 else 0)
|
| 115 |
+
rec['authentication_scanned'] = 1 if rng.random() < sc['authentication_rate'] else 0
|
| 116 |
+
rec['mobile_verification_used'] = 1 if rng.random() < (
|
| 117 |
+
sc['authentication_rate'] * 0.5) else 0
|
| 118 |
+
|
| 119 |
+
rec['temperature_monitored'] = 1 if rng.random() < sc['temperature_monitoring'] else 0
|
| 120 |
+
rec['temperature_excursion'] = 0
|
| 121 |
+
if not rec['temperature_monitored'] or rng.random() < (0.05 if scenario == 'serialized_track_trace' else (0.15 if scenario == 'partial_visibility' else 0.40)):
|
| 122 |
+
rec['temperature_excursion'] = 1 if rng.random() < 0.30 else 0
|
| 123 |
+
rec['GPS_tracked'] = 1 if rng.random() < sc['GPS_tracking'] else 0
|
| 124 |
+
|
| 125 |
+
rec['customs_cleared'] = 1 if rng.random() < (0.98 if scenario == 'serialized_track_trace' else (0.85 if scenario == 'partial_visibility' else 0.60)) else 0
|
| 126 |
+
rec['import_permit_valid'] = 1 if rng.random() < (0.95 if scenario == 'serialized_track_trace' else (0.70 if scenario == 'partial_visibility' else 0.30)) else 0
|
| 127 |
+
rec['WHO_prequalified_product'] = 1 if rng.random() < (0.55 if scenario == 'serialized_track_trace' else (0.25 if scenario == 'partial_visibility' else 0.05)) else 0
|
| 128 |
+
|
| 129 |
+
# Integrity issues
|
| 130 |
+
rec['diversion_detected'] = 1 if rng.random() < sc['diversion_rate'] else 0
|
| 131 |
+
rec['tampering_evidence'] = 1 if rng.random() < sc['tampering_detected'] else 0
|
| 132 |
+
rec['packaging_breach'] = 1 if rng.random() < (sc['tampering_detected'] * 1.5) else 0
|
| 133 |
+
|
| 134 |
+
# SF entry into supply chain
|
| 135 |
+
base_sf = sc['sf_entry_rate']
|
| 136 |
+
if not rec['serialized']:
|
| 137 |
+
base_sf *= 1.5
|
| 138 |
+
if rec['intermediary_count'] > 5:
|
| 139 |
+
base_sf *= 1.3
|
| 140 |
+
if not rec['customs_cleared']:
|
| 141 |
+
base_sf *= 2.0
|
| 142 |
+
if rec['diversion_detected']:
|
| 143 |
+
base_sf *= 2.0
|
| 144 |
+
base_sf = np.clip(base_sf, 0.005, 0.80)
|
| 145 |
+
|
| 146 |
+
rec['sf_product_detected'] = 1 if rng.random() < base_sf else 0
|
| 147 |
+
rec['sf_entry_point'] = 'none'
|
| 148 |
+
if rec['sf_product_detected']:
|
| 149 |
+
rec['sf_entry_point'] = rng.choice(
|
| 150 |
+
['manufacturer_level', 'wholesaler', 'port_customs',
|
| 151 |
+
'regional_distribution', 'last_mile', 'retail'],
|
| 152 |
+
p=[0.15, 0.20, 0.15, 0.20, 0.15, 0.15])
|
| 153 |
+
|
| 154 |
+
rec['recall_initiated'] = 0
|
| 155 |
+
if rec['sf_product_detected'] and rng.random() < (
|
| 156 |
+
0.60 if scenario == 'serialized_track_trace' else
|
| 157 |
+
(0.15 if scenario == 'partial_visibility' else 0.02)):
|
| 158 |
+
rec['recall_initiated'] = 1
|
| 159 |
+
|
| 160 |
+
rec['batch_quantity'] = max(100, int(rng.lognormal(8, 1)))
|
| 161 |
+
rec['value_usd'] = round(rec['batch_quantity'] * max(0.01, rng.lognormal(
|
| 162 |
+
np.log(0.50), 0.8)), 2)
|
| 163 |
+
|
| 164 |
+
rec['year'] = rng.choice([2020, 2021, 2022, 2023, 2024],
|
| 165 |
+
p=[0.10, 0.15, 0.20, 0.25, 0.30])
|
| 166 |
+
|
| 167 |
+
records.append(rec)
|
| 168 |
+
|
| 169 |
+
df = pd.DataFrame(records)
|
| 170 |
+
print(f"\n{'='*65}")
|
| 171 |
+
print(f"Supply Chain — {scenario} (n={n}, seed={seed})")
|
| 172 |
+
print(f"{'='*65}")
|
| 173 |
+
print(f" System: {sc['system']}")
|
| 174 |
+
print(f" Serialized: {df['serialized'].mean()*100:.1f}%")
|
| 175 |
+
print(f" SF detected: {df['sf_product_detected'].mean()*100:.1f}%")
|
| 176 |
+
print(f" Diversion: {df['diversion_detected'].mean()*100:.1f}%")
|
| 177 |
+
print(f" Avg intermediaries: {df['intermediary_count'].mean():.1f}")
|
| 178 |
+
return df
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
if __name__ == '__main__':
|
| 182 |
+
parser = argparse.ArgumentParser()
|
| 183 |
+
parser.add_argument('--all-scenarios', action='store_true')
|
| 184 |
+
parser.add_argument('--n', type=int, default=10000)
|
| 185 |
+
parser.add_argument('--seed', type=int, default=42)
|
| 186 |
+
args = parser.parse_args()
|
| 187 |
+
os.makedirs('data', exist_ok=True)
|
| 188 |
+
if args.all_scenarios:
|
| 189 |
+
for sc in SCENARIOS:
|
| 190 |
+
df = generate_dataset(n=args.n, seed=args.seed, scenario=sc)
|
| 191 |
+
df.to_csv(os.path.join('data', f'sct_{sc}.csv'), index=False)
|
| 192 |
+
print(f" -> Saved\n")
|
| 193 |
+
else:
|
| 194 |
+
df = generate_dataset(n=args.n, seed=args.seed)
|
| 195 |
+
df.to_csv(os.path.join('data', 'sct_partial_visibility.csv'), index=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.24
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
matplotlib>=3.7
|
validate_dataset.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Validation & Diagnostic Visualization for Supply Chain Integrity & Track-and-Trace Dataset."""
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
SCENARIOS = ['serialized_track_trace', 'partial_visibility', 'opaque_uncontrolled']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def load_scenarios(data_dir='data'):
|
| 13 |
+
dfs = {}
|
| 14 |
+
for sc in SCENARIOS:
|
| 15 |
+
path = os.path.join(data_dir, f'sct_{sc}.csv')
|
| 16 |
+
if os.path.exists(path):
|
| 17 |
+
dfs[sc] = pd.read_csv(path)
|
| 18 |
+
return dfs
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def make_report(dfs, output='validation_report.png'):
|
| 22 |
+
fig, axes = plt.subplots(4, 2, figsize=(16, 24))
|
| 23 |
+
fig.suptitle(
|
| 24 |
+
'Supply Chain Integrity & Track-and-Trace — Validation Report\n'
|
| 25 |
+
'(Serialized → Partial Visibility → Opaque)',
|
| 26 |
+
fontsize=15, fontweight='bold', y=0.99)
|
| 27 |
+
colors = ['#2ecc71', '#f39c12', '#e74c3c']
|
| 28 |
+
x = np.arange(len(SCENARIOS))
|
| 29 |
+
labels = ['Serialized', 'Partial', 'Opaque']
|
| 30 |
+
|
| 31 |
+
ax = axes[0, 0]
|
| 32 |
+
sf = [dfs[sc]['sf_product_detected'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 33 |
+
ax.bar(x, sf, color=colors, alpha=0.8)
|
| 34 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 35 |
+
for i, v in enumerate(sf):
|
| 36 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 37 |
+
ax.set_ylabel('SF Rate (%)'); ax.set_title('SF Product Detection Rate')
|
| 38 |
+
|
| 39 |
+
ax = axes[0, 1]
|
| 40 |
+
ser = [dfs[sc]['serialized'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 41 |
+
ax.bar(x, ser, color=colors, alpha=0.8)
|
| 42 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 43 |
+
for i, v in enumerate(ser):
|
| 44 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 45 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Serialization Coverage')
|
| 46 |
+
|
| 47 |
+
ax = axes[1, 0]
|
| 48 |
+
div = [dfs[sc]['diversion_detected'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 49 |
+
ax.bar(x, div, color=colors, alpha=0.8)
|
| 50 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 51 |
+
for i, v in enumerate(div):
|
| 52 |
+
ax.text(i, v+0.3, f'{v:.1f}%', ha='center', fontsize=10, fontweight='bold')
|
| 53 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Diversion Detected')
|
| 54 |
+
|
| 55 |
+
ax = axes[1, 1]
|
| 56 |
+
interm = [dfs[sc]['intermediary_count'].mean() for sc in SCENARIOS if sc in dfs]
|
| 57 |
+
ax.bar(x, interm, color=colors, alpha=0.8)
|
| 58 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 59 |
+
for i, v in enumerate(interm):
|
| 60 |
+
ax.text(i, v+0.1, f'{v:.1f}', ha='center', fontsize=10, fontweight='bold')
|
| 61 |
+
ax.set_ylabel('Count'); ax.set_title('Average Intermediaries')
|
| 62 |
+
|
| 63 |
+
ax = axes[2, 0]
|
| 64 |
+
df = dfs.get('partial_visibility', list(dfs.values())[1])
|
| 65 |
+
ep = df[df['sf_product_detected']==1]['sf_entry_point'].value_counts()
|
| 66 |
+
if len(ep) > 0:
|
| 67 |
+
ax.barh(range(len(ep)), ep.values, color='#e74c3c', alpha=0.7)
|
| 68 |
+
ax.set_yticks(range(len(ep)))
|
| 69 |
+
ax.set_yticklabels([s.replace('_', ' ').title() for s in ep.index], fontsize=7)
|
| 70 |
+
ax.set_xlabel('Count')
|
| 71 |
+
ax.set_title('SF Entry Points (Partial Visibility)')
|
| 72 |
+
|
| 73 |
+
ax = axes[2, 1]
|
| 74 |
+
temp = [dfs[sc]['temperature_monitored'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 75 |
+
ax.bar(x, temp, color=colors, alpha=0.8)
|
| 76 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 77 |
+
for i, v in enumerate(temp):
|
| 78 |
+
ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
|
| 79 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Temperature Monitoring')
|
| 80 |
+
|
| 81 |
+
ax = axes[3, 0]
|
| 82 |
+
transit = [dfs[sc]['transit_days'].median() for sc in SCENARIOS if sc in dfs]
|
| 83 |
+
ax.bar(x, transit, color=colors, alpha=0.8)
|
| 84 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 85 |
+
for i, v in enumerate(transit):
|
| 86 |
+
ax.text(i, v+0.5, f'{v:.0f}d', ha='center', fontsize=10, fontweight='bold')
|
| 87 |
+
ax.set_ylabel('Days'); ax.set_title('Median Transit Days')
|
| 88 |
+
|
| 89 |
+
ax = axes[3, 1]
|
| 90 |
+
recall = [dfs[sc]['recall_initiated'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 91 |
+
ax.bar(x, recall, color=colors, alpha=0.8)
|
| 92 |
+
ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
|
| 93 |
+
for i, v in enumerate(recall):
|
| 94 |
+
ax.text(i, v+0.2, f'{v:.1f}%', ha='center', fontsize=10, fontweight='bold')
|
| 95 |
+
ax.set_ylabel('Rate (%)'); ax.set_title('Recall Initiated')
|
| 96 |
+
|
| 97 |
+
plt.tight_layout(rect=[0, 0, 1, 0.97])
|
| 98 |
+
plt.savefig(output, dpi=150, bbox_inches='tight')
|
| 99 |
+
print(f'Saved validation report to {output}')
|
| 100 |
+
plt.close()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == '__main__':
|
| 104 |
+
dfs = load_scenarios()
|
| 105 |
+
if dfs:
|
| 106 |
+
make_report(dfs)
|
validation_report.png
ADDED
|
Git LFS Details
|