Skip to content

Commit 7ab517e

Browse files
committed
feat: add filtering capability to benchmark and conversion scripts
1 parent 37b7c18 commit 7ab517e

11 files changed

Lines changed: 148 additions & 65 deletions

‎AGENTS.md‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,35 @@
44

55
## Issue Summary Workflow
66
When user says "summary on issue #N", use `gh issue comment N --body-file -`
7-
to post a summary of completed work to the GitHub issue.
7+
to post a summary of completed work to the GitHub issue.
8+
9+
## Testing Workflow
10+
11+
### Unit Tests
12+
```powershell
13+
dotnet test tests/MiniPdf.Tests
14+
```
15+
16+
### Benchmarks (Excel / DOCX / Issues)
17+
```powershell
18+
scripts/Run-Benchmark.ps1 # Excel (150+ cases)
19+
scripts/Run-Benchmark_docx.ps1 # DOCX
20+
scripts/Run-Benchmark_issues.ps1 # User-reported issues
21+
```
22+
Flags: `-CompareOnly`, `-SkipGenerate`, `-SkipReference`, `-SkipMiniPdf`
23+
24+
### Single File / Filtered Run
25+
```powershell
26+
scripts/Run-Benchmark.ps1 -Filter "border" # only cases containing "border"
27+
scripts/Run-Benchmark_docx.ps1 -Filter "heading"
28+
scripts/Run-Benchmark_issues.ps1 -Filter "sa8000"
29+
```
30+
31+
### Quick Compare Only
32+
```powershell
33+
cd tests/MiniPdf.Benchmark
34+
python compare_pdfs.py
35+
```
36+
37+
### Scoring
38+
`overall = text×0.4 + visual×0.4 + pages×0.2` — report in `tests/MiniPdf.Benchmark/reports/`

‎scripts/Run-Benchmark.ps1‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ param(
1919
[switch]$SkipReference,
2020
[switch]$SkipInstall,
2121
[switch]$WithOffice,
22-
[switch]$SkipOffice
22+
[switch]$SkipOffice,
23+
[string]$Filter
2324
)
2425

2526
$ErrorActionPreference = "Continue"
@@ -49,6 +50,7 @@ if ($SkipMiniPdf) { $pyArgs += "--skip-minipdf" }
4950
if ($SkipReference) { $pyArgs += "--skip-reference" }
5051
if ($WithOffice) { $pyArgs += "--with-office" }
5152
if ($SkipOffice) { $pyArgs += "--skip-office" }
53+
if ($Filter) { $pyArgs += "--filter"; $pyArgs += $Filter }
5254

5355
# Run the benchmark pipeline
5456
Write-Host "`n[Running] python run_benchmark.py $($pyArgs -join ' ')`n" -ForegroundColor Yellow

‎scripts/Run-Benchmark_docx.ps1‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ param(
1919
[switch]$SkipReference,
2020
[switch]$SkipInstall,
2121
[switch]$WithOffice,
22-
[switch]$SkipOffice
22+
[switch]$SkipOffice,
23+
[string]$Filter
2324
)
2425

2526
$ErrorActionPreference = "Continue"
@@ -49,6 +50,7 @@ if ($SkipMiniPdf) { $pyArgs += "--skip-minipdf" }
4950
if ($SkipReference) { $pyArgs += "--skip-reference" }
5051
if ($WithOffice) { $pyArgs += "--with-office" }
5152
if ($SkipOffice) { $pyArgs += "--skip-office" }
53+
if ($Filter) { $pyArgs += "--filter"; $pyArgs += $Filter }
5254

5355
# Run the benchmark pipeline
5456
Write-Host "`n[Running] python run_benchmark_docx.py $($pyArgs -join ' ')`n" -ForegroundColor Yellow

‎scripts/Run-Benchmark_issues.ps1‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ param(
1818
[switch]$SkipReference,
1919
[switch]$SkipInstall,
2020
[switch]$WithOffice,
21-
[switch]$SkipOffice
21+
[switch]$SkipOffice,
22+
[string]$Filter
2223
)
2324

2425
$ErrorActionPreference = "Continue"
@@ -65,6 +66,9 @@ foreach ($d in @($MiniPdfXlsx, $MiniPdfDocx, $RefXlsx, $RefDocx, $OfficeXlsx, $O
6566

6667
# ── XLSX ──
6768
$xlsxFiles = Get-ChildItem -Path $XlsxIssueDir -Filter "*.xlsx" -ErrorAction SilentlyContinue
69+
if ($Filter) {
70+
$xlsxFiles = $xlsxFiles | Where-Object { $_.BaseName -like "*$Filter*" }
71+
}
6872
if ($xlsxFiles -and $xlsxFiles.Count -gt 0) {
6973
$cnt = $xlsxFiles.Count
7074
Write-Host "`n--- XLSX Issue Files: $cnt files ---" -ForegroundColor Cyan
@@ -73,7 +77,9 @@ if ($xlsxFiles -and $xlsxFiles.Count -gt 0) {
7377
Write-Host "[Step 1] Converting XLSX -> PDF (MiniPdf)..." -ForegroundColor Yellow
7478
Push-Location $ScriptsDir
7579
try {
76-
dotnet run convert_xlsx_to_pdf.cs -- $XlsxIssueDir $MiniPdfXlsx
80+
$convertArgs = @("convert_xlsx_to_pdf.cs", "--", $XlsxIssueDir, $MiniPdfXlsx)
81+
if ($Filter) { $convertArgs += $Filter }
82+
dotnet run @convertArgs
7783
} finally {
7884
Pop-Location
7985
}
@@ -83,7 +89,9 @@ if ($xlsxFiles -and $xlsxFiles.Count -gt 0) {
8389
Write-Host "[Step 2] Converting XLSX -> PDF (LibreOffice)..." -ForegroundColor Yellow
8490
Push-Location $BenchmarkDir
8591
try {
86-
python generate_reference_pdfs.py --xlsx-dir $XlsxIssueDir --pdf-dir $RefXlsx
92+
$refArgs = @("generate_reference_pdfs.py", "--xlsx-dir", $XlsxIssueDir, "--pdf-dir", $RefXlsx)
93+
if ($Filter) { $refArgs += @("--filter", $Filter) }
94+
python @refArgs
8795
} finally {
8896
Pop-Location
8997
}
@@ -104,6 +112,7 @@ if ($xlsxFiles -and $xlsxFiles.Count -gt 0) {
104112
if ($WithOffice -and (Test-Path $OfficeXlsx)) {
105113
$compareArgs += @("--office-dir", $OfficeXlsx)
106114
}
115+
if ($Filter) { $compareArgs += @("--filter", $Filter) }
107116
Push-Location $BenchmarkDir
108117
try {
109118
python @compareArgs
@@ -116,6 +125,9 @@ if ($xlsxFiles -and $xlsxFiles.Count -gt 0) {
116125

117126
# ── DOCX ──
118127
$docxFiles = Get-ChildItem -Path $DocxIssueDir -Filter "*.docx" -ErrorAction SilentlyContinue
128+
if ($Filter) {
129+
$docxFiles = $docxFiles | Where-Object { $_.BaseName -like "*$Filter*" }
130+
}
119131
if ($docxFiles -and $docxFiles.Count -gt 0) {
120132
$cnt = $docxFiles.Count
121133
Write-Host "`n--- DOCX Issue Files: $cnt files ---" -ForegroundColor Cyan
@@ -124,7 +136,9 @@ if ($docxFiles -and $docxFiles.Count -gt 0) {
124136
Write-Host "[Step 1] Converting DOCX -> PDF (MiniPdf)..." -ForegroundColor Yellow
125137
Push-Location $ScriptsDir
126138
try {
127-
dotnet run convert_docx_to_pdf.cs -- $DocxIssueDir $MiniPdfDocx
139+
$convertArgs = @("convert_docx_to_pdf.cs", "--", $DocxIssueDir, $MiniPdfDocx)
140+
if ($Filter) { $convertArgs += $Filter }
141+
dotnet run @convertArgs
128142
} finally {
129143
Pop-Location
130144
}
@@ -134,7 +148,9 @@ if ($docxFiles -and $docxFiles.Count -gt 0) {
134148
Write-Host "[Step 2] Converting DOCX -> PDF (LibreOffice)..." -ForegroundColor Yellow
135149
Push-Location $BenchmarkDir
136150
try {
137-
python generate_reference_pdfs_docx.py --docx-dir $DocxIssueDir --pdf-dir $RefDocx
151+
$refArgs = @("generate_reference_pdfs_docx.py", "--docx-dir", $DocxIssueDir, "--pdf-dir", $RefDocx)
152+
if ($Filter) { $refArgs += @("--filter", $Filter) }
153+
python @refArgs
138154
} finally {
139155
Pop-Location
140156
}
@@ -155,6 +171,7 @@ if ($docxFiles -and $docxFiles.Count -gt 0) {
155171
if ($WithOffice -and (Test-Path $OfficeDocx)) {
156172
$compareArgs += @("--office-dir", $OfficeDocx)
157173
}
174+
if ($Filter) { $compareArgs += @("--filter", $Filter) }
158175
Push-Location $BenchmarkDir
159176
try {
160177
python @compareArgs

‎tests/MiniPdf.Benchmark/compare_pdfs.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ def main():
847847
help="Skip AI call when pixel similarity is already above this threshold (default: 0.97)")
848848
parser.add_argument("--report-only", action="store_true",
849849
help="Skip comparisons; regenerate report from existing comparison_report.json")
850+
parser.add_argument("--filter", default=None, metavar="PATTERN",
851+
help="Only compare files whose name contains this substring")
850852
args = parser.parse_args()
851853

852854
if args.ai_compare:
@@ -899,6 +901,10 @@ def main():
899901
for f in Path(office_dir).glob("*.pdf"):
900902
names.add(f.stem)
901903

904+
# Apply filter
905+
if args.filter:
906+
names = {n for n in names if args.filter.lower() in n.lower()}
907+
902908
if not names:
903909
print("No PDF files found in either directory.")
904910
print("Run the following first:")

‎tests/MiniPdf.Benchmark/generate_reference_pdfs.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def main():
8989
help="Directory containing .xlsx files")
9090
parser.add_argument("--pdf-dir", default="reference_pdfs",
9191
help="Output directory for reference PDFs")
92+
parser.add_argument("--filter", default=None, metavar="PATTERN",
93+
help="Only convert files whose name contains this substring")
9294
args = parser.parse_args()
9395

9496
xlsx_dir = os.path.abspath(args.xlsx_dir)
@@ -108,6 +110,8 @@ def main():
108110
print()
109111

110112
xlsx_files = sorted(Path(xlsx_dir).glob("*.xlsx"))
113+
if args.filter:
114+
xlsx_files = [f for f in xlsx_files if args.filter.lower() in f.stem.lower()]
111115
if not xlsx_files:
112116
print("No .xlsx files found.")
113117
sys.exit(1)

‎tests/MiniPdf.Benchmark/generate_reference_pdfs_docx.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def main():
8080
help="Directory containing .docx files")
8181
parser.add_argument("--pdf-dir", default="reference_pdfs_docx",
8282
help="Output directory for reference PDFs")
83+
parser.add_argument("--filter", default=None, metavar="PATTERN",
84+
help="Only convert files whose name contains this substring")
8385
args = parser.parse_args()
8486

8587
docx_dir = os.path.abspath(args.docx_dir)
@@ -99,6 +101,8 @@ def main():
99101
print()
100102

101103
docx_files = sorted(Path(docx_dir).glob("*.docx"))
104+
if args.filter:
105+
docx_files = [f for f in docx_files if args.filter.lower() in f.stem.lower()]
102106
if not docx_files:
103107
print("No .docx files found.")
104108
sys.exit(1)

‎tests/MiniPdf.Benchmark/run_benchmark.py‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,44 +56,41 @@ def step_generate_xlsx():
5656
)
5757

5858

59-
def step_generate_minipdf_pdfs():
59+
def step_generate_minipdf_pdfs(filter_pattern: str = None):
6060
"""Step 2: Convert Excel files to PDF using MiniPdf."""
6161
banner("Step 2: Convert Excel -> PDF (MiniPdf)")
6262
scripts_dir = SCRIPT_DIR / ".." / "MiniPdf.Scripts"
6363

64-
# Use dotnet run with the .cs script
65-
return run(
66-
["dotnet", "run", "--no-cache", "convert_xlsx_to_pdf.cs"],
67-
cwd=str(scripts_dir),
68-
)
64+
cmd = ["dotnet", "run", "--no-cache", "convert_xlsx_to_pdf.cs"]
65+
if filter_pattern:
66+
cmd += ["--", str(XLSX_DIR.resolve()), str(MINIPDF_PDF_DIR.resolve()), filter_pattern]
67+
return run(cmd, cwd=str(scripts_dir))
6968

7069

71-
def step_generate_reference_pdfs():
70+
def step_generate_reference_pdfs(filter_pattern: str = None):
7271
"""Step 3: Convert Excel files to PDF using LibreOffice (reference)."""
7372
banner("Step 3: Convert Excel -> PDF (LibreOffice Reference)")
74-
return run(
75-
[sys.executable, "generate_reference_pdfs.py",
76-
"--xlsx-dir", str(XLSX_DIR.resolve()),
77-
"--pdf-dir", str(REFERENCE_PDF_DIR.resolve())],
78-
cwd=str(SCRIPT_DIR),
79-
check=False,
80-
)
73+
cmd = [sys.executable, "generate_reference_pdfs.py",
74+
"--xlsx-dir", str(XLSX_DIR.resolve()),
75+
"--pdf-dir", str(REFERENCE_PDF_DIR.resolve())]
76+
if filter_pattern:
77+
cmd += ["--filter", filter_pattern]
78+
return run(cmd, cwd=str(SCRIPT_DIR), check=False)
8179

8280

83-
def step_generate_office_pdfs():
81+
def step_generate_office_pdfs(filter_pattern: str = None):
8482
"""Step 3b: Convert Excel files to PDF using Office (Excel COM)."""
8583
banner("Step 3b: Convert Excel -> PDF (Office / Excel COM)")
86-
return run(
87-
[sys.executable, "generate_office_pdfs.py",
88-
"--xlsx-dir", str(XLSX_DIR.resolve()),
89-
"--pdf-dir", str(OFFICE_PDF_DIR.resolve())],
90-
cwd=str(SCRIPT_DIR),
91-
check=False,
92-
)
84+
cmd = [sys.executable, "generate_office_pdfs.py",
85+
"--xlsx-dir", str(XLSX_DIR.resolve()),
86+
"--pdf-dir", str(OFFICE_PDF_DIR.resolve())]
87+
if filter_pattern:
88+
cmd += ["--filter", filter_pattern]
89+
return run(cmd, cwd=str(SCRIPT_DIR), check=False)
9390

9491

9592
def step_compare(ai_compare: bool = False, ai_max_pages: int = 1, ai_threshold: float = 0.90,
96-
use_office: bool = False):
93+
use_office: bool = False, filter_pattern: str = None):
9794
"""Step 4: Compare MiniPdf PDFs against reference PDFs."""
9895
banner("Step 4: Compare MiniPdf vs Reference")
9996
cmd = [
@@ -106,6 +103,8 @@ def step_compare(ai_compare: bool = False, ai_max_pages: int = 1, ai_threshold:
106103
cmd += ["--office-dir", str(OFFICE_PDF_DIR.resolve())]
107104
if ai_compare:
108105
cmd += ["--ai-compare", "--ai-max-pages", str(ai_max_pages), "--ai-threshold", str(ai_threshold)]
106+
if filter_pattern:
107+
cmd += ["--filter", filter_pattern]
109108
return run(cmd, cwd=str(SCRIPT_DIR))
110109

111110

@@ -150,6 +149,8 @@ def step_analyze_report():
150149

151150
def main():
152151
parser = argparse.ArgumentParser(description="MiniPdf Benchmark Pipeline")
152+
parser.add_argument("--filter", default=None, metavar="PATTERN",
153+
help="Only process files matching this substring (e.g. 'border' or 'chart_bar')")
153154
parser.add_argument("--skip-generate", action="store_true", help="Skip Excel generation")
154155
parser.add_argument("--skip-minipdf", action="store_true", help="Skip MiniPdf PDF conversion")
155156
parser.add_argument("--skip-reference", action="store_true", help="Skip LibreOffice reference conversion")
@@ -176,25 +177,26 @@ def main():
176177

177178
ai_kwargs = dict(ai_compare=args.ai_compare, ai_max_pages=args.ai_max_pages, ai_threshold=args.ai_threshold)
178179
compare_kwargs = dict(**ai_kwargs, use_office=args.with_office)
180+
filt = args.filter
179181

180182
if args.compare_only:
181-
step_compare(**compare_kwargs)
183+
step_compare(**compare_kwargs, filter_pattern=filt)
182184
step_analyze_report()
183185
return
184186

185-
if not args.skip_generate:
187+
if not args.skip_generate and not filt:
186188
step_generate_xlsx()
187189

188190
if not args.skip_minipdf:
189-
step_generate_minipdf_pdfs()
191+
step_generate_minipdf_pdfs(filter_pattern=filt)
190192

191193
if not args.skip_reference:
192-
step_generate_reference_pdfs()
194+
step_generate_reference_pdfs(filter_pattern=filt)
193195

194196
if args.with_office and not args.skip_office:
195-
step_generate_office_pdfs()
197+
step_generate_office_pdfs(filter_pattern=filt)
196198

197-
step_compare(**compare_kwargs)
199+
step_compare(**compare_kwargs, filter_pattern=filt)
198200
step_analyze_report()
199201

200202
banner("Pipeline Complete")

0 commit comments

Comments
 (0)