1. 实际应用场景 & 痛点引入
场景
你在家想做烘焙,但厨房里只有部分工具和食材,不确定能做什么蛋糕、饼干或面包。
你希望有一个工具:
- 根据现有工具和食材,自动生成可做的烘焙食谱。
- 提供详细制作步骤和时间,避免翻找多个教程。
- 记录烘焙失败原因,总结经验,下次改进。
痛点
1. 不知道能做什么:每次都要查多个食谱,看是否缺材料。
2. 步骤分散:不同网站的步骤格式不一,容易遗漏。
3. 失败无记录:每次失败后不知道原因,容易重复犯错。
4. 缺乏个性化推荐:没有根据现有条件智能推荐。
2. 核心逻辑讲解
系统分为以下几个模块:
1. 用户资源输入
- 用户列出自己有的烘焙工具(烤箱、打蛋器、模具等)和食材(面粉、鸡蛋、糖、黄油等)。
2. 食谱数据库
- 存储多种蛋糕、饼干、面包的配方,包括所需工具、食材、步骤、时间。
3. 匹配引擎
- 根据用户拥有的工具和食材,筛选出可做的食谱。
- 按匹配度排序(完全匹配 > 部分匹配)。
4. 步骤与时间管理
- 输出详细制作步骤,并估算总时间和各阶段时间。
5. 失败记录与经验总结
- 用户可记录每次失败原因(如“蛋白打发不足”“烤箱温度过高”)。
- 系统统计高频失败原因,给出改进建议。
3. 代码模块化实现(Python)
项目结构:
baking_assistant/
├── main.py # 入口
├── inventory.py # 用户资源输入
├── recipe_db.py # 食谱数据库
├── matcher.py # 匹配引擎
├── step_manager.py # 步骤与时间管理
├── failure_logger.py # 失败记录
├── config.json # 配置文件
└── README.md
config.json
{
"recipes": [
{
"name": "戚风蛋糕",
"tools": ["烤箱", "电动打蛋器", "蛋糕模"],
"ingredients": ["鸡蛋", "低筋面粉", "糖", "油", "牛奶"],
"steps": [
"分离蛋白蛋黄",
"打发蛋白至硬性发泡",
"混合蛋黄糊",
"蛋白与蛋黄糊翻拌均匀",
"倒入模具震出气泡",
"烤箱150°C烤50分钟"
],
"time_minutes": 70
},
{
"name": "曲奇饼干",
"tools": ["烤箱", "打蛋器", "裱花袋"],
"ingredients": ["黄油", "糖粉", "低筋面粉", "鸡蛋"],
"steps": [
"软化黄油加糖粉打发",
"加入蛋液搅匀",
"筛入面粉拌匀",
"装入裱花袋挤成形状",
"烤箱170°C烤15分钟"
],
"time_minutes": 40
}
]
}
inventory.py
class Inventory:
def __init__(self):
self.tools = set()
self.ingredients = set()
def add_tool(self, tool):
self.tools.add(tool)
def add_ingredient(self, ingredient):
self.ingredients.add(ingredient)
def get_tools(self):
return self.tools
def get_ingredients(self):
return self.ingredients
recipe_db.py
import json
class RecipeDB:
def __init__(self, config_path="config.json"):
with open(config_path, 'r', encoding='utf-8') as f:
data = json.load(f)
self.recipes = data["recipes"]
def get_all(self):
return self.recipes
matcher.py
class Matcher:
def __init__(self, db):
self.db = db
def match(self, tools, ingredients):
matched = []
for recipe in self.db.get_all():
if recipe["tools"].issubset(tools) and recipe["ingredients"].issubset(ingredients):
matched.append(recipe)
return matched
step_manager.py
class StepManager:
@staticmethod
def show_steps(recipe):
print(f"\n【{recipe['name']}】制作步骤:")
for i, step in enumerate(recipe["steps"], 1):
print(f"{i}. {step}")
print(f"总耗时: {recipe['time_minutes']} 分钟")
failure_logger.py
import datetime
class FailureLogger:
def __init__(self):
self.failures = []
def log_failure(self, recipe_name, reason):
self.failures.append({
"time": datetime.datetime.now().isoformat(),
"recipe": recipe_name,
"reason": reason
})
def show_failures(self):
if not self.failures:
print("暂无失败记录")
return
print("\n失败记录:")
for f in self.failures:
print(f"{f['time']} - {f['recipe']}: {f['reason']}")
def summary(self):
reasons = [f["reason"] for f in self.failures]
from collections import Counter
count = Counter(reasons)
print("\n失败原因统计:")
for reason, cnt in count.most_common():
print(f"{reason}: {cnt}次")
main.py
from inventory import Inventory
from recipe_db import RecipeDB
from matcher import Matcher
from step_manager import StepManager
from failure_logger import FailureLogger
def main():
inv = Inventory()
db = RecipeDB()
matcher = Matcher(db)
step_mgr = StepManager()
logger = FailureLogger()
# 模拟用户输入
inv.add_tool("烤箱")
inv.add_tool("电动打蛋器")
inv.add_tool("蛋糕模")
inv.add_ingredient("鸡蛋")
inv.add_ingredient("低筋面粉")
inv.add_ingredient("糖")
inv.add_ingredient("油")
inv.add_ingredient("牛奶")
print("=== 居家烘焙助手 ===")
while True:
print("\n1. 查找可做的食谱")
print("2. 记录烘焙失败")
print("3. 查看失败记录")
print("4. 退出")
choice = input("选择: ").strip()
if choice == "1":
recipes = matcher.match(inv.get_tools(), inv.get_ingredients())
if recipes:
print("\n可做的食谱:")
for r in recipes:
print(f"- {r['name']}")
name = input("输入要查看的食谱名称: ").strip()
selected = next((r for r in recipes if r["name"] == name), None)
if selected:
step_mgr.show_steps(selected)
else:
print("没有可做的食谱,请补充工具或食材")
elif choice == "2":
recipe_name = input("失败的食谱名称: ").strip()
reason = input("失败原因: ").strip()
logger.log_failure(recipe_name, reason)
print("已记录失败原因")
elif choice == "3":
logger.show_failures()
logger.summary()
elif choice == "4":
break
else:
print("无效选择")
if __name__ == "__main__":
main()
4. README.md
# Baking Assistant
根据现有工具和食材生成可做的烘焙食谱,提供详细步骤和时间,记录失败原因并总结经验。
## 功能
- 输入工具与食材
- 智能匹配可做的食谱
- 显示详细制作步骤
- 记录失败原因与统计
## 安装
bash
pip install -r requirements.txt
目前仅需标准库
python main.py
## 使用
- 运行程序,输入已有工具和食材。
- 选择查找可做的食谱。
- 可记录失败原因并查看统计。
5. 使用说明
1. 运行
"main.py"。
2. 输入已有工具和食材。
3. 选择查找可做的食谱并查看步骤。
4. 记录失败原因,系统会统计高频问题。
5. 根据经验改进下次烘焙。
6. 核心知识点卡片
知识点 描述 应用场景
集合运算 判断工具/食材是否足够 食谱匹配
JSON 数据存储 存储食谱信息 可扩展维护
失败记录统计 使用 Counter 统计原因 经验总结
模块化设计 分离数据、逻辑、UI 易维护
步骤管理 分阶段输出制作流程 提高成功率
7. 总结
这个居家烘焙助手 APP通过资源匹配 + 详细步骤 + 失败记录分析,解决了烘焙爱好者“不知道能做什么”“步骤分散”“失败无总结”的痛点。
- 创新点:智能匹配现有条件 + 失败经验沉淀
- 技术栈:Python + JSON + 集合运算 + 数据统计
- 扩展性:可加入图片识别食材、社区分享、智能推荐算法
如果你愿意,还可以增加图片识别食材功能(使用 TensorFlow/Keras)并设计 Flutter 移动端,让它在手机上更实用。
利用AI解决实际问题,如果你觉得这个工具好用,欢迎关注长安牧笛!