summaryrefslogtreecommitdiff
path: root/src/lib/stats-aggregate.source.sh
AgeCommit message (Collapse)Author
2026-06-28Fix stats gauge bars rendering at width:0% (stats_category_max)Paul Buetow
Regression from or0 (STATS_* accessors): stats_category_max compared values via `(( _stats_counts_ref[key] > max ))`. For a nameref to an ASSOCIATIVE array, an arithmetic subscript is itself arithmetic-evaluated, so a string key (e.g. "sony") resolves to an unset variable -> 0, i.e. it always read index 0 and returned max 0. Every bar then scaled to width:0% (counts/percentages were unaffected, so only the bars looked broken). Read the value through a quoted ${assoc[$key]} expansion first, then compare. The byte-identical double-render test missed this because both renders were equally broken; added explicit non-zero bar-width assertions (100% / 50%) to test_render_stats_page_renders_sections_and_escapes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28or0: encapsulate STATS_* maps behind aggregator accessorsPaul Buetow
The stats reader modules (stats-render.source.sh, stats-filter-album.source.sh) indexed stats-aggregate.source.sh's private STATS_* associative arrays directly, so a key-convention change in the aggregator would silently break both readers. Add a read API owned by stats-aggregate.source.sh (the data owner), mirroring album-render's ALBUM_VIEW_PAGE_BY_PHOTO / album_view_page_for_photo split: stats_total_photos - STATS_TOTALS[photos] denominator stats_filter_pagebase - (prefix,label) -> pagebase, hiding the STATS_FILTER_KEYSEP catkey encoding stats_filter_title - STATS_FILTER_TITLE[pagebase] stats_filter_photos - STATS_FILTER_PHOTOS[pagebase] list stats_filter_count - number of filter mini-albums stats_filter_pagebases - pagebases, LC_ALL=C-sorted (order owned here) stats_category_count/size/max/keys_by_count_desc - per-category count-array reads Route every cross-module STATS_* read through these accessors. The render module's _stats_max_count / _stats_keys_by_count_desc were duplicates of the new stats_category_max / stats_category_keys_by_count_desc, so they are removed. Behavior preserved exactly: missing-key semantics, iteration order (ordered ladders, calendar months, count-desc with LC_ALL=C tie-break, sorted pagebase enqueue) and generated HTML are byte-identical. Header docs updated to describe the accessor boundary. The arrays stay the backing store; only the cross-module READ path is encapsulated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27stats: replace render_kind case with declare -F name dispatchPaul Buetow
_stats_render_category dispatched on render_kind via a four-arm case (camera|ranked|ordered|month), a modification magnet inconsistent with the codebase's other data-driven dispatch (the STATS_RECORD_FUNCTIONS registry and template.source.sh's prepare_template_render_var__<kind> declare -F lookup). Resolve the per-kind renderer by name instead: dispatch to _stats_render_section__<render_kind> via `declare -F`, guarded so a missing handler fails loudly (and so set -euo pipefail's errexit does not trip on declare -F's non-zero "absent" status). Rename the three section renderers to the _stats_render_section__{ranked,ordered,month} convention. Fold the camera kind into ranked: the camera leaderboard differed from an ordinary ranked section only by the extra 'stats-leaderboard' <ul> class -- data, not logic -- so it becomes a 'ranked' entry carrying that class in a new optional 5th spec field (list_class), eliminating the camera special case. Stats body output is byte-identical before/after for every render kind (verified via snapshot diff); the existing stats tests stay green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24Promote single canonical identify-stream EXIF parser into metadata-cache (8r0)Paul Buetow
The `identify -verbose` EXIF-line regex and its array-fill loop were duplicated in three places that had already drifted: album-metadata's photo_exif_details_html and _photo_exif_values_to (exif: only) and stats-aggregate's _stats_parse_identify_stream (exif: plus a native Geometry -> __geometry path). Promote one canonical parser, photo_exif_values_to, into metadata-cache.source.sh next to its sibling cache primitive cached_photo_identify_output. It reads an identify stream from stdin and fills a nameref associative array; it is a strict superset of all three former sites (bare exif: tag keys plus the synthetic __geometry key). - stats accumulate_photo_stats now calls photo_exif_values_to (stdin); _stats_parse_identify_stream is removed. - album _photo_exif_values_to is a thin wrapper that pipes cached_photo_identify_output through the canonical parser. - album photo_exif_details_html consumes the same parser and skips the __geometry key it does not display. metadata-cache is sourced before both consumers in LIB_SOURCES, so the canonical parser is available at use time. Regenerated bin/shuriken via `just build`. Added test_shared_identify_parser_returns_exif_and_geometry asserting one parse yields both an exif: key and __geometry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17pn0 decouple stats from album internalsPaul Buetow
Stats reached directly into album-module internals: the private global ALBUM_VIEW_PAGE_BY_PHOTO and the EXIF cache reader cached_photo_identify_output. Introduce a clean boundary, behaviour and generated HTML byte-identical. - Promote the EXIF identify cache primitive (cached_photo_identify_output plus its private helpers photo_cache_signature and print_cached_photo_identify_output) out of album-metadata.source.sh into a new shared src/lib/metadata-cache.source.sh, sourced before both album and stats (right after metadata-label in LIB_SOURCES). It is a low-level metadata primitive used by both consumers, so it no longer belongs to album internals. Signature/behaviour unchanged. - Add album_view_page_for_photo accessor in album-render.source.sh as the documented public API; keep ALBUM_VIEW_PAGE_BY_PHOTO as the album's private backing store. stats-filter-album.source.sh now calls the accessor instead of indexing the global, so a change to album page naming/caching stays contained in the album module. - Add test_album_stats_decoupling_boundary asserting the accessor returns the backing-store value and that the assembled bin/shuriken keeps the cache primitive in the shared module and no longer indexes the global from the stats filter section. Existing stats/album tests unchanged. Verified: 3-image fixture (STATS_PAGE=yes, fixed seed) diff -r of stashed original vs new build is byte-identical across all 47 dist files (only the inherent generated_at timestamp normalized). just test, just shellcheck, just check-generated and git diff --check all pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17en0: make stats categories self-registering via STATS_CATEGORIESPaul Buetow
Adding an EXIF stats category previously required editing four places: the reset function, a new _stats_record_*, the body builder, and a new _stats_render_* section. Introduce a STATS_CATEGORIES registry (the single source of truth) and make the generic code iterate it instead. - STATS_CATEGORIES: ordered, pipe-delimited specs (count_array|prefix|heading|render_kind), declared -gra so it survives a function-scoped source. The array order IS the overview display order. - STATS_CATEGORY_BUCKETS: tab-delimited bucket ladders for the 'ordered' histogram kinds (apertures wide->narrow, etc.). - STATS_RECORD_FUNCTIONS: the per-photo recorder dispatch list. Collapsed touch-points: - reset_photo_exif_stats clears each registry count array via _stats_category_arrays. - accumulate_photo_stats dispatches recorders from STATS_RECORD_FUNCTIONS. - _stats_build_body iterates STATS_CATEGORIES, dispatching each spec through _stats_render_category (camera/ranked/ordered/month kinds). - _stats_render_ordered_section reads its ladder from STATS_CATEGORY_BUCKETS; the camera leaderboard is now ranked + a 'stats-leaderboard' list_class. Adding a category is now: append one STATS_CATEGORIES entry (plus a STATS_CATEGORY_BUCKETS row for an ordered ladder) and have a record function tally into its array. No edits to reset, the body builder, or a per-category render branch. Behaviour-preserving: category order, bucket order, headings, counts and links are unchanged. Verified byte-identical by diffing the stats/ output of the pre-change binary against the new one over the same fixture album. Added test_stats_categories_registry_is_single_source_of_truth (registered in main()) asserting reset, the body builder and the bucket ladders all derive from the registry; it fails if a category is added in only one place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17mn0 share camera Make+Model dedup helperPaul Buetow
The rule that joins a camera's EXIF Make + Model into one label while avoiding a duplicated manufacturer prefix (e.g. "Canon Canon EOS 5D" -> "Canon EOS 5D") was implemented independently in the album tooltip builder and the stats leaderboard tally. Extract it into a single shared helper camera_label_from_make_model in the new src/lib/metadata-label.source.sh, sourced before both callers. Both prior implementations were behavior-identical (empty model -> make, empty make -> model, exact/prefix dedup, case-sensitive), so this is a pure DRY refactor with no observable output change. Added a focused unit test covering dedup, plain concatenation and the empty-field edge cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-16cn0 split stats.source.sh into aggregate/render/filter-album modulesPaul Buetow
Pure code move: split the ~1248-line stats.source.sh (SRP+SoC) into three cohesive modules, all functions and STATS_* constants/globals moved verbatim: - stats-aggregate.source.sh: EXIF parsing, bucketing, _stats_tally, reset/collect_photo_exif_stats and the STATS_* maps. - stats-render.source.sh: stats overview page (sections, bars, leaderboard, render_stats_page, _stats_build_body, _stats_filter_link, background pickers). - stats-filter-album.source.sh: per-filter mini-albums (render_filter_pages, gallery/view/thumbnail builders, _stats_enqueue_filter_album). Updated LIB_SOURCES accordingly. No logic change (verified: all 55 functions and top-level globals preserved; full suite, shellcheck, check-generated, diff all pass). The SoC point (HTML built in bash rather than templates) is left for a follow-up (nn0/qn0). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>