mirror of
https://github.com/smittix/intercept.git
synced 2026-07-07 17:18:11 -07:00
style: apply ruff-format to entire codebase
First-time run of ruff-format via pre-commit hook normalises quote style, trailing commas, and whitespace across 188 Python files. No logic changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+40
-37
@@ -23,7 +23,7 @@ def haversine_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> fl
|
||||
def _ensure_table() -> None:
|
||||
"""Create geofence_zones table if it doesn't exist."""
|
||||
with get_db() as conn:
|
||||
conn.execute('''
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS geofence_zones (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
@@ -33,7 +33,7 @@ def _ensure_table() -> None:
|
||||
alert_on TEXT DEFAULT 'enter_exit',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
""")
|
||||
|
||||
|
||||
class GeofenceManager:
|
||||
@@ -46,30 +46,29 @@ class GeofenceManager:
|
||||
def list_zones(self) -> list[dict]:
|
||||
with get_db() as conn:
|
||||
cursor = conn.execute(
|
||||
'SELECT id, name, lat, lon, radius_m, alert_on, created_at FROM geofence_zones ORDER BY id'
|
||||
"SELECT id, name, lat, lon, radius_m, alert_on, created_at FROM geofence_zones ORDER BY id"
|
||||
)
|
||||
return [dict(row) for row in cursor]
|
||||
|
||||
def add_zone(self, name: str, lat: float, lon: float, radius_m: float,
|
||||
alert_on: str = 'enter_exit') -> int:
|
||||
def add_zone(self, name: str, lat: float, lon: float, radius_m: float, alert_on: str = "enter_exit") -> int:
|
||||
with get_db() as conn:
|
||||
cursor = conn.execute(
|
||||
'INSERT INTO geofence_zones (name, lat, lon, radius_m, alert_on) VALUES (?, ?, ?, ?, ?)',
|
||||
"INSERT INTO geofence_zones (name, lat, lon, radius_m, alert_on) VALUES (?, ?, ?, ?, ?)",
|
||||
(name, lat, lon, radius_m, alert_on),
|
||||
)
|
||||
return cursor.lastrowid
|
||||
|
||||
def delete_zone(self, zone_id: int) -> bool:
|
||||
with get_db() as conn:
|
||||
cursor = conn.execute('DELETE FROM geofence_zones WHERE id = ?', (zone_id,))
|
||||
cursor = conn.execute("DELETE FROM geofence_zones WHERE id = ?", (zone_id,))
|
||||
# Clean up inside tracking
|
||||
for entity_zones in self._inside.values():
|
||||
entity_zones.discard(zone_id)
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def check_position(self, entity_id: str, entity_type: str,
|
||||
lat: float, lon: float,
|
||||
metadata: dict[str, Any] | None = None) -> list[dict]:
|
||||
def check_position(
|
||||
self, entity_id: str, entity_type: str, lat: float, lon: float, metadata: dict[str, Any] | None = None
|
||||
) -> list[dict]:
|
||||
"""Check entity position against all zones. Returns list of events."""
|
||||
zones = self.list_zones()
|
||||
if not zones:
|
||||
@@ -80,36 +79,40 @@ class GeofenceManager:
|
||||
curr_inside: set[int] = set()
|
||||
|
||||
for zone in zones:
|
||||
dist = haversine_distance(lat, lon, zone['lat'], zone['lon'])
|
||||
zid = zone['id']
|
||||
if dist <= zone['radius_m']:
|
||||
dist = haversine_distance(lat, lon, zone["lat"], zone["lon"])
|
||||
zid = zone["id"]
|
||||
if dist <= zone["radius_m"]:
|
||||
curr_inside.add(zid)
|
||||
|
||||
if zid not in prev_inside and zone['alert_on'] in ('enter', 'enter_exit'):
|
||||
events.append({
|
||||
'type': 'geofence_enter',
|
||||
'zone_id': zid,
|
||||
'zone_name': zone['name'],
|
||||
'entity_id': entity_id,
|
||||
'entity_type': entity_type,
|
||||
'distance_m': round(dist, 1),
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
**(metadata or {}),
|
||||
})
|
||||
if zid not in prev_inside and zone["alert_on"] in ("enter", "enter_exit"):
|
||||
events.append(
|
||||
{
|
||||
"type": "geofence_enter",
|
||||
"zone_id": zid,
|
||||
"zone_name": zone["name"],
|
||||
"entity_id": entity_id,
|
||||
"entity_type": entity_type,
|
||||
"distance_m": round(dist, 1),
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
**(metadata or {}),
|
||||
}
|
||||
)
|
||||
else:
|
||||
if zid in prev_inside and zone['alert_on'] in ('exit', 'enter_exit'):
|
||||
events.append({
|
||||
'type': 'geofence_exit',
|
||||
'zone_id': zid,
|
||||
'zone_name': zone['name'],
|
||||
'entity_id': entity_id,
|
||||
'entity_type': entity_type,
|
||||
'distance_m': round(dist, 1),
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
**(metadata or {}),
|
||||
})
|
||||
if zid in prev_inside and zone["alert_on"] in ("exit", "enter_exit"):
|
||||
events.append(
|
||||
{
|
||||
"type": "geofence_exit",
|
||||
"zone_id": zid,
|
||||
"zone_name": zone["name"],
|
||||
"entity_id": entity_id,
|
||||
"entity_type": entity_type,
|
||||
"distance_m": round(dist, 1),
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
**(metadata or {}),
|
||||
}
|
||||
)
|
||||
|
||||
self._inside[entity_id] = curr_inside
|
||||
return events
|
||||
|
||||
Reference in New Issue
Block a user