Skip to content

Commit 1b2086f

Browse files
committed
feat(verify): support exclude_paths in smartphone backfill sampling
1 parent 6d208b5 commit 1b2086f

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎app/verify/wikipedia_smartphone_backfill.py‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,10 @@ def _liveness_for(url: str | None, page_liveness: dict[str, str]) -> str:
10521052

10531053

10541054
def sample_diverse_records(
1055-
phone_dir: Path, repo_root: Path, limit: int | None
1055+
phone_dir: Path,
1056+
repo_root: Path,
1057+
limit: int | None,
1058+
exclude_paths: set[str] | None = None,
10561059
) -> list[tuple[str, dict[str, Any]]]:
10571060
"""Sample diverse records across brands and years without loading the entire 93k tree."""
10581061
brand_dirs = sorted(
@@ -1064,12 +1067,15 @@ def sample_diverse_records(
10641067
for path in bd.rglob("*.json"):
10651068
if path.name.startswith("_"):
10661069
continue
1070+
rel = path.relative_to(repo_root).as_posix()
1071+
if exclude_paths and rel in exclude_paths:
1072+
continue
10671073
try:
10681074
rec = json.loads(path.read_text(encoding="utf-8-sig"))
10691075
except Exception:
10701076
continue
10711077
if isinstance(rec, dict) and is_eligible_smartphone(rec):
1072-
all_recs.append((path.relative_to(repo_root).as_posix(), rec))
1078+
all_recs.append((rel, rec))
10731079
return all_recs
10741080

10751081
per_brand_quota = max(3, (limit // len(brand_dirs)) + 2) if brand_dirs else limit
@@ -1083,25 +1089,31 @@ def sample_diverse_records(
10831089
for path in yd.rglob("*.json"):
10841090
if path.name.startswith("_"):
10851091
continue
1092+
rel = path.relative_to(repo_root).as_posix()
1093+
if exclude_paths and rel in exclude_paths:
1094+
continue
10861095
try:
10871096
rec = json.loads(path.read_text(encoding="utf-8-sig"))
10881097
except Exception:
10891098
continue
10901099
if isinstance(rec, dict) and is_eligible_smartphone(rec):
1091-
brand_items.append((path.relative_to(repo_root).as_posix(), rec))
1100+
brand_items.append((rel, rec))
10921101
break
10931102
if len(brand_items) >= per_brand_quota:
10941103
break
10951104
else:
10961105
for path in bd.rglob("*.json"):
10971106
if path.name.startswith("_"):
10981107
continue
1108+
rel = path.relative_to(repo_root).as_posix()
1109+
if exclude_paths and rel in exclude_paths:
1110+
continue
10991111
try:
11001112
rec = json.loads(path.read_text(encoding="utf-8-sig"))
11011113
except Exception:
11021114
continue
11031115
if isinstance(rec, dict) and is_eligible_smartphone(rec):
1104-
brand_items.append((path.relative_to(repo_root).as_posix(), rec))
1116+
brand_items.append((rel, rec))
11051117
if len(brand_items) >= per_brand_quota:
11061118
break
11071119
if brand_items:
@@ -1208,19 +1220,20 @@ def consider_fallback(base: str, record_brand: str = "") -> None:
12081220
page_rows.extend(extracted)
12091221
fetcher.rows = list(page_rows)
12101222

1223+
cache = load_cache(cache_path) if cache_path else {}
1224+
cached_paths = set(cache.keys())
1225+
12111226
# Load candidate records
12121227
repo_root: Path | None = None
12131228
if records is None:
12141229
phone_dir, repo_root = smartphone_scan_root(data_root)
1215-
chosen = sample_diverse_records(phone_dir, repo_root, limit)
1230+
chosen = sample_diverse_records(phone_dir, repo_root, limit, exclude_paths=cached_paths)
12161231
eligible_count = 73465
12171232
else:
1218-
loaded = [(rel, rec) for rel, rec in records if is_eligible_smartphone(rec)]
1233+
loaded = [(rel, rec) for rel, rec in records if is_eligible_smartphone(rec) and rel not in cached_paths]
12191234
chosen = sample_diverse(loaded, limit)
12201235
eligible_count = len(loaded)
12211236
repo_root = data_root
1222-
1223-
cache = load_cache(cache_path) if cache_path else {}
12241237
result = RunResult(
12251238
eligible=eligible_count,
12261239
index_rows=len(page_rows),

0 commit comments

Comments
 (0)