zone_dwell_reader data action reads zone dwell events from the local RESDB SQLite database. It executes custom SELECT queries and returns matching records for downstream actions to process.
What it does
The zone dwell reader:- Accepts custom SELECT queries via
feature_variables.select_query - Validates query safety to prevent write operations (INSERT, UPDATE, DELETE)
- Executes the query against the
zone_dwell_eventstable - Parses JSON columns like
attachments,detection_result, andextra_info - Calculates ongoing duration for records without exit times
- Returns all matching records in a single response
Requirements
| Requirement | Description |
|---|---|
| select_query | A valid SELECT query in feature_variables. Required. |
| RESDB database | The local SQLite database must be initialized |
Configuration
Configure the action throughfeature_variables on the action detail:
| Variable | Type | Required | Description |
|---|---|---|---|
select_query | string | Yes | Full SELECT query to execute |
Available columns
Thezone_dwell_events table contains these columns:
| Column | Type | Description |
|---|---|---|
id | integer | Auto-incrementing primary key |
timestamp | datetime | When the event was recorded |
camera_name | text | Name of the camera/stream |
tracked_object_id | text | Stable ID for the tracked object |
zone_name | text | Name of the detection zone |
entry_time | datetime | When the object entered the zone |
exit_time | datetime | When the object exited (NULL if ongoing) |
duration_seconds | real | Time spent in zone (NULL if ongoing) |
is_read | boolean | Whether the record has been processed |
model_label_id | integer | Detection model label ID |
created_at | datetime | Database insertion timestamp |
branch_id | integer | Associated branch ID |
stream_id | integer | Associated stream ID |
stream_zone_id | integer | Associated stream zone ID |
is_violated | boolean | Whether a violation was created |
attachments | text (JSON) | Array of ResultAttachment objects |
detection_result | text (JSON) | Detection metadata |
extra_info | text (JSON) | Additional data (including violated_branch_rules) |
Example queries
Query ongoing dwell events
Find people who have been in a zone for more than 60 seconds and haven’t left yet: Query:Query completed dwell events by duration
Find completed visits that lasted between 5 and 30 minutes: Query:Query events with attachments
Find recent events that have captured frames attached: Query:Query by zone and stream
Find events in a specific zone from a specific camera: Query:Query unprocessed events
Find events that haven’t been used for violations yet: Query:Query events not violated by specific rule
Find events that haven’t been processed by a specific branch rule: Query:Result format
Success with records
| Field | Value |
|---|---|
is_success | true |
feature_result | records_found |
note | ”Found X zone dwell records” |
extras.records | Array of record objects |
extras.total_records | Number of records returned |
extras.query_used | The executed query (truncated if long) |
extras.columns | Array of column names |
No records found
| Field | Value |
|---|---|
is_success | true |
feature_result | no_records_found |
note | ”No zone dwell records found matching criteria” |
extras.records | Empty array |
extras.total_records | 0 |
Record structure
Each record inextras.records contains:
| Field | Description |
|---|---|
| All database columns | Original column values |
record_id | Copy of id for convenience |
is_ongoing | true if exit_time is NULL |
duration_seconds | Calculated from entry_time to now if ongoing |
attachments | Parsed JSON array (if present) |
detection_result | Parsed JSON object (if present) |
extra_info | Parsed JSON object (if present) |
Possible errors
No query provided
No query provided
Error:
no_query_providedWhat happened: The select_query feature variable was not set.How to fix: Add a select_query to the action’s feature_variables configuration.Invalid query
Invalid query
Error:
invalid_queryWhat happened: The query doesn’t start with SELECT or contains forbidden keywords.How to fix:- Ensure query starts with SELECT
- Remove any INSERT, UPDATE, DELETE, DROP, or other write statements
- Use only single statements (no semicolons for multiple statements)
Database error
Database error
Error:
errorWhat happened: SQL execution failed due to syntax error or database issue.How to fix:- Verify SQL syntax is valid SQLite
- Check column names exist in the table
- Ensure database file is accessible
Workflow integration
The zone dwell reader is typically used as the first step in a violation workflow:- zone_dwell_reader queries for events matching violation criteria
- zone_dwell_violation_snapshot annotates frames from the records
- create_violation creates violation records from the prepared attachments
The zone dwell reader returns all matching records in a single response. Downstream actions should iterate through
extras.records to process each record.