haileyhalimj@gmail.com
commited on
Commit
·
852cd18
1
Parent(s):
60e706b
✅ Add production speed check to product readiness validation
Browse files- Add speed_data to DemandFilter class initialization
- Load speed data in load_data() method alongside other required data
- Add production speed check to is_product_ready_for_optimization()
- Products without speed data are now excluded from optimization
- Remove redundant speed data loading and warning in filter_products()
- Speed check is now part of the core readiness criteria
- Prevents optimization errors from missing speed data
- Improves data validation feedback with 'Missing production speed data' reason
- src/demand_filtering.py +12 -16
src/demand_filtering.py
CHANGED
|
@@ -25,6 +25,7 @@ class DemandFilter:
|
|
| 25 |
self.kit_dependencies = None
|
| 26 |
self.line_assignments = None
|
| 27 |
self.team_requirements = None
|
|
|
|
| 28 |
|
| 29 |
def load_data(self, force_reload=False):
|
| 30 |
"""Load all necessary data for filtering"""
|
|
@@ -79,6 +80,10 @@ class DemandFilter:
|
|
| 79 |
'Humanizer': kits_df.set_index('Kit')['Humanizer'].to_dict()
|
| 80 |
}
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return True
|
| 83 |
|
| 84 |
except Exception as e:
|
|
@@ -123,6 +128,7 @@ class DemandFilter:
|
|
| 123 |
1) Should be right type - standalone master, subkit, prepack
|
| 124 |
2) Should have line assignment
|
| 125 |
3) Should have staffing requirements
|
|
|
|
| 126 |
|
| 127 |
Returns:
|
| 128 |
Tuple[bool, List[str]]: (is_ready, exclusion_reasons)
|
|
@@ -159,6 +165,10 @@ class DemandFilter:
|
|
| 159 |
if total_staff == 0:
|
| 160 |
exclusion_reasons.append("Zero staffing requirements")
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
is_ready = len(exclusion_reasons) == 0
|
| 163 |
return is_ready, exclusion_reasons
|
| 164 |
|
|
@@ -225,24 +235,10 @@ class DemandFilter:
|
|
| 225 |
for reason, count in reason_counts.items():
|
| 226 |
print(f" • {reason}: {count} products")
|
| 227 |
|
| 228 |
-
# Print data quality warnings for included products
|
| 229 |
-
# Load speed data for validation
|
| 230 |
-
speed_data = None
|
| 231 |
-
try:
|
| 232 |
-
from src.config import optimization_config
|
| 233 |
-
from src.preprocess import extract
|
| 234 |
-
speed_data = extract.read_package_speed_data()
|
| 235 |
-
except Exception as e:
|
| 236 |
-
print(f"Warning: Could not load speed data for validation: {e}")
|
| 237 |
-
|
| 238 |
-
if speed_data:
|
| 239 |
-
included_without_speed = sum(1 for pid in included_products if pid not in speed_data)
|
| 240 |
-
if included_without_speed > 0:
|
| 241 |
-
print(f"\n⚠️ DATA QUALITY WARNING: {included_without_speed} included products missing speed data")
|
| 242 |
-
|
| 243 |
included_without_hierarchy = sum(1 for pid in included_products if self.standalone_master_filter(pid)[0] == "unclassified")
|
| 244 |
if included_without_hierarchy > 0:
|
| 245 |
-
print(f"⚠️ DATA QUALITY WARNING: {included_without_hierarchy} included products missing hierarchy data")
|
| 246 |
|
| 247 |
return included_products, included_demand, excluded_products, excluded_demand
|
| 248 |
|
|
|
|
| 25 |
self.kit_dependencies = None
|
| 26 |
self.line_assignments = None
|
| 27 |
self.team_requirements = None
|
| 28 |
+
self.speed_data = None
|
| 29 |
|
| 30 |
def load_data(self, force_reload=False):
|
| 31 |
"""Load all necessary data for filtering"""
|
|
|
|
| 80 |
'Humanizer': kits_df.set_index('Kit')['Humanizer'].to_dict()
|
| 81 |
}
|
| 82 |
|
| 83 |
+
# Load production speed data
|
| 84 |
+
self.speed_data = extract.read_package_speed_data()
|
| 85 |
+
|
| 86 |
+
print(f"✅ Filtering data loaded: {len(self.demand_data)} products with demand, {len(self.speed_data)} with speed data")
|
| 87 |
return True
|
| 88 |
|
| 89 |
except Exception as e:
|
|
|
|
| 128 |
1) Should be right type - standalone master, subkit, prepack
|
| 129 |
2) Should have line assignment
|
| 130 |
3) Should have staffing requirements
|
| 131 |
+
4) Should have production speed data
|
| 132 |
|
| 133 |
Returns:
|
| 134 |
Tuple[bool, List[str]]: (is_ready, exclusion_reasons)
|
|
|
|
| 165 |
if total_staff == 0:
|
| 166 |
exclusion_reasons.append("Zero staffing requirements")
|
| 167 |
|
| 168 |
+
# Check production speed data
|
| 169 |
+
if self.speed_data is None or product_id not in self.speed_data:
|
| 170 |
+
exclusion_reasons.append("Missing production speed data")
|
| 171 |
+
|
| 172 |
is_ready = len(exclusion_reasons) == 0
|
| 173 |
return is_ready, exclusion_reasons
|
| 174 |
|
|
|
|
| 235 |
for reason, count in reason_counts.items():
|
| 236 |
print(f" • {reason}: {count} products")
|
| 237 |
|
| 238 |
+
# Print data quality warnings for included products
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
included_without_hierarchy = sum(1 for pid in included_products if self.standalone_master_filter(pid)[0] == "unclassified")
|
| 240 |
if included_without_hierarchy > 0:
|
| 241 |
+
print(f"\n⚠️ DATA QUALITY WARNING: {included_without_hierarchy} included products missing hierarchy data")
|
| 242 |
|
| 243 |
return included_products, included_demand, excluded_products, excluded_demand
|
| 244 |
|