Created
September 18, 2020 16:44
-
-
Save rsmudge/49fb0a6a76a312cdd95666256265a64f to your computer and use it in GitHub Desktop.
Fire a beacon_revisited event when we get a checkin event that occurs some window of time (e.g., 60s here) after the last checkin event. Keep in mind checkin is only fired on task acknowledgement. If you set the window to 8 hours and don't interact with the Beacon for 8 hours--you'll fire revisited.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global('%checkins'); | |
on beacon_checkin { | |
local('$last'); | |
if ($1 in %checkins) { | |
$last = %checkins[$1]; | |
# has it been 1m since the last task acknowledgement? | |
if (($3 - $last) > 60000) { | |
fire_event("beacon_revisited", $1); | |
} | |
} | |
# store last checkin | |
%checkins[$1] = $3; | |
} | |
on beacon_revisited { | |
println("Beacon $1 is here!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could this be extended in some way to create working hours for a beacon?