from dataclasses import dataclass from typing import Dict, Any, Optional @dataclass class DishThermalState: food_name: str macronutrients: Dict[str, float] # grams of water, fat, protein, carbs estimated_mass_g: float initial_temp_c: float volume_cm3: Optional[float] = None class MicrowaveThermalEngine: """Calculates cook parameters based on physical properties""" DEFAULT_EFFICIENCY = 0.70 # ~70% magnetron efficiency TARGET_TEMP_C = 74.0 # Safe food temperature @staticmethod def estimate_specific_heat(macros: Dict[str, float], total_weight_g: float) -> float: """Estimates Cp in J/(g*C) based on macro composition""" if total_weight_g <= 0: return 3.5 # Fallback average for mixed meals w_water = macros.get("water_g", total_weight_g * 0.7) / total_weight_g w_protein = macros.get("protein_g", 0.0) / total_weight_g w_fat = macros.get("fat_g", 0.0) / total_weight_g w_carbs = macros.get("carbs_g", 0.0) / total_weight_g return (4.184 * w_water) + (1.71 * w_protein) + (1.67 * w_fat) + (1.42 * w_carbs) def calculate_cook_plan(self, state: DishThermalState, microwave_wattage: int) -> Dict[str, Any]: cp = self.estimate_specific_heat(state.macronutrients, state.estimated_mass_g) delta_t = max(0.0, self.TARGET_TEMP_C - state.initial_temp_c) # Q = m * c_p * delta_t required_joules = state.estimated_mass_g * cp * delta_t effective_power_watts = microwave_wattage * self.DEFAULT_EFFICIENCY total_seconds = required_joules / effective_power_watts if effective_power_watts > 0 else 0 # Determine duty cycle / power level recommendations power_level = 100 if state.initial_temp_c < 0: # Frozen food requires defrost cycle to prevent edge-cooking power_level = 50 total_seconds *= 1.4 return { "cook_time_seconds": round(total_seconds), "recommended_power_level_pct": power_level, "estimated_specific_heat": round(cp, 2), "energy_joules": round(required_joules) }