Skip to content

fix: resolve import errors blocking tracker tests + add get_zones_for_point#86

Merged
Devnil434 merged 4 commits into
Devnil434:mainfrom
Saswat-Mpt:fix/tracker-method-indentation
May 21, 2026
Merged

fix: resolve import errors blocking tracker tests + add get_zones_for_point#86
Devnil434 merged 4 commits into
Devnil434:mainfrom
Saswat-Mpt:fix/tracker-method-indentation

Conversation

@Saswat-Mpt
Copy link
Copy Markdown
Contributor

@Saswat-Mpt Saswat-Mpt commented May 18, 2026

Problem

services/tracking/tracker.py imports get_zones_for_point from
services.detection.zones, but that function did not exist, causing
all tracker tests to fail with ImportError/AttributeError.

Root Cause

Three issues compounding each other:

  1. get_zones_for_point() missing from zones.py
  2. services/tracking/__init__.py was empty — broke @patch in tests
  3. services/__init__.py was empty — broke module resolution

Changes Made

File Change
services/detection/zones.py Added get_zones_for_point(x, y) with shapely point-in-polygon
services/tracking/__init__.py Exposed tracker module for test @patch resolution
services/__init__.py Exposed tracking subpackage for proper imports
.gitignore Added eagle_surveillance.egg-info/

Test Results

Screenshot 2026-05-18 144749

Closes #67

Summary by CodeRabbit

  • New Features

    • Zone definitions can be loaded from an external, configurable file and hot-reloaded; config path is overrideable via env var.
  • Behavior Changes

    • Zone matching may use an optional geometry library and will skip malformed polygons.
    • Per-track event history is now capped (50 events) and is trimmed/managed; expiring a track removes its stored events.
    • Zone entry counts are determined from explicit event hints.
  • Chores

    • Added ignore rules for Python caches, bytecode, and package metadata.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 394b9204-cef9-4b33-bc2f-a37c89826699

📥 Commits

Reviewing files that changed from the base of the PR and between 0df8c08 and f2b2229.

📒 Files selected for processing (5)
  • .gitignore
  • services/__init__.py
  • services/detection/zones.py
  • services/memory/memory.py
  • services/tracking/__init__.py

📝 Walkthrough

Walkthrough

Loads detection zones from YAML config with hot-reload and shapely-based point queries; exposes tracking exports at package init; simplifies MemoryService lifecycle and rewrites MemoryStore Redis keying and event-history behavior.

Changes

Zone System & Package Configuration

Layer / File(s) Summary
Build configuration
.gitignore
Ignores Python __pycache__/, *.pyc, and eagle_surveillance.egg-info/.
Package initializers export tracking
services/__init__.py, services/tracking/__init__.py
services now imports and exposes tracking; services.tracking re-exports tracker.
Zone configuration & point query
services/detection/zones.py
Start ZoneConfigLoader singleton, get_zones_for_point(x,y) uses optional shapely containment (returns lightweight _Zone results exposing .name), skips malformed polygons, and DEFAULT_ZONES aliases loader output (zone dicts).
MemoryService and MemoryStore rewrite
services/memory/memory.py
Remove anomaly/baseline logic from lifecycle, add schema/typing imports, change embeddings typing, rewrite MemoryStore Redis schema (per-track events lists + track->camera mapping), trim lists to MAX_EVENTS_PER_TRACK=50, set TTL, update get_sequence/get_zone_entry_count, and adjust expire_track to delete mapping and events list.

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Caller
  participant ZoneLoader as ZoneConfigLoader
  participant Config as config/zones.yaml
  participant Shapely as shapely (optional)
  participant Result as _Zone

  Caller->>ZoneLoader: get_zones()
  ZoneLoader->>Config: read definitions (ZONES_CONFIG_PATH)
  Config-->>ZoneLoader: zone dicts
  ZoneLoader-->>Caller: zone list

  Caller->>Shapely: polygon.contains(Point(x,y)) (if installed)
  Shapely-->>Caller: containment results
  Caller->>Result: wrap matches (_Zone.name)
  Result-->>Caller: matched zone names
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Devnil434/Eagle#86: Overlaps with the refactor of services/detection/zones.py and package tracking re-exports introduced in this PR.

Poem

"I nibble docs and tweak a key,
zones now know where rabbits be,
packages hum the tracking tune,
memory saves tales past the moon,
carrots and logs—preserved with glee." 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to services/memory/memory.py add imports, docstrings, and modify expire_track() functionality, which are out of scope for fixing tracker import errors per issue #67. Move services/memory/memory.py changes to a separate PR addressing CI lint and coverage issues, or clarify their necessity for resolving issue #67.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: fixing import errors blocking tracker tests and adding the get_zones_for_point function.
Linked Issues check ✅ Passed All acceptance criteria from issue #67 are met: update() and _cosine_similarity() belong to Tracker class, tracker.update() works without AttributeError, and all tracker tests pass.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% 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.

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

55-59: ⚡ Quick win

Use boundary-inclusive geometry predicate for zone membership checking.

Line 58 uses contains, which excludes boundary points. When points fall exactly on polygon edges, they are incorrectly treated as outside the zone, causing potential tracking edge flicker. Replace with covers to include boundary points.

Suggested change
-                if poly.contains(point):
+                if poly.covers(point):
                     # Return a lightweight object with .name attribute
🤖 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/zones.py` around lines 55 - 59, The loop that builds a
Polygon instance with poly = Polygon(zone["polygon"]) and checks membership
using poly.contains(point) excludes points on the polygon boundary; change the
predicate to poly.covers(point) so boundary points are treated as inside. Locate
the membership check (the poly.contains call) in the for zone in zones loop and
replace contains with covers, keeping the same Polygon construction and return
behavior (no other logic changes required).
🤖 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.

Nitpick comments:
In `@services/detection/zones.py`:
- Around line 55-59: The loop that builds a Polygon instance with poly =
Polygon(zone["polygon"]) and checks membership using poly.contains(point)
excludes points on the polygon boundary; change the predicate to
poly.covers(point) so boundary points are treated as inside. Locate the
membership check (the poly.contains call) in the for zone in zones loop and
replace contains with covers, keeping the same Polygon construction and return
behavior (no other logic changes required).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2bb79c91-bcd8-4172-aeb6-7abc1724da92

📥 Commits

Reviewing files that changed from the base of the PR and between 455e467 and 4feb566.

📒 Files selected for processing (4)
  • .gitignore
  • services/__init__.py
  • services/detection/zones.py
  • services/tracking/__init__.py

@Saswat-Mpt
Copy link
Copy Markdown
Contributor Author

Hi @Devnil434, The CI shows 2 pre-existing issues unrelated to this PR:

  1. Lint failureservices/memory/memory.py has undefined names
    (TrackEvent, TrackSequence, ActionHint) — not in my changed files.

  2. Docstring coverage at 50% — my zones.py has 100% docstring
    coverage; the gap comes from other files scanned by CI.

My changes (services/__init__.py, services/tracking/__init__.py,
services/detection/zones.py, .gitignore) fix all 15 tracker tests

Happy to work on the issues stated, if they haven’t already been assigned to someone else. Feel free to assign them to me!

@Devnil434 Devnil434 merged commit f282de7 into Devnil434:main May 21, 2026
0 of 2 checks passed
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.

[Bug] — tracker.py methods are outside the Tracker class

2 participants