devin/1780910557-m4-ingestion-mgmt
main
实现 M4 采集管理(在 M0–M3 已完成的地基/数据模型/OFF 采集/只读 API 之上),补齐持续运营所需能力:增量更新、第二数据源补全(GS1)、去重合并与字段级冲突解决、数据质量评分、定时调度。全部为 Python 侧(ingestion/),只写库、可单测。
ingestion/
OpenFoodFactsAdapter.fetch_modified_since()
last_modified_t
etl/state.py
ingest_state
0004
GREATEST(...)
adapters/gs1.py
etl/supplement.py
gs1
etl/dedup.py
merged
canonical_id
merge_log
etl/merge.py
etl/quality.py
product.quality_score
0.4*完整度 + 0.3*源权重 + 0.2*多源一致 + 0.1*新鲜度
load_record()
merge_products()
jobs/schedule.py
jobs/update_off.py
jobs/dedup.py
docs/ingestion-management.md
ruff check
ruff format --check
pytest
注:库集成测试在无数据库或未应用 M4 迁移时自动跳过。
- OFF incremental fetch via search API + persistent watermark (ingest_state, migration 0004) - GS1 barcode supplement adapter (offline mapping + GS1-style API) filling only gaps with field-level provenance - Non-GTIN dedup with canonical selection + merge_log; field-level conflict resolution (source trust > recency) - Quality scoring (0.4 completeness + 0.3 source trust + 0.2 multi-source + 0.1 freshness) wired into load/merge - Jobs: update_off, dedup, schedule; docs/ingestion-management.md - 19 new tests (pure + DB-integration), ruff clean Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
No dependencies set.
The note is not visible to the blocked user.
目标
实现 M4 采集管理(在 M0–M3 已完成的地基/数据模型/OFF 采集/只读 API 之上),补齐持续运营所需能力:增量更新、第二数据源补全(GS1)、去重合并与字段级冲突解决、数据质量评分、定时调度。全部为 Python 侧(
ingestion/),只写库、可单测。改动
OpenFoodFactsAdapter.fetch_modified_since()用 OFF search API 按last_modified_t拉变更;etl/state.py+ 新表ingest_state(迁移0004,可逆)持久化每源水位,GREATEST(...)保证只前进。adapters/gs1.py(离线 JSON 映射 / GS1 风格 API 两种模式)+etl/supplement.py,只填空缺字段(品牌/厂商/GPC/产地/净含量),记字段级溯源,源标记gs1。etl/dedup.py对非 GTIN 重复(同名+品牌+净含量)择质量最高者为主记录,子行(溯源/图片/MSRP)重指向,标merged+canonical_id,写merge_log。etl/merge.py多源同字段按「源权重 > 新鲜度」择优,保留 provenance。etl/quality.py落到product.quality_score,公式0.4*完整度 + 0.3*源权重 + 0.2*多源一致 + 0.1*新鲜度,load_record()/merge_products()写入后重算。jobs/schedule.py(零额外依赖的周期循环)+jobs/update_off.py/jobs/dedup.pyCLI。docs/ingestion-management.md。测试
ruff check/ruff format --check全过;pytest33 passed(新增 19:纯函数 + 库集成)。0004up/down 可逆验证通过。