tidwall / tile38

Real-time Geospatial and Geofencing
https://tile38.com
MIT License
9.09k stars 569 forks source link

SETCHAN with FENCE DETECT inside,outside doesn't work as expected #703

Closed EmersonLopes closed 1 year ago

EmersonLopes commented 1 year ago

The bug occurs when I create a channel for ford brand cars only, but the channel is showing cars from other brands as well

Create "channelFord" channel only for ford brand cars

SETCHAN channelFord INTERSECTS cars WHERE info.brand == 'ford' FENCE DETECT inside,outside OBJECT {"type":"Polygon","coordinates":[[[-87.6875402606167,41.91766993152294],[-87.6875402606167,41.91053637115587],[-87.67749935516063,41.91053637115587],[-87.67749935516063,41.91766993152294],[-87.6875402606167,41.91766993152294]]]}

subscribe in channel

SUBSCRIBE channelFord

SET inside

SET cars ABC1234 FIELD info {"brand":"ford","year":"2010"} POINT 41.91323014924143 -87.68240968749839
SET cars DEF5678 FIELD info {"brand":"bmw","year":"2012"} POINT 41.91323014924143 -87.68240968749839

SET outside

SET cars ABC1234 POINT 41.90930071720268 -87.68233201750633
SET cars DEF5678 POINT 41.90930071720268 -87.68233201750633

the result of subcribe

{"ok":true,"command":"subscribe","channel":"channelFord","num":1,"elapsed":"6.972µs"}
{"command":"set","group":"64ee4467552d5e0001eb6cdd","detect":"inside","hook":"channelFord","key":"cars","time":"2023-08-29T19:17:59.188812826Z","id":"ABC1234","object":{"type":"Point","coordinates":[-87.68240968749839,41.91323014924143]},"fields":{"info":{"brand":"ford","year":"2010"}}}
{"command":"set","group":"64ee4468552d5e0001eb6cdf","detect":"outside","hook":"channelFord","key":"cars","time":"2023-08-29T19:18:00.421592342Z","id":"DEF5678","object":{"type":"Point","coordinates":[-87.68240968749839,41.91323014924143]},"fields":{"info":{"brand":"bmw","year":"2012"}}}
{"command":"set","group":"64ee4467552d5e0001eb6cdd","detect":"outside","hook":"channelFord","key":"cars","time":"2023-08-29T19:18:17.522848886Z","id":"ABC1234","object":{"type":"Point","coordinates":[-87.68233201750633,41.90930071720268]},"fields":{"info":{"brand":"ford","year":"2010"}}}
{"command":"set","group":"64ee4468552d5e0001eb6cdf","detect":"outside","hook":"channelFord","key":"cars","time":"2023-08-29T19:18:18.375318778Z","id":"DEF5678","object":{"type":"Point","coordinates":[-87.68233201750633,41.90930071720268]},"fields":{"info":{"brand":"bmw","year":"2012"}}}

The expected result was that only Ford cars were captured in the canal.

Help

Did I do something wrong? Help me please

iwpnd commented 1 year ago

Try

SETCHAN channelFord INTERSECTS cars WHERE 'info.brand == "ford"' FENCE DETECT inside,outside [...]
EmersonLopes commented 1 year ago

Try

SETCHAN channelFord INTERSECTS cars WHERE 'info.brand == "ford"' FENCE DETECT inside,outside [...]

With this command the result was the same

tidwall commented 1 year ago

The WHERE clause is considered to be part of the geofence constraint.

Basically the INTERSECTS command you are providing says:

For all cars that are inside of the provided polygon and are a ford, send an "inside" event, otherwise send an "outside" event.

Perhaps using "enter,exit" instead of "inside,outside" will give you better results, because an "exit" event cannot happen unless the car was previously considered inside.

iwpnd commented 1 year ago

My bad, I overlooked your inside,outside

Using a channel like so:

SETCHAN channelFord INTERSECTS cars WHERE 'info.brand == "ford"' FENCE DETECT enter,exit OBJECT {"type":"Polygon","coordinates":[[[-87.6875402606167,41.91766993152294],[-87.6875402606167,41.91053637115587],[-87.67749935516063,41.91053637115587],[-87.67749935516063,41.91766993152294],[-87.6875402606167,41.91766993152294]]]}

works as expected on ford vehicles, but ignores everything else.

>> 127.0.0.1:9851> SET cars ABC1234 FIELD info {"brand":"ford","year":"2010"} POINT 41.91323014924143 -87.68240968749839
>> {"ok":true,"elapsed":"1.109292ms"}
>> {"command":"set","group":"64ef2d1716fcd30001286d1d","detect":"enter","hook":"channelFord","key":"cars","time":"2023-08-30T11:50:46.999727689Z","id":"ABC1234","object":{"type":"Point","coordinates":[-87.68240968749839,41.91323014924143]},"fields":{"info":{"brand":"ford","year":"2010"}}}
>> SET cars DEF5678 FIELD info {"brand":"bmw","year":"2012"} POINT 41.91323014924143 -87.68240968749839
{"ok":true,"elapsed":"235.875µs"}
>> 
EmersonLopes commented 1 year ago

Got it, thanks for the help guys. Enter, exit really works I will use enter, exit