haileyhalimj@gmail.com commited on
Commit
cff99be
ยท
1 Parent(s): 06404f5

Delete codes no longer used

Browse files
src/config/constants.py CHANGED
@@ -135,6 +135,9 @@ class DefaultConfig:
135
  LineType.MINI_LOAD: 15
136
  }
137
 
 
 
 
138
  # Default cost rates (example values)
139
  DEFAULT_COST_RATES = {
140
  "UNICEF Fixed term": {
 
135
  LineType.MINI_LOAD: 15
136
  }
137
 
138
+ # Default minimum UNICEF fixed-term employees per day
139
+ FIXED_MIN_UNICEF_PER_DAY = 2
140
+
141
  # Default cost rates (example values)
142
  DEFAULT_COST_RATES = {
143
  "UNICEF Fixed term": {
src/config/optimization_config.py CHANGED
@@ -269,21 +269,9 @@ def get_team_requirements(product_list=None):
269
  if product_list is None:
270
  product_list = get_product_list() # Get fresh product list
271
 
272
- try:
273
- # Check if streamlit has this data (for future extension)
274
- # streamlit_team_req = dashboard.team_requirements
275
- # return streamlit_team_req
276
- pass
277
- except Exception as e:
278
- print(f"Using default value for team requirements, extracting from CSV: {e}")
279
-
280
- # Read the kits calculation data directly
281
  kits_df = extract.read_personnel_requirement_data()
282
- # kits_path = "data/real_data_excel/converted_csv/Kits__Calculation.csv"
283
- # kits_df = pd.read_csv(kits_path)
284
- print("kits_df columns:", kits_df.columns.tolist())
285
- print("kits_df head:", kits_df.head())
286
- # Initialize the team requirements dictionary
287
  team_req_dict = {
288
  "UNICEF Fixed term": {},
289
  "Humanizer": {}
@@ -309,8 +297,6 @@ def get_team_requirements(product_list=None):
309
 
310
  return team_req_dict
311
 
312
- # DO NOT load at import time - always call get_team_requirements() dynamically
313
- # TEAM_REQ_PER_PRODUCT = get_team_requirements(PRODUCT_LIST) # REMOVED - was causing stale data!
314
 
315
 
316
  def get_max_employee_per_type_on_day():
@@ -334,10 +320,7 @@ def get_max_employee_per_type_on_day():
334
  }
335
  return max_employee_per_type_on_day
336
 
337
- # DO NOT load at import time - always call get_max_employee_per_type_on_day() dynamically
338
- # MAX_EMPLOYEE_PER_TYPE_ON_DAY = get_max_employee_per_type_on_day() # REMOVED - was causing stale data!
339
 
340
- # available employee but for fixed in shift 1, it is mandatory employment
341
 
342
  MAX_HOUR_PER_PERSON_PER_DAY = 14 # legal standard
343
  def get_max_hour_per_shift_per_person():
@@ -352,15 +335,7 @@ def get_max_hour_per_shift_per_person():
352
  # Fallback to default only if not configured by user
353
  return DefaultConfig.MAX_HOUR_PER_SHIFT_PER_PERSON
354
 
355
- # DO NOT load at import time - always call get_max_hour_per_shift_per_person() dynamically
356
- # MAX_HOUR_PER_SHIFT_PER_PERSON = get_max_hour_per_shift_per_person() # REMOVED - was causing stale data!
357
 
358
- # Removed unnecessary getter functions - use direct imports instead:
359
- # - MAX_HOUR_PER_PERSON_PER_DAY
360
- # - MAX_HOUR_PER_SHIFT_PER_PERSON
361
- # - KIT_LINE_MATCH_DICT
362
- # - MAX_PARALLEL_WORKERS
363
- # - EVENING_SHIFT_MODE
364
 
365
  # Keep these complex getters that access DefaultConfig or have complex logic:
366
  def get_evening_shift_demand_threshold():
@@ -388,48 +363,9 @@ def get_fixed_min_unicef_per_day():
388
  return getattr(DefaultConfig, 'FIXED_MIN_UNICEF_PER_DAY', {1: 1, 2: 1, 3: 1, 4: 1, 5: 1})
389
 
390
 
391
- # ============================================================================
392
- # BETTER APPROACH: Explicit module-level variables with clear documentation
393
- # These variables provide backward compatibility while being explicit and clear
394
- # ============================================================================
395
-
396
- def _ensure_fresh_config():
397
- """
398
- Helper function to refresh module-level variables when configuration changes.
399
- Call this after updating Streamlit session state to ensure fresh values.
400
- """
401
- global PER_PRODUCT_SPEED, LINE_LIST, EMPLOYEE_TYPE_LIST, SHIFT_LIST
402
- global LINE_CNT_PER_TYPE, COST_LIST_PER_EMP_SHIFT, MAX_EMPLOYEE_PER_TYPE_ON_DAY
403
- global MAX_HOUR_PER_SHIFT_PER_PERSON, MAX_PARALLEL_WORKERS, FIXED_MIN_UNICEF_PER_DAY
404
- global PAYMENT_MODE_CONFIG
405
-
406
- # Refresh all cached values
407
- PER_PRODUCT_SPEED = extract.read_package_speed_data()
408
- LINE_LIST = get_line_list()
409
- EMPLOYEE_TYPE_LIST = get_employee_type_list()
410
- SHIFT_LIST = get_active_shift_list()
411
- LINE_CNT_PER_TYPE = get_line_cnt_per_type()
412
- COST_LIST_PER_EMP_SHIFT = get_cost_list_per_emp_shift()
413
- MAX_EMPLOYEE_PER_TYPE_ON_DAY = get_max_employee_per_type_on_day()
414
- MAX_HOUR_PER_SHIFT_PER_PERSON = get_max_hour_per_shift_per_person()
415
- MAX_PARALLEL_WORKERS = get_max_parallel_workers()
416
- FIXED_MIN_UNICEF_PER_DAY = get_fixed_min_unicef_per_day()
417
- PAYMENT_MODE_CONFIG = get_payment_mode_config()
418
-
419
- # Note: Module-level variables will be initialized at the end of this file
420
- # after all functions are defined. This ensures all getter functions are available.
421
 
422
  # ---- Kit Hierarchy for Production Ordering ----
423
  def get_kit_hierarchy_data():
424
- try:
425
- # Try to get from streamlit first (future extension)
426
- # streamlit_hierarchy = dashboard.kit_hierarchy_data
427
- # return streamlit_hierarchy
428
- pass
429
- except Exception as e:
430
- print(f"Using default hierarchy data from extract: {e}")
431
-
432
- # Get hierarchy data from extract functions
433
  kit_levels, dependencies, priority_order = extract.get_production_order_data()
434
 
435
  return kit_levels, dependencies, priority_order
@@ -437,6 +373,21 @@ def get_kit_hierarchy_data():
437
  KIT_LEVELS, KIT_DEPENDENCIES, PRODUCTION_PRIORITY_ORDER = get_kit_hierarchy_data()
438
  print(f"Kit Hierarchy loaded: {len(KIT_LEVELS)} kits, Priority order: {len(PRODUCTION_PRIORITY_ORDER)} items")
439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
440
  def get_max_parallel_workers():
441
  """Get max parallel workers - checks Streamlit session state first"""
442
  try:
@@ -449,19 +400,8 @@ def get_max_parallel_workers():
449
  # Fallback to default only if not configured by user
450
  return DefaultConfig.MAX_PARALLEL_WORKERS
451
 
452
- # DO NOT load at import time - always call get_max_parallel_workers() dynamically
453
- # MAX_PARALLEL_WORKERS = get_max_parallel_workers() # REMOVED - was causing stale data!
454
- # maximum number of workers that can work on a line at the same time
455
 
456
 
457
- # Fixed staff constraint mode
458
- # Options:
459
- # "mandatory" - Forces all fixed staff to work full hours every day (expensive, 99.7% waste)
460
- # "available" - Staff available up to limits but not forced (balanced approach)
461
- # "priority" - Fixed staff used first, then temporary staff (realistic business model)
462
- # "none" - Purely demand-driven scheduling (cost-efficient)
463
- FIXED_STAFF_CONSTRAINT_MODE = "priority" # Recommended: "priority" for realistic business model
464
-
465
  def get_fixed_min_unicef_per_day():
466
  """
467
  Get fixed minimum UNICEF employees per day - try from streamlit session state first, then default
@@ -473,14 +413,10 @@ def get_fixed_min_unicef_per_day():
473
  print(f"Using fixed minimum UNICEF per day from config page: {st.session_state.fixed_min_unicef_per_day}")
474
  return st.session_state.fixed_min_unicef_per_day
475
  except ImportError:
476
- pass # Streamlit not available in CLI mode
477
 
478
- # Default value - minimum UNICEF Fixed term employees required per day
479
- return 2
480
-
481
- # Set the constant for backward compatibility
482
- # DO NOT load at import time - always call get_fixed_min_unicef_per_day() dynamically
483
- # FIXED_MIN_UNICEF_PER_DAY = get_fixed_min_unicef_per_day() # REMOVED - was causing stale data!
484
 
485
 
486
  def get_payment_mode_config():
@@ -505,36 +441,5 @@ def get_payment_mode_config():
505
 
506
  return payment_mode_config
507
 
508
- # DO NOT load at import time - always call get_payment_mode_config() dynamically
509
-
510
- # ============================================================================
511
- # INITIALIZE MODULE-LEVEL VARIABLES
512
- # This section is at the end to ensure all functions are defined first
513
- # ============================================================================
514
-
515
- # DISABLED: Module-level initialization was causing infinite loops in Hugging Face deployment
516
- # The functions are called dynamically when needed instead of at import time
517
- # This prevents the infinite loop where importing this module triggers Streamlit session access
518
- # which causes the app to reload, which imports this module again, etc.
519
-
520
- # Initialize with default values (will use fallback data when no Streamlit session)
521
- # PER_PRODUCT_SPEED = extract.read_package_speed_data()
522
- # LINE_LIST = get_line_list()
523
- # EMPLOYEE_TYPE_LIST = get_employee_type_list()
524
- # SHIFT_LIST = get_active_shift_list()
525
- # LINE_CNT_PER_TYPE = get_line_cnt_per_type()
526
- # COST_LIST_PER_EMP_SHIFT = get_cost_list_per_emp_shift()
527
- # MAX_EMPLOYEE_PER_TYPE_ON_DAY = get_max_employee_per_type_on_day()
528
- # MAX_HOUR_PER_SHIFT_PER_PERSON = get_max_hour_per_shift_per_person()
529
- # MAX_PARALLEL_WORKERS = get_max_parallel_workers()
530
- # FIXED_MIN_UNICEF_PER_DAY = get_fixed_min_unicef_per_day()
531
- # PAYMENT_MODE_CONFIG = get_payment_mode_config()
532
 
533
  print("โœ… Module-level configuration functions defined (variables initialized dynamically)")
534
-
535
- # Note: These variables are initialized once at import time with default/fallback values.
536
- # To get fresh values after changing Streamlit configuration, either:
537
- # 1. Call the get_*() functions directly (RECOMMENDED for dynamic use)
538
- # 2. Call _ensure_fresh_config() to refresh all module-level variables
539
- # 3. Use importlib.reload() to reload the entire module
540
-
 
269
  if product_list is None:
270
  product_list = get_product_list() # Get fresh product list
271
 
272
+
 
 
 
 
 
 
 
 
273
  kits_df = extract.read_personnel_requirement_data()
274
+
 
 
 
 
275
  team_req_dict = {
276
  "UNICEF Fixed term": {},
277
  "Humanizer": {}
 
297
 
298
  return team_req_dict
299
 
 
 
300
 
301
 
302
  def get_max_employee_per_type_on_day():
 
320
  }
321
  return max_employee_per_type_on_day
322
 
 
 
323
 
 
324
 
325
  MAX_HOUR_PER_PERSON_PER_DAY = 14 # legal standard
326
  def get_max_hour_per_shift_per_person():
 
335
  # Fallback to default only if not configured by user
336
  return DefaultConfig.MAX_HOUR_PER_SHIFT_PER_PERSON
337
 
 
 
338
 
 
 
 
 
 
 
339
 
340
  # Keep these complex getters that access DefaultConfig or have complex logic:
341
  def get_evening_shift_demand_threshold():
 
363
  return getattr(DefaultConfig, 'FIXED_MIN_UNICEF_PER_DAY', {1: 1, 2: 1, 3: 1, 4: 1, 5: 1})
364
 
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
  # ---- Kit Hierarchy for Production Ordering ----
368
  def get_kit_hierarchy_data():
 
 
 
 
 
 
 
 
 
369
  kit_levels, dependencies, priority_order = extract.get_production_order_data()
370
 
371
  return kit_levels, dependencies, priority_order
 
373
  KIT_LEVELS, KIT_DEPENDENCIES, PRODUCTION_PRIORITY_ORDER = get_kit_hierarchy_data()
374
  print(f"Kit Hierarchy loaded: {len(KIT_LEVELS)} kits, Priority order: {len(PRODUCTION_PRIORITY_ORDER)} items")
375
 
376
+ def get_kit_levels():
377
+ """Get kit levels lazily - returns {kit_id: level} where 0=prepack, 1=subkit, 2=master"""
378
+ kit_levels, _, _ = get_kit_hierarchy_data()
379
+ return kit_levels
380
+
381
+ def get_kit_dependencies():
382
+ """Get kit dependencies lazily - returns {kit_id: [dependency_list]}"""
383
+ _, dependencies, _ = get_kit_hierarchy_data()
384
+ return dependencies
385
+
386
+ def get_production_priority_order():
387
+ """Get production priority order lazily - returns [kit_ids] sorted by production priority"""
388
+ _, _, priority_order = get_kit_hierarchy_data()
389
+ return priority_order
390
+
391
  def get_max_parallel_workers():
392
  """Get max parallel workers - checks Streamlit session state first"""
393
  try:
 
400
  # Fallback to default only if not configured by user
401
  return DefaultConfig.MAX_PARALLEL_WORKERS
402
 
 
 
 
403
 
404
 
 
 
 
 
 
 
 
 
405
  def get_fixed_min_unicef_per_day():
406
  """
407
  Get fixed minimum UNICEF employees per day - try from streamlit session state first, then default
 
413
  print(f"Using fixed minimum UNICEF per day from config page: {st.session_state.fixed_min_unicef_per_day}")
414
  return st.session_state.fixed_min_unicef_per_day
415
  except ImportError:
416
+ pass
417
 
418
+ # Fallback to default configuration
419
+ return DefaultConfig.FIXED_MIN_UNICEF_PER_DAY
 
 
 
 
420
 
421
 
422
  def get_payment_mode_config():
 
441
 
442
  return payment_mode_config
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
 
445
  print("โœ… Module-level configuration functions defined (variables initialized dynamically)")
 
 
 
 
 
 
 
src/models/optimizer_real_import_fix.txt DELETED
@@ -1,34 +0,0 @@
1
- # ---- config import (ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ์— ๋งž์ถฐ ์กฐ์ •) ----
2
- from src.config.optimization_config import (
3
- get_date_span, # DYNAMIC: Get date span dynamically
4
- get_product_list, # DYNAMIC: list of products (e.g., ['A','B',...])
5
- get_employee_type_list, # DYNAMIC: e.g., ['UNICEF Fixed term','Humanizer']
6
- get_active_shift_list, # DYNAMIC: e.g., [1,2,3]
7
- get_line_list, # DYNAMIC: e.g., [6,7] (line type ids)
8
- get_line_cnt_per_type, # DYNAMIC: {6: count_of_long_lines, 7: count_of_short_lines}
9
- get_demand_dictionary, # DYNAMIC: {product: total_units_over_period}
10
- get_cost_list_per_emp_shift, # DYNAMIC: {emp_type: {shift: cost_per_hour}}
11
- get_max_employee_per_type_on_day, # DYNAMIC: {emp_type: {t: headcount}}
12
- MAX_HOUR_PER_PERSON_PER_DAY, # e.g., 14
13
- get_max_hour_per_shift_per_person, # DYNAMIC: {1: hours, 2: hours, 3: hours}
14
- get_max_parallel_workers, # DYNAMIC: {6: max_workers, 7: max_workers}
15
- FIXED_STAFF_CONSTRAINT_MODE, # not used in fixed-team model (๋™์‹œ ํˆฌ์ž…์ด๋ผ ๋ฌด์˜๋ฏธ)
16
- get_team_requirements, # DYNAMIC: {emp_type: {product: team_size}} from Kits_Calculation.csv
17
- get_payment_mode_config, # DYNAMIC: {shift: 'bulk'/'partial'} payment mode configuration
18
- get_kit_line_match, # DYNAMIC: Get kit line match lazily
19
- EVENING_SHIFT_MODE,
20
- EVENING_SHIFT_DEMAND_THRESHOLD,
21
- # Hierarchy variables for production ordering - now using getter functions
22
- get_kit_levels, # DYNAMIC: {kit_id: level} where 0=prepack, 1=subkit, 2=master
23
- get_kit_dependencies, # DYNAMIC: {kit_id: [dependency_list]}
24
- get_production_priority_order, # DYNAMIC: [kit_ids] sorted by production priority
25
- # Fixed staffing requirements
26
- get_fixed_min_unicef_per_day, # DYNAMIC: Minimum UNICEF employees required per day
27
- )
28
-
29
-
30
-
31
- # 2) kit_line_match - lazy load on first use
32
- KIT_LINE_MATCH_DICT = get_kit_line_match()
33
-
34
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ui/pages/optimization_results.py CHANGED
@@ -107,7 +107,7 @@ def display_weekly_summary(results):
107
  # Production vs Demand Chart
108
  st.subheader("๐ŸŽฏ Production vs Demand")
109
 
110
- from config.optimization_config import get_demand_dictionary
111
  DEMAND_DICTIONARY = get_demand_dictionary()
112
  prod_demand_data = []
113
  for product, production in results['weekly_production'].items():
@@ -556,7 +556,7 @@ def display_cost_analysis(results):
556
  line_name = line_names.get(row['line_type_id'], f"Line {row['line_type_id']}")
557
 
558
  # Calculate costs for this production run (accounting for payment mode)
559
- from config.optimization_config import get_payment_mode_config, get_max_hour_per_shift_per_person
560
  PAYMENT_MODE_CONFIG = get_payment_mode_config() # Dynamic call
561
  MAX_HOUR_PER_SHIFT_PER_PERSON = get_max_hour_per_shift_per_person() # Dynamic call
562
 
 
107
  # Production vs Demand Chart
108
  st.subheader("๐ŸŽฏ Production vs Demand")
109
 
110
+ from src.config.optimization_config import get_demand_dictionary
111
  DEMAND_DICTIONARY = get_demand_dictionary()
112
  prod_demand_data = []
113
  for product, production in results['weekly_production'].items():
 
556
  line_name = line_names.get(row['line_type_id'], f"Line {row['line_type_id']}")
557
 
558
  # Calculate costs for this production run (accounting for payment mode)
559
+ from src.config.optimization_config import get_payment_mode_config, get_max_hour_per_shift_per_person
560
  PAYMENT_MODE_CONFIG = get_payment_mode_config() # Dynamic call
561
  MAX_HOUR_PER_SHIFT_PER_PERSON = get_max_hour_per_shift_per_person() # Dynamic call
562