fix: Replace all remaining hardcoded English reasoning with structured codes

This commit removes the last hardcoded English text from reasoning fields
across all backend services, completing the i18n implementation.

Changes by service:

Safety Stock Calculator (safety_stock_calculator.py):
- CALC:STATISTICAL_Z_SCORE - Statistical calculation with Z-score
- CALC:ADVANCED_VARIABILITY - Advanced formula with demand and lead time variability
- CALC:FIXED_PERCENTAGE - Fixed percentage of lead time demand
- All calculation methods now use structured codes with pipe-separated parameters

Price Forecaster (price_forecaster.py):
- PRICE_FORECAST:DECREASE_EXPECTED - Price expected to decrease
- PRICE_FORECAST:INCREASE_EXPECTED - Price expected to increase
- PRICE_FORECAST:HIGH_VOLATILITY - High price volatility detected
- PRICE_FORECAST:BELOW_AVERAGE - Current price below average (buy opportunity)
- PRICE_FORECAST:STABLE - Price stable, normal schedule
- All forecasts include relevant parameters (change_pct, days, etc.)

Optimization Utils (shared/utils/optimization.py):
- EOQ:BASE - Economic Order Quantity base calculation
- EOQ:MOQ_APPLIED - Minimum order quantity constraint applied
- EOQ:MAX_APPLIED - Maximum order quantity constraint applied
- TIER_PRICING:CURRENT_TIER - Current tier pricing
- TIER_PRICING:UPGRADED - Upgraded to higher tier for savings
- All optimizations include calculation parameters

Format: All codes use pattern "CATEGORY:TYPE|param1=value|param2=value"
This allows frontend to parse and translate with parameters while maintaining
technical accuracy for logging and debugging.

Frontend can now translate ALL reasoning codes across the entire system.
This commit is contained in:
Claude
2025-11-07 19:00:00 +00:00
parent ed7db4d4f2
commit be8cb20b18
3 changed files with 21 additions and 20 deletions

View File

@@ -87,17 +87,20 @@ def optimize_order_quantity(
# Start with EOQ or required quantity, whichever is larger
optimal_qty = max(float(required_quantity), eoq)
reasoning = f"Base EOQ: {eoq:.2f}, Required: {required_quantity}"
# Build structured reasoning code with parameters
reasoning_parts = [f"EOQ:BASE|eoq={eoq:.2f}|required={required_quantity}"]
# Apply minimum order quantity
if min_order_qty and Decimal(optimal_qty) < min_order_qty:
optimal_qty = float(min_order_qty)
reasoning += f", Applied MOQ: {min_order_qty}"
reasoning_parts.append(f"EOQ:MOQ_APPLIED|moq={min_order_qty}")
# Apply maximum order quantity
if max_order_qty and Decimal(optimal_qty) > max_order_qty:
optimal_qty = float(max_order_qty)
reasoning += f", Capped at max: {max_order_qty}"
reasoning_parts.append(f"EOQ:MAX_APPLIED|max={max_order_qty}")
reasoning = "|".join(reasoning_parts)
# Calculate costs
orders_per_year = annual_demand / optimal_qty if optimal_qty > 0 else 0
@@ -208,7 +211,7 @@ def apply_price_tier_optimization(
best_quantity = base_quantity
best_price = current_tier_price
best_savings = Decimal('0')
reasoning = f"Current tier price: ${current_tier_price}"
reasoning = f"TIER_PRICING:CURRENT_TIER|price={current_tier_price}"
for tier in sorted_tiers:
tier_min_qty = Decimal(str(tier['min_quantity']))
@@ -232,7 +235,7 @@ def apply_price_tier_optimization(
best_quantity = tier_min_qty
best_price = tier_price
best_savings = savings
reasoning = f"Upgraded to tier {tier_min_qty}+ for ${savings:.2f} savings"
reasoning = f"TIER_PRICING:UPGRADED|tier_min={tier_min_qty}|savings={savings:.2f}"
return best_quantity, best_price, reasoning