Lilli98 commited on
Commit
7db2386
·
verified ·
1 Parent(s): 25d9fbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py
2
- # @title Beer Game Final Version (v4.25 - Based on v4.21 Logic + UI Fixes)
3
 
4
  # -----------------------------------------------------------------------------
5
  # 1. Import Libraries
@@ -506,41 +506,33 @@ else:
506
  st.write(f"Incoming Order (This Week): **{current_incoming_order}**")
507
 
508
  if name == "Factory":
509
- arriving_this_week = list(state['factory_production_pipeline'])[0] if state['factory_production_pipeline'] else 0
510
- st.write(f"Completing This Week: **{arriving_this_week}**")
511
 
512
  # FIX: 'Next week' for Factory is the order it just received from Distributor
513
  prod_completing_next = state['last_week_orders'].get("Distributor", 0)
514
 
515
  st.write(f"Completing Next Week: **{prod_completing_next}**")
516
  else:
517
- arriving_this_week = list(e['incoming_shipments'])[0] if e['incoming_shipments'] else 0
518
- st.write(f"Arriving This Week: **{arriving_this_week}**")
519
 
520
  arriving_next = 0
521
 
522
- # FIX: Add special case for Distributor
523
  if name == 'Distributor':
524
  # 'Next week' for Distributor is what's in the factory pipeline
525
  if state['factory_production_pipeline']:
526
  arriving_next = list(state['factory_production_pipeline'])[0]
527
 
528
- # Original logic for R/W (q_len > 1)
529
  elif len(e['incoming_shipments']) > 1:
 
530
  arriving_next = list(e['incoming_shipments'])[1]
531
 
532
- # Original logic for R/W (q_len = 1 or 0)
533
- elif name in ('Wholesaler', 'Retailer') and e['incoming_shipments'].maxlen == 2:
534
- # 如果队列长度为1,说明下周的货在[0],这周的货是0
535
- if len(e['incoming_shipments']) == 1:
536
- arriving_next = list(e['incoming_shipments'])[0]
537
- arriving_this_week = 0 # 覆盖
538
- else: # 队列为0
539
- arriving_next = 0
540
- arriving_this_week = 0 # 覆盖
541
-
542
- # 重新显示修正后的"Arriving This Week"
543
- st.write(f"Arriving This Week: **{arriving_this_week}**")
544
 
545
  st.write(f"Arriving Next Week: **{arriving_next}**")
546
 
@@ -562,11 +554,9 @@ else:
562
  st.write(f"**Incoming Order (This Week):**\n# {current_incoming_order}")
563
 
564
  with col3:
565
- # Arriving THIS week (Step 1)
566
- arriving_this_week = list(e['incoming_shipments'])[0] if e['incoming_shipments'] else 0
567
- st.write(f"**Shipment Arriving (This Week):**\n# {arriving_this_week}")
568
 
569
- # Arriving NEXT week (Distributor的队列长度为1,所以[1]永远是0)
570
  arriving_next = 0
571
  st.write(f"**Shipment Arriving (Next Week):**\n# {arriving_next}")
572
 
@@ -576,6 +566,7 @@ else:
576
  st.header("Your Decision (Step 4)")
577
 
578
  # Prepare the state snapshot for the AI prompt (State AFTER arrivals/orders, BEFORE shipping)
 
579
  all_decision_point_states = {}
580
  for name in echelon_order:
581
  e_curr = echelons[name] # This is END OF LAST WEEK state
@@ -646,16 +637,18 @@ else:
646
  else:
647
  try:
648
  history_df = pd.json_normalize(state['logs'])
 
649
  human_cols = {
650
  'week': 'Week', f'{human_role}.opening_inventory': 'Opening Inv.',
651
- f'{human_role}.opening_backlog': 'Opening Backlog', f'{human_role}.arrived_this_week': 'Arrived This Week',
652
  f'{human_role}.incoming_order': 'Incoming Order', f'{human_role}.initial_order': 'Your Initial Order',
653
  f'{human_role}.ai_suggestion': 'AI Suggestion', f'{human_role}.order_placed': 'Your Final Order',
654
  f'{human_role}.arriving_next_week': 'Arriving Next Week', f'{human_role}.weekly_cost': 'Weekly Cost',
655
  }
 
656
  ordered_display_cols_keys = [
657
  'week', f'{human_role}.opening_inventory', f'{human_role}.opening_backlog',
658
- f'{human_role}.arrived_this_week', f'{human_role}.incoming_order',
659
  f'{human_role}.initial_order', f'{human_role}.ai_suggestion', f'{human_role}.order_placed',
660
  f'{human_role}.arriving_next_week', f'{human_role}.weekly_cost'
661
  ]
 
1
  # app.py
2
+ # @title Beer Game Final Version (v4.25 - Based on v4.21 Logic + UI Fixes v2)
3
 
4
  # -----------------------------------------------------------------------------
5
  # 1. Import Libraries
 
506
  st.write(f"Incoming Order (This Week): **{current_incoming_order}**")
507
 
508
  if name == "Factory":
509
+ # FIX: 'Arriving This Week' (Completing This Week) removed from UI
 
510
 
511
  # FIX: 'Next week' for Factory is the order it just received from Distributor
512
  prod_completing_next = state['last_week_orders'].get("Distributor", 0)
513
 
514
  st.write(f"Completing Next Week: **{prod_completing_next}**")
515
  else:
516
+ # FIX: 'Arriving This Week' removed from UI
 
517
 
518
  arriving_next = 0
519
 
520
+ # FIX: Logic to correctly calculate 'Arriving Next Week'
521
  if name == 'Distributor':
522
  # 'Next week' for Distributor is what's in the factory pipeline
523
  if state['factory_production_pipeline']:
524
  arriving_next = list(state['factory_production_pipeline'])[0]
525
 
 
526
  elif len(e['incoming_shipments']) > 1:
527
+ # R/W: q_len=2, 'next' is [1]
528
  arriving_next = list(e['incoming_shipments'])[1]
529
 
530
+ elif len(e['incoming_shipments']) == 1 and name in ('Wholesaler', 'Retailer'):
531
+ # R/W: q_len=1, 'next' is [0] (as 'this' is 0)
532
+ arriving_next = list(e['incoming_shipments'])[0]
533
+
534
+ # (if q_len=0, arriving_next remains 0)
535
+ # (if q_len=1 and is Distributor, arriving_next remains 0, which is correct)
 
 
 
 
 
 
536
 
537
  st.write(f"Arriving Next Week: **{arriving_next}**")
538
 
 
554
  st.write(f"**Incoming Order (This Week):**\n# {current_incoming_order}")
555
 
556
  with col3:
557
+ # FIX: 'Arriving This Week' removed from UI
 
 
558
 
559
+ # Arriving NEXT week (Distributor的队列长度为1,所以[1]永远是0, this is correct for local view)
560
  arriving_next = 0
561
  st.write(f"**Shipment Arriving (Next Week):**\n# {arriving_next}")
562
 
 
566
  st.header("Your Decision (Step 4)")
567
 
568
  # Prepare the state snapshot for the AI prompt (State AFTER arrivals/orders, BEFORE shipping)
569
+ # This logic remains correct and is NOT a UI element
570
  all_decision_point_states = {}
571
  for name in echelon_order:
572
  e_curr = echelons[name] # This is END OF LAST WEEK state
 
637
  else:
638
  try:
639
  history_df = pd.json_normalize(state['logs'])
640
+ # FIX: Removed 'Arrived This Week' from log UI
641
  human_cols = {
642
  'week': 'Week', f'{human_role}.opening_inventory': 'Opening Inv.',
643
+ f'{human_role}.opening_backlog': 'Opening Backlog',
644
  f'{human_role}.incoming_order': 'Incoming Order', f'{human_role}.initial_order': 'Your Initial Order',
645
  f'{human_role}.ai_suggestion': 'AI Suggestion', f'{human_role}.order_placed': 'Your Final Order',
646
  f'{human_role}.arriving_next_week': 'Arriving Next Week', f'{human_role}.weekly_cost': 'Weekly Cost',
647
  }
648
+ # FIX: Removed 'Arrived This Week' from log UI
649
  ordered_display_cols_keys = [
650
  'week', f'{human_role}.opening_inventory', f'{human_role}.opening_backlog',
651
+ f'{human_role}.incoming_order',
652
  f'{human_role}.initial_order', f'{human_role}.ai_suggestion', f'{human_role}.order_placed',
653
  f'{human_role}.arriving_next_week', f'{human_role}.weekly_cost'
654
  ]