Skip to content

feat(logging): persistent state/audit log, configurable OCR scale, and temporal baseline fix - #24

Merged
ndomako10 merged 5 commits into
mainfrom
fix/temporal-baseline-filtering
Apr 30, 2026
Merged

feat(logging): persistent state/audit log, configurable OCR scale, and temporal baseline fix#24
ndomako10 merged 5 commits into
mainfrom
fix/temporal-baseline-filtering

Conversation

@ndomako10

Copy link
Copy Markdown
Owner

Summary

  • Replaces per-run timestamped log files with a persistent rename-state.json (last-good state) and rename-log.json (full audit log); prior state survives across runs without needing to scan filenames
  • Adds configurable OcrScalePercent setting so OCR decode resolution can be tuned per deployment
  • Fixes a validation failure that occurred when processing a batch of older photos after newer photos had already been renamed: all three prior-state fallback levels (state file, audit log, directory scan) now filter out entries whose datetime is ≥ the earliest source photo in the current batch, ensuring the baseline always predates the photos being processed

Test plan

  • Run .\scripts\Rename-Photos.ps1 -WhatIf on a folder of unprocessed photos — confirm no files are renamed and no state is written
  • Run against a batch of photos; confirm logs/rename-state.json and logs/rename-log.json are written with correct entries
  • Re-run against the same folder (already renamed) — confirm script exits cleanly with 0 renamed
  • Simulate the regression: rename a batch of "newer" photos first, then run against a batch of "older" photos — confirm validation uses the pre-batch baseline, not the newer-batch state
  • Adjust OcrScalePercent in settings.json and confirm OCR behaviour changes accordingly
  • Run Pester suite: Invoke-Pester tests/

Logging:
- Replace per-run rename-log-{timestamp}.json with rename-state.json
  (small file, overwritten each run) and rename-log.json (append-only
  audit log, deduplicated on OriginalFile)
- Prior state loading uses a 3-level fallback: state file → audit log →
  output directory scan
- Add -StartOdometer parameter to seed odometer on first-ever run
- Remove $reportsDir, $logFile, and timestamped log approach

OCR:
- Add -ScalePct parameter to Get-OdometerReading; decode image at
  configurable percentage before OCR (default 25%)
- Thread OcrScalePercent setting through Add-OcrToPhotoContext and
  main body; reads from settings.json key OcrScalePercent

closes #22
… batch

All three file-based fallback levels (rename-state.json, rename-log.json,
directory scan) now ignore entries whose datetime is >= the earliest EXIF
datetime in the source batch. A batch ExifTool pre-pass collects that lower
bound before the fallback chain runs. Level 3 also now populates
lastGoodDateTime from the selected filename so time-bound validation works
after a directory-scan fallback.

Without this fix, processing a batch of older photos when newer photos are
already in the output folder would cause all readings to fail with
"Odometer decreased" because the baseline was pulled from a more recent run.
The -Source parameter was unconditionally overwritten by settings.json
Paths.Source, unlike every other parameter which checks
$PSBoundParameters.ContainsKey() first. Added the same guard so a
command-line -Source takes precedence over settings.

This caused the -WhatIf Pester test to silently run against the
settings-defined source folder instead of the empty temp folder passed
by the test.
When the source folder is empty the pipeline produces no output and the
variable is $null rather than an empty array. Accessing .Count on $null
throws PropertyNotFoundException. @() ensures an empty array in all cases.
@ndomako10
ndomako10 merged commit bd7b300 into main Apr 30, 2026
2 checks passed
@ndomako10
ndomako10 deleted the fix/temporal-baseline-filtering branch April 30, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant