Skip to content

docs: add Google-style docstrings to detection.py and tracker.py#78

Open
SiddharthRiot wants to merge 2 commits into
Devnil434:mainfrom
SiddharthRiot:fix/docstrings-detection-tracker
Open

docs: add Google-style docstrings to detection.py and tracker.py#78
SiddharthRiot wants to merge 2 commits into
Devnil434:mainfrom
SiddharthRiot:fix/docstrings-detection-tracker

Conversation

@SiddharthRiot
Copy link
Copy Markdown
Contributor

@SiddharthRiot SiddharthRiot commented May 16, 2026

Closes #4

Changes

  • Added Google-style docstrings to all public methods in services/detection/detection.py and services/tracking/tracker.py
  • All docstrings include Args, Returns, and Example sections
  • Fixed undefined names (DetectionFrameDetectionFrameSchema, DetectionDetectionSchema)
  • Fixed incorrect imports and removed unused variables
  • ruff check passes with no errors

Testing

python -m ruff check services/detection/detection.py services/tracking/tracker.py
All checks passed!

Summary by CodeRabbit

Release Notes

  • Improvements

    • Updated detection visualization to display bounding boxes, labels, confidence scores, and object centroids.
    • Streamlined detection output structure for cleaner integration.
    • Removed zone overlay feature from detection results.
    • Simplified CLI demo interface by removing advanced analysis features.
  • Documentation

    • Enhanced documentation for tracking and detection modules.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@SiddharthRiot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 28 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d4747815-9ebe-42a6-b95a-7de8324afcac

📥 Commits

Reviewing files that changed from the base of the PR and between 8b9277f and 7cb8d2a.

📒 Files selected for processing (1)
  • services/memory/memory.py
📝 Walkthrough

Walkthrough

The PR refactors detection output to use DetectionFrameSchema with BoundingBox coordinates and simplifies zone computation. Visualization is rewritten to render bounding boxes, labels, confidence, and centroids. The tracker module is enhanced with comprehensive docstrings and comment cleanup throughout public and private methods, with no signature or logic changes.

Changes

Detection Output Schema and Visualization Refactoring

Layer / File(s) Summary
Detection output schema and Detector interface
services/detection/detection.py
Detector.detect() now returns DetectionFrameSchema with per-detection DetectionSchema instances containing BoundingBox(x1, y1, x2, y2) plus label, confidence, and class_id; zone computation logic removed; module and class docstrings updated.
Detection visualization and CLI integration
services/detection/detection.py
draw_detections() rewritten to render bounding box rectangles, label+confidence text, and centroid markers from BoundingBox fields; zone polygon/HUD rendering removed; main() loop updated to draw and display annotated frames; frame width query added to stream logging.

Tracker Documentation Enhancement

Layer / File(s) Summary
Tracker class documentation and interfaces
services/tracking/tracker.py
Module docstring, sys.path insertion, and Tracker class/method signatures kept unchanged; __init__, update(), drain_lifecycle_events(), _emit_lifecycle(), and _cosine_similarity() gain expanded Google-style docstrings with parameters and return types; section divider comments simplified or removed throughout tracking logic; main() docstring and CLI window title formatting updated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #4: Write docstrings for detector.py and tracker.py — This PR partially addresses the issue by adding docstrings to services/tracking/tracker.py and expanding module/class documentation in services/detection/detection.py, though the issue title references detector.py while the changes touch detection.py.

Poem

A detector sees through OpenCV's lens,
With bounding boxes crisp and dense,
The tracker dances, step by step,
While docstrings guide the developer's prep,
🐰 Code clean, comments wise, the vision glows bright!

🚥 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 accurately reflects the main change: adding Google-style docstrings to detection.py and tracker.py as stated in the PR objectives.
Linked Issues check ✅ Passed The PR addresses issue #4 by adding Google-style docstrings with Args and Returns sections, fixing undefined names (DetectionFrame→DetectionFrameSchema, Detection→DetectionSchema), and passing ruff checks.
Out of Scope Changes check ✅ Passed The changes are limited to adding docstrings, fixing type references, and minor documentation updates directly aligned with issue #4 requirements; no extraneous modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
services/detection/detection.py (1)

31-33: ⚡ Quick win

Remove stale zone-membership work from detect() and align the docstrings with the actual return contract.

get_zones_for_point(cx, cy) is executed per detection and discarded, so this adds avoidable work in a hot loop. At the same time, the docstrings still claim zone memberships are part of returned detections, which no longer matches the constructed DetectionSchema.

Proposed cleanup
-from services.detection.zones import DEFAULT_ZONES, get_zones_for_point
+from services.detection.zones import DEFAULT_ZONES
@@
-    DetectionFrameSchema objects with bounding boxes, labels, confidence
-    scores, and zone memberships.
+    DetectionFrameSchema objects with bounding boxes, labels, and confidence
+    scores.
@@
-            DetectionFrameSchema with all detected objects and zone memberships.
+            DetectionFrameSchema with all detected objects.
@@
-            _ = [z.name for z in get_zones_for_point(cx, cy)]
-
             detections.append(DetectionSchema(

Also applies to: 71-72, 92-93

🤖 Prompt for 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.

In `@services/detection/detection.py` around lines 31 - 33, The detect() function
still calls get_zones_for_point(cx, cy) per detection and mentions zone
memberships in its docstring even though returned objects are
DetectionSchema/DetectionFrameSchema without zone data; remove the per-detection
get_zones_for_point call and any unused zone-handling variables from detect(),
update the detect() and related docstrings to reflect that detections no longer
include zone memberships (only bounding boxes, labels, and confidence), and
ensure DetectionFrameSchema/DetectionSchema construction matches the docstrings;
search for and remove the same stale calls/comments around the other noted
locations (lines ~71-72 and ~92-93) so the implementation and docs are
consistent.
🤖 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 `@services/tracking/tracker.py`:
- Around line 317-318: The docstring for the cosine similarity function
(cosine_similarity) incorrectly states the return range as [0, 1]; update it to
reflect the true range of cosine similarity: "Float in [-1, 1] representing
similarity; 0.0 if either norm is zero." Modify the docstring text in tracker.py
(the cosine_similarity function) to use [-1, 1] and keep the note about the
zero-norm early return.

---

Nitpick comments:
In `@services/detection/detection.py`:
- Around line 31-33: The detect() function still calls get_zones_for_point(cx,
cy) per detection and mentions zone memberships in its docstring even though
returned objects are DetectionSchema/DetectionFrameSchema without zone data;
remove the per-detection get_zones_for_point call and any unused zone-handling
variables from detect(), update the detect() and related docstrings to reflect
that detections no longer include zone memberships (only bounding boxes, labels,
and confidence), and ensure DetectionFrameSchema/DetectionSchema construction
matches the docstrings; search for and remove the same stale calls/comments
around the other noted locations (lines ~71-72 and ~92-93) so the implementation
and docs are consistent.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5306bbbb-8977-4efd-ac30-11a09042a5f0

📥 Commits

Reviewing files that changed from the base of the PR and between 29a47a7 and 8b9277f.

📒 Files selected for processing (2)
  • services/detection/detection.py
  • services/tracking/tracker.py

Comment on lines +317 to +318
Float in [0, 1] representing similarity; 0.0 if either norm is zero.
"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix incorrect cosine similarity return range in docstring.

Line 317 says similarity is in [0, 1], but cosine similarity is typically in [-1, 1] (except zero-norm early return). Please update the docstring range to match the implementation.

Suggested docstring fix
-            Float in [0, 1] representing similarity; 0.0 if either norm is zero.
+            Float in [-1, 1] representing similarity; 0.0 if either norm is zero.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Float in [0, 1] representing similarity; 0.0 if either norm is zero.
"""
Float in [-1, 1] representing similarity; 0.0 if either norm is zero.
"""
🤖 Prompt for 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.

In `@services/tracking/tracker.py` around lines 317 - 318, The docstring for the
cosine similarity function (cosine_similarity) incorrectly states the return
range as [0, 1]; update it to reflect the true range of cosine similarity:
"Float in [-1, 1] representing similarity; 0.0 if either norm is zero." Modify
the docstring text in tracker.py (the cosine_similarity function) to use [-1, 1]
and keep the note about the zero-norm early return.

@SiddharthRiot
Copy link
Copy Markdown
Contributor Author

Hey @Devnil434, the CI failure is not related to my changes. The lint check passes successfully. the test job fails due to missing pytest-cov dependency in GitHub actions workflow (--cov flag is unrecognized). This is a pre-existing issue in the repo. happy to fix the workflow if needed, just let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write docstrings for detector.py and tracker.py

2 participants