Skip to content

Surface staffline rhythm diagnostics + close text-batch staffline gap - #154

Merged
kyrieb-ekat merged 3 commits into
mainfrom
kyrie/staffline-rhythm-chart-and-batch-fix
Aug 5, 2026
Merged

Surface staffline rhythm diagnostics + close text-batch staffline gap#154
kyrieb-ekat merged 3 commits into
mainfrom
kyrie/staffline-rhythm-chart-and-batch-fix

Conversation

@kyrieb-ekat

@kyrieb-ekat kyrieb-ekat commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a client-side "rhythm" gap-distribution chart to StafflineViewerModal.tsx, reconstructing the diagnostic group_staves.py computes server-side (previously only visible via run_page.py's own matplotlib output, never through the landing-page pipeline). No new backend storage -- computed from the already-stored JSOMR JSON.
  • Closes a known gap (documented in documentation_allons-y/STAFFLINE_INTEGRATION_FOLLOWUPS.md): tasks_text_batch.py's independent YOLO pass (backing /text-batch/run, the Cantus-aligned batch path) never called staffline_stage.py, so images processed only through it got no staffline_detections row. Now mirrors tasks_predict.py's existing has_class -> run_staffline_detection block.

Context

Local main had fallen behind origin/main by the whole staffline integration (staffline_stage.py, the StafflinesTab UI, etc. all already existed upstream), which is what looked like nothing was wired up. This PR is the follow-up work once synced: filling in the two real gaps that remained.

Changes

  • landing-page/src/lib/rhythmGaps.ts (new): per-stave consecutive-line gap computation + noise-floor/cut-threshold/max-interp-gap reference values, mirroring group_staves.py's multipliers.
  • landing-page/src/components/project/RhythmChart.tsx (new): inline-SVG bar chart rendering the above.
  • landing-page/src/components/project/StafflineViewerModal.tsx: overlay/rhythm tab toggle.
  • landing-page/src/types.ts: added missing scale_unit field to JsomrLineRecord (already sent by the backend, just untyped).
  • landing-page/scripts/tasks_text_batch.py: runs staffline detection after YOLO layer-separation, same as the predict-job path.

Verification

  • tsc --noEmit clean.
  • eslint on changed files: only the 2 pre-existing warnings/errors that were already there before this change (confirmed via stash diff), nothing new.
  • landing-page/scripts/tests/test_staffline_adapter.py: 7/7 pass.
  • Not yet run end-to-end through the live app (needs a real DB/Celery/browser session) -- worth doing before merge.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a Rhythm view to the staffline viewer, with charts showing spacing gaps, anomaly indicators, thresholds, and reference limits.
    • Added tabbed Overlay and Rhythm views when rhythm data is available.
    • Added rhythm-gap diagnostics based on assigned line data.
  • Bug Fixes

    • Improved staffline detection processing and event reporting during image analysis.
    • Preserved existing annotation, masking, music-box, and progress tracking behaviour.

Surfaces the gap-distribution diagnostic group_staves.py computes server-side (previously only visible via run_page.py's own matplotlib output, never through the landing-page pipeline). Computed client-side from the already-stored JSOMR JSON via a new rhythmGaps.ts helper, rendered with a new inline-SVG RhythmChart component -- no new backend storage. Added the missing scale_unit field to JsomrLineRecord in types.ts (already sent by the backend, just not typed).
tasks_text_batch.py (the Celery task backing /text-batch/run, the Cantus-aligned batch text-finding path) runs its own independent YOLO layer-separation pass and previously never called staffline_stage.py, so images processed only through it got no staffline_detections row -- a known gap flagged in documentation_allons-y/STAFFLINE_INTEGRATION_FOLLOWUPS.md. Mirrors tasks_predict.py's existing has_class -> run_staffline_detection block, right after write_annotation().
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kyrieb-ekat, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c9061ec-4369-418b-827a-1e302b195a52

📥 Commits

Reviewing files that changed from the base of the PR and between 916f465 and 9e85be1.

📒 Files selected for processing (1)
  • landing-page/src/components/project/RhythmChart.tsx
📝 Walkthrough

Walkthrough

Changes

Staffline processing and rhythm diagnostics

Layer / File(s) Summary
Staffline detection pipeline
landing-page/scripts/tasks_text_batch.py
The text-batch pipeline runs staffline detection when YOLO identifies the staffline class. It publishes detection events and logs detection errors.
Rhythm-gap computation
landing-page/src/types.ts, landing-page/src/lib/rhythmGaps.ts
JsomrLineRecord now requires scale_unit. New logic computes stave gaps, anomaly flags, thresholds, and interpolation limits.
Rhythm viewer integration
landing-page/src/components/project/StafflineViewerModal.tsx, landing-page/src/components/project/RhythmChart.tsx
The modal adds Overlay and Rhythm tabs. The Rhythm tab renders an SVG chart with gap bars, reference lines, labels, and a legend.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TextBatchPipeline
  participant YOLO
  participant StafflineDetector
  participant EventPublisher
  TextBatchPipeline->>YOLO: Run image inference
  TextBatchPipeline->>StafflineDetector: Detect stafflines when the class is present
  StafflineDetector-->>TextBatchPipeline: Return events or an error
  TextBatchPipeline->>EventPublisher: Publish events or log errors
Loading
sequenceDiagram
  participant StafflineViewerModal
  participant computeRhythmGaps
  participant RhythmChart
  StafflineViewerModal->>computeRhythmGaps: Provide ready line records
  computeRhythmGaps-->>StafflineViewerModal: Return rhythm summary
  StafflineViewerModal->>RhythmChart: Render the Rhythm tab
  RhythmChart-->>StafflineViewerModal: Display the SVG chart
Loading

Possibly related PRs

  • DDMAL/mothra#53: Updates a related prediction pipeline to invoke staffline detection and process its results.

Suggested reviewers: giannatan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies both main changes: staffline rhythm diagnostics and staffline detection in the text-batch workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kyrie/staffline-rhythm-chart-and-batch-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@landing-page/scripts/tasks_text_batch.py`:
- Around line 90-93: Update the staffline-detection handling around
run_staffline_detection so error events are published unchanged to
publish_event, preserving their type: "error" and the resulting failed job
status. Only retain the log conversion if the text-batch event contract
explicitly treats staffline failures as non-fatal.

In `@landing-page/src/components/project/RhythmChart.tsx`:
- Around line 106-118: Update the legend spans in RhythmChart’s chart legend to
replace each fixed-color inline style with Tailwind arbitrary color utility
classes, using the existing NOISE_FLOOR_COLOR, CUT_THRESHOLD_COLOR,
MAX_INTERP_COLOR, and ANOMALY_COLOR values. Remove the corresponding style props
while preserving the legend text and layout.
- Around line 39-104: Update the SVG rendered by RhythmChart to include an
accessible title and description or equivalent screen-reader data summary
describing the chart and its bar values. In the bars mapping, preserve the
anomaly color while adding a non-color visual indicator such as a distinct
stroke, pattern, or label whenever b.isAnomalous is true.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 16af9a08-d752-4ba0-a94e-d89438b20966

📥 Commits

Reviewing files that changed from the base of the PR and between df2da22 and 916f465.

📒 Files selected for processing (5)
  • landing-page/scripts/tasks_text_batch.py
  • landing-page/src/components/project/RhythmChart.tsx
  • landing-page/src/components/project/StafflineViewerModal.tsx
  • landing-page/src/lib/rhythmGaps.ts
  • landing-page/src/types.ts

Comment thread landing-page/scripts/tasks_text_batch.py
Comment thread landing-page/src/components/project/RhythmChart.tsx
Comment thread landing-page/src/components/project/RhythmChart.tsx
- RhythmChart.tsx: add an SVG <title>/<desc> (page-level and per-bar) so the chart has an accessible name/data summary, and give anomalous bars a dark stroke outline so they are distinguishable without relying on color alone.
- RhythmChart.tsx: replace the legend's inline style={{color:...}} props with Tailwind arbitrary-value classes, per this repo's Tailwind-only styling rule (CLAUDE.md).

Left the third finding (tasks_text_batch.py:93, staffline errors downgraded from type:error to type:log before publish_event) as-is with a reply explaining it -- this is the exact existing pattern tasks_predict.py already uses (job_store.publish_event flips the whole job to failed on any type:error event, and a per-image staffline hiccup already gets its own status=failed row in staffline_detections, so it deliberately shouldn't fail the entire predict/text-batch job).
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