Add grouped missing reference report
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from collections import Counter, defaultdict
|
||||
from pathlib import Path
|
||||
import csv
|
||||
|
||||
|
||||
def write_missing_report(rows: list[dict], out: Path) -> None:
|
||||
missing = [r for r in rows if not r["exists_by_filename"]]
|
||||
|
||||
crate_counts = Counter(r["crate"] for r in missing)
|
||||
filename_counts = Counter(r["filename"] for r in missing)
|
||||
|
||||
with out.open("w", encoding="utf-8") as f:
|
||||
f.write("# Serato Doctor Missing Report\n\n")
|
||||
f.write(f"Total missing references: {len(missing)}\n\n")
|
||||
|
||||
f.write("## Missing by crate\n\n")
|
||||
for crate, count in crate_counts.most_common():
|
||||
f.write(f"{count:5} {crate}\n")
|
||||
|
||||
f.write("\n## Most common missing filenames\n\n")
|
||||
for filename, count in filename_counts.most_common(100):
|
||||
f.write(f"{count:5} {filename}\n")
|
||||
|
||||
f.write("\n## Detail\n\n")
|
||||
by_crate = defaultdict(list)
|
||||
for r in missing:
|
||||
by_crate[r["crate"]].append(r["filename"])
|
||||
|
||||
for crate, names in sorted(by_crate.items()):
|
||||
f.write(f"\n### {crate}\n")
|
||||
for name in sorted(set(names)):
|
||||
f.write(f"- {name}\n")
|
||||
|
||||
|
||||
def write_csv(rows: list[dict], out: Path) -> None:
|
||||
with out.open("w", newline="", encoding="utf-8") as f:
|
||||
writer = csv.DictWriter(
|
||||
f,
|
||||
fieldnames=["crate", "serato_path", "filename", "exists_by_filename"],
|
||||
)
|
||||
writer.writeheader()
|
||||
writer.writerows(rows)
|
||||
|
||||
Reference in New Issue
Block a user