Some more fixes
This commit is contained in:
@@ -58,6 +58,10 @@ class FrigateCounter:
|
|||||||
self.counter_lock = threading.Lock()
|
self.counter_lock = threading.Lock()
|
||||||
self.seen_objects = {}
|
self.seen_objects = {}
|
||||||
|
|
||||||
|
# State pintu tracking
|
||||||
|
self.timer_active_pintu = False
|
||||||
|
self.timer_start_time_pintu = None
|
||||||
|
|
||||||
# Load previous counter value on startup
|
# Load previous counter value on startup
|
||||||
self.load_previous_counter()
|
self.load_previous_counter()
|
||||||
|
|
||||||
@@ -219,6 +223,21 @@ class FrigateCounter:
|
|||||||
"""Check if both pintu-kiri-buka and pintu-kanan-buka have been detected"""
|
"""Check if both pintu-kiri-buka and pintu-kanan-buka have been detected"""
|
||||||
if self.pintu_kiri_buka_detected and self.pintu_kanan_buka_detected:
|
if self.pintu_kiri_buka_detected and self.pintu_kanan_buka_detected:
|
||||||
self.start_timer()
|
self.start_timer()
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.timer_active_pintu:
|
||||||
|
self.start_timer_pintu()
|
||||||
|
|
||||||
|
def start_timer_pintu(self):
|
||||||
|
"""Start the 5-minute timer Pintu"""
|
||||||
|
logger.info("Starting 5-minute timer Pintu")
|
||||||
|
self.timer_active_pintu = True
|
||||||
|
self.timer_start_time_pintu = datetime.now()
|
||||||
|
|
||||||
|
# Schedule timer expiration check
|
||||||
|
timer_thread = threading.Thread(target=self.check_timer_expiration_pintu)
|
||||||
|
timer_thread.daemon = True
|
||||||
|
timer_thread.start()
|
||||||
|
|
||||||
def start_timer(self):
|
def start_timer(self):
|
||||||
"""Start the 30-minute timer"""
|
"""Start the 30-minute timer"""
|
||||||
@@ -235,6 +254,16 @@ class FrigateCounter:
|
|||||||
self.pintu_kiri_buka_detected = False
|
self.pintu_kiri_buka_detected = False
|
||||||
self.pintu_kanan_buka_detected = False
|
self.pintu_kanan_buka_detected = False
|
||||||
|
|
||||||
|
def check_timer_expiration_pintu(self):
|
||||||
|
"""Check if timer has expired (5 minutes)"""
|
||||||
|
time.sleep(5 * 60) # Wait 5 minutes
|
||||||
|
|
||||||
|
if self.timer_active_pintu:
|
||||||
|
logger.info("Timer Pintu expired (5 minutes)")
|
||||||
|
self.timer_active_pintu = False
|
||||||
|
self.pintu_kiri_buka_detected = False
|
||||||
|
self.pintu_kanan_buka_detected = False
|
||||||
|
|
||||||
def check_timer_expiration(self):
|
def check_timer_expiration(self):
|
||||||
"""Check if timer has expired (30 minutes)"""
|
"""Check if timer has expired (30 minutes)"""
|
||||||
time.sleep(30 * 60) # Wait 30 minutes
|
time.sleep(30 * 60) # Wait 30 minutes
|
||||||
@@ -276,7 +305,7 @@ class FrigateCounter:
|
|||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
INSERT INTO karung_counts (camera_name, date, counter_value)
|
INSERT INTO karung_counts (camera_name, date, counter_value)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
''', ('frigate_camera', date.today(), self.counter))
|
''', (self.camera_name, date.today(), self.counter))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
logger.info(f"Saved counter result to database: {self.counter}")
|
logger.info(f"Saved counter result to database: {self.counter}")
|
||||||
@@ -285,7 +314,7 @@ class FrigateCounter:
|
|||||||
# Ensure we don't lose data due to database errors
|
# Ensure we don't lose data due to database errors
|
||||||
# We should still try to save to JSON as backup
|
# We should still try to save to JSON as backup
|
||||||
try:
|
try:
|
||||||
self.save_to_json('frigate_camera')
|
self.save_to_json(self.camera_name)
|
||||||
logger.info("Fallback save to JSON successful")
|
logger.info("Fallback save to JSON successful")
|
||||||
except Exception as e2:
|
except Exception as e2:
|
||||||
logger.error(f"Fallback save to JSON also failed: {e2}")
|
logger.error(f"Fallback save to JSON also failed: {e2}")
|
||||||
|
|||||||
Reference in New Issue
Block a user