CEL Esper - Event Porcessing

Hello,
I have a problem that I can’t solve.
I created an event to calculate how many devices have in each place and how many are in transit, it works correctly until a certain moment, when two or more devices trigger the event at the same time or in a very short period the calculation goes wrong.
Follow the code below:



/***********************************************************************************************************************************/
/*                                                                                                                                 */
/*    Every time the update is made to the Manageable Object of a property, if it is an object, it is necessary to include all the */ 
/*    fields of the same, otherwise they are excluded                                                                              */
/*                                                                                                                                 */
/***********************************************************************************************************************************/
create constant variable string id_folder = "11246847";

/*get the manageable object*/
create schema MyObject(
  object ManagedObject,
  alarmType string
);

@Name("GetObject")
@Resilient
insert into MyObject
select 
     findManagedObjectById(id_folder) as object,
     getString(a, "type") as alarmType
from AlarmCreated a
where (getString(a, "type") = "c8y_Geo-VW-SBC-Entering"
    or getString(a, "type") = "c8y_Geo-VW-SBC-Leaving"
    or getString(a, "type") = "c8y_Geo-VW-SC-Entering"
    or getString(a, "type") = "c8y_Geo-VW-SC-Leaving")
    and (getString(a, "status") = "ACTIVE");

/*********************************************************************************************************************************/

/********************************************            TEST            *********************************************************

insert into UpdateManagedObject
select
  id_folder as id,
  {
    "VW-São_Bernardo_do_Campo", getNumber(mo, "object.VW-São_Bernardo_do_Campo")+1,
    "VW-São_Carlos", getNumber(mo, "object.VW-São_Carlos"),
    "OnCarriage", getNumber(mo, "object.OnCarriage")-1
  } as fragments 
from MyObject mo
where getString(mo, "alarmType") = "c8y_Geo-VW-SBC-Entering";

********************************************            TEST            *********************************************************/

/*********************************************************************************************************************************/

@Name("SBC-Entering")
@Resilient
insert into UpdateManagedObject
select
  id_folder as id,
  {
    
    "VW-São_Bernardo_do_Campo", getNumber(mo, "object.VW-São_Bernardo_do_Campo")+1,
    "OnCarriage", getNumber(mo, "object.OnCarriage")-1
    
  } as fragments 
from MyObject mo
where getString(mo, "alarmType") = "c8y_Geo-VW-SBC-Entering";

/*********************************************************************************************************************************/

@Name("SC-Entering")
@Resilient
insert into UpdateManagedObject
select
  id_folder as id,
  {
    
    "VW-São_Carlos", getNumber(mo, "object.VW-São_Carlos")+1,
    "OnCarriage", getNumber(mo, "object.OnCarriage")-1
    
  } as fragments
from MyObject mo
where getString(mo, "alarmType") = "c8y_Geo-VW-SC-Entering";

/*********************************************************************************************************************************/

@Name("SBC-Leaving")
@Resilient
insert into UpdateManagedObject
select
  id_folder as id,
  {
    
    "VW-São_Bernardo_do_Campo", getNumber(mo, "object.VW-São_Bernardo_do_Campo")-1,
    "OnCarriage", getNumber(mo, "object.OnCarriage")+1
    
  } as fragments 
from MyObject mo
where getString(mo, "alarmType") = "c8y_Geo-VW-SBC-Leaving";

/*********************************************************************************************************************************/

@Name("SC-Leaving")
@Resilient
insert into UpdateManagedObject
select
  id_folder as id,
  {
  
    "VW-São_Carlos", getNumber(mo, "object.VW-São_Carlos")-1,
    "OnCarriage", getNumber(mo, "object.OnCarriage")+1
    
  } as fragments 
from MyObject mo
where getString(mo, "alarmType") = "c8y_Geo-VW-SC-Leaving";


Hi Lucas,

what exactly is going wrong with the calculation?

best regards
Michael

Hi Michael,

The problem is, I have 30 device simulators, where 3 devices are moving. I created 2 geofences, which generate the alarms for entering and leaving the geofences and for each type of alarm I increase or decrease their respective location.
A rule for counting how many devices you have in each place.
However, after a few hours or days this counter, it gets lost. Apparently when two or more alarms are generated at the same time, the event does not process one or more of those alarms, or the event is interrupted in the middle of the process.

Thank you for your help.
Best Regards,
Lucas