Spaces:
Runtime error
Runtime error
| """ | |
| PregoPal - 体重检查插件 | |
| ======================= | |
| 检查体重记录,对比 WS/T 801 标准。 | |
| """ | |
| from plugins.base import LoopPlugin, PluginResult, LoopStage, LoopContext | |
| from modules.nutrition_standards import WeightStandardParser | |
| class WeightCheckPlugin(LoopPlugin): | |
| """检查体重记录,对比 WS/T 801 标准""" | |
| def stage(self) -> LoopStage: | |
| return LoopStage.SUMMARIZE | |
| def name(self) -> str: | |
| return "weight_check" | |
| async def run(self, ctx: LoopContext) -> PluginResult: | |
| # 从简报中获取体重数据 | |
| weight_data = ctx.briefing.get("weight_data", {}) | |
| if not weight_data or "bmi_before" not in weight_data: | |
| return PluginResult( | |
| success=True, | |
| data={"status": "no_data"}, | |
| message="暂无体重数据,跳过检查" | |
| ) | |
| result = WeightStandardParser.evaluate( | |
| bmi_before_pregnancy=weight_data.get("bmi_before", 22.0), | |
| current_week=weight_data.get("current_week", 20), | |
| total_gain=weight_data.get("total_gain", 5.0), | |
| ) | |
| ctx.briefing["weight_evaluation"] = result | |
| ctx.weight_data = result | |
| return PluginResult( | |
| success=True, | |
| data=result, | |
| message=result["message"] | |
| ) | |