Debug Entry-Exit Tracking System

Job ID: 39302459

Budget: $10 – $30 USD

My project is an employee entrance and exit project. It is written in python and hosted on a server. It uses a custom machine learning model to detect the employees and logs their entry and exit times. The project is nearly complete but I am facing problem with the logic of how it counts the entry and exit of the employees. Your task would be to only fix the method that counts them. I will show the code below, right now it only detects one departure and doesn't count anything else.
The code:
def handle_employee_movement(self, track_id, bbox, employee_type):
x1, y1, x2, y2 = bbox
cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
point = (int(cx), int(cy))

in_area3 = cv2.pointPolygonTest(self.areas['area3'], point, False) >= 0
in_area4 = cv2.pointPolygonTest(self.areas['area4'], point, False) >= 0

entry_logged = False
exit_logged = False

if in_area3 and track_id not in self.enter2 and track_id not in self.counted_enter2:
self.enter2.append(track_id)

if in_area4 and track_id in self.enter2 and track_id not in self.counted_enter2:
self.counted_enter2.add(track_id)
self.log_employee_entry(employee_type)
logger.info(f"[ENTRY] Employee {track_id} moved from area3 → area4")
entry_logged = True

if in_area4 and track_id not in self.exit2 and track_id not in self.counted_exit2:
self.exit2.append(track_id)

if in_area3 and track_id in self.exit2 and track_id not in self.counted_exit2:
self.counted_exit2.add(track_id)
self.log_employee_exit(employee_type)
logger.info(f"[EXIT] Employee {track_id} moved from area4 → area3")
exit_logged = True

# === Cleaning logic ===
if entry_logged or exit_logged:
if track_id in self.enter2:
self.enter2.remove(track_id)
if track_id in self.exit2:
self.exit2.remove(track_id)
self.counted_enter2.discard(track_id)
self.counted_exit2.discard(track_id)
Related categories: Python Software Testing