haileyhalimj@gmail.com
commited on
Commit
·
d6dee1d
1
Parent(s):
9cb13fc
🔧 Fix import error: Replace singleton pattern with direct instantiation
Browse files- Remove redundant convenience functions from demand_filtering.py (34 lines removed)
- Fix optimization_config.py to use DemandFilter() directly instead of get_shared_filter_instance()
- Eliminate unnecessary singleton pattern - each call creates fresh instance
- Resolves import error: 'cannot import name get_shared_filter_instance'
- Simplify codebase while maintaining functionality
- File size reduced from 376 to 342 lines in demand_filtering.py
- src/config/optimization_config.py +4 -4
- src/demand_filtering.py +2 -35
src/config/optimization_config.py
CHANGED
|
@@ -75,8 +75,8 @@ def get_product_list():
|
|
| 75 |
"""
|
| 76 |
try:
|
| 77 |
# Always get fresh filtered products to reflect current configs
|
| 78 |
-
from src.demand_filtering import
|
| 79 |
-
filter_instance =
|
| 80 |
|
| 81 |
# Force reload data to pick up new dates/configs
|
| 82 |
filter_instance.load_data(force_reload=True)
|
|
@@ -260,8 +260,8 @@ def get_demand_dictionary(force_reload=False):
|
|
| 260 |
"""
|
| 261 |
try:
|
| 262 |
# Always get fresh filtered demand to reflect current configs
|
| 263 |
-
from src.demand_filtering import
|
| 264 |
-
filter_instance =
|
| 265 |
|
| 266 |
# Force reload data to pick up new dates/configs
|
| 267 |
filter_instance.load_data(force_reload=True)
|
|
|
|
| 75 |
"""
|
| 76 |
try:
|
| 77 |
# Always get fresh filtered products to reflect current configs
|
| 78 |
+
from src.demand_filtering import DemandFilter
|
| 79 |
+
filter_instance = DemandFilter()
|
| 80 |
|
| 81 |
# Force reload data to pick up new dates/configs
|
| 82 |
filter_instance.load_data(force_reload=True)
|
|
|
|
| 260 |
"""
|
| 261 |
try:
|
| 262 |
# Always get fresh filtered demand to reflect current configs
|
| 263 |
+
from src.demand_filtering import DemandFilter
|
| 264 |
+
filter_instance = DemandFilter()
|
| 265 |
|
| 266 |
# Force reload data to pick up new dates/configs
|
| 267 |
filter_instance.load_data(force_reload=True)
|
src/demand_filtering.py
CHANGED
|
@@ -226,7 +226,7 @@ class DemandFilter:
|
|
| 226 |
if speed_data:
|
| 227 |
included_without_speed = sum(1 for pid in included_products if pid not in speed_data)
|
| 228 |
if included_without_speed > 0:
|
| 229 |
-
print(f"\n⚠️ DATA QUALITY WARNING: {included_without_speed} included products missing speed data
|
| 230 |
|
| 231 |
included_without_hierarchy = sum(1 for pid in included_products if self.standalone_master_filter(pid)[0] == "unclassified")
|
| 232 |
if included_without_hierarchy > 0:
|
|
@@ -330,40 +330,7 @@ class DemandFilter:
|
|
| 330 |
}
|
| 331 |
|
| 332 |
|
| 333 |
-
#
|
| 334 |
-
def get_filtered_product_list() -> List[str]:
|
| 335 |
-
"""Get list of products ready for optimization"""
|
| 336 |
-
filter_instance = DemandFilter()
|
| 337 |
-
return filter_instance.get_filtered_product_list()
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
def get_filtered_demand_dictionary() -> Dict[str, int]:
|
| 341 |
-
"""Get demand dictionary for products ready for optimization"""
|
| 342 |
-
filter_instance = DemandFilter()
|
| 343 |
-
return filter_instance.get_filtered_demand_dictionary()
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
def get_exclusion_summary() -> Dict:
|
| 347 |
-
"""Get summary of excluded products for reporting"""
|
| 348 |
-
filter_instance = DemandFilter()
|
| 349 |
-
return filter_instance.get_exclusion_summary()
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
def get_complete_analysis() -> Dict:
|
| 353 |
-
"""Get complete product analysis including data quality metrics"""
|
| 354 |
-
filter_instance = DemandFilter()
|
| 355 |
-
return filter_instance.get_complete_product_analysis()
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
# Singleton instance for consistency across modules
|
| 359 |
-
_SHARED_FILTER_INSTANCE = None
|
| 360 |
-
|
| 361 |
-
def get_shared_filter_instance():
|
| 362 |
-
"""Returns a shared singleton instance of DemandFilter."""
|
| 363 |
-
global _SHARED_FILTER_INSTANCE
|
| 364 |
-
if _SHARED_FILTER_INSTANCE is None:
|
| 365 |
-
_SHARED_FILTER_INSTANCE = DemandFilter()
|
| 366 |
-
return _SHARED_FILTER_INSTANCE
|
| 367 |
|
| 368 |
if __name__ == "__main__":
|
| 369 |
# Test the filtering
|
|
|
|
| 226 |
if speed_data:
|
| 227 |
included_without_speed = sum(1 for pid in included_products if pid not in speed_data)
|
| 228 |
if included_without_speed > 0:
|
| 229 |
+
print(f"\n⚠️ DATA QUALITY WARNING: {included_without_speed} included products missing speed data")
|
| 230 |
|
| 231 |
included_without_hierarchy = sum(1 for pid in included_products if self.standalone_master_filter(pid)[0] == "unclassified")
|
| 232 |
if included_without_hierarchy > 0:
|
|
|
|
| 330 |
}
|
| 331 |
|
| 332 |
|
| 333 |
+
# Test script when run directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
if __name__ == "__main__":
|
| 336 |
# Test the filtering
|