MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / _compute_diff

Function _compute_diff

scripts/fetch_nifdc_standards.py:243–270  ·  view source on GitHub ↗

Compare fetched data with existing and return a diff report.

(existing: dict[str, dict], fetched: list[dict])

Source from the content-addressed store, hash-verified

241 items = json.load(f)
242 return {r["number"]: r for r in items if isinstance(r, dict) and "number" in r}
243 except Exception as e:
244 print(f"[warn] could not load existing standards.json: {e}")
245 return {}
246
247
248def _compute_diff(existing: dict[str, dict], fetched: list[dict]) -> dict:
249 """Compare fetched data with existing and return a diff report."""
250 fetched_map = {r["number"]: r for r in fetched}
251 existing_nums = set(existing.keys())
252 fetched_nums = set(fetched_map.keys())
253
254 added = sorted(fetched_nums - existing_nums)
255 removed = sorted(existing_nums - fetched_nums)
256
257 changed: list[dict] = []
258 for num in sorted(existing_nums & fetched_nums):
259 old, new = existing[num], fetched_map[num]
260 diffs = {}
261 for field in ("title_zh", "status", "status_zh", "effective_date", "approval_date"):
262 ov, nv = old.get(field, ""), new.get(field, "")
263 if ov != nv:
264 diffs[field] = {"old": ov, "new": nv}
265 if diffs:
266 changed.append({"number": num, "fields": diffs})
267
268 return {
269 "added_count": len(added),
270 "removed_count": len(removed),
271 "changed_count": len(changed),
272 "added": added[:20],
273 "removed": removed[:20],

Callers 1

mainFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected