User avatar
johan
GpsGate
Posts: 14440
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

GUIDE: Multiple events per event rule and device.

Mon Jun 09, 2014 1:11 pm

GUIDE: Multiple events per event rule and device.

Added support for multiple active events

Install

Make sure all plugins are up to date (all green) under SiteAdmin -> Plugins.

Usage

ScriptExpression can now manually start/end event using

context.startEvent(namespace)
context.endEvent(namespace)
context.endAllEvents()

context.setVariable(name, value [, namespace]): Sets an event expression variable

use third namespace parameter in context.setVariable to map the variable value to the corresponding event.

Example

Code: Select all

var speed = trackPoint.velocity.groundSpeed * 3.6;
if(speed > 20){
  context.startEvent('s1');
  context.setVariable('Severity', 'Fast', 's1');
}
else {
  context.endEvent('s1');
}

if(speed > 50){
  context.startEvent('s2');
  context.setVariable('Severity', 'Even Faster', 's2');
}
else {
  context.endEvent('s2');
}

if(speed > 100){
  context.startEvent('s3');
  context.setVariable('Severity', 'Supet Fast', 's3');
}
else {
  context.endEvent('s3');
}

return false;

Regards,
Johan

GpsGate Support

Alon
Posts: 180
Joined: Wed Sep 01, 2004 3:48 pm

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 10, 2014 1:00 am

Hi,

To continue my question from thread: topic.asp?TOPIC_ID=17172 -

If my script on the event's start expression holds these lines:

Code: Select all

context.setVariable('Tags', session.user.getTags());
return false;
with 'match any'
Should I see on the notification list -> Argument -> Message -> list of available variables the parameter 'Tags'? because I'm not (saved event and reopened)

As this script does not suppose to start an event, just add a variable to notification list, I haven't used the

Code: Select all

context.startEvent()
Is this a mistake?

Please explain me what am I missing.

Thank you.

User avatar
johan
GpsGate
Posts: 14440
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 10, 2014 10:27 am

Try to understand how things work by starting with very simple examples. Make a theory about how you think it works and test. Verify and confirm (or reject).

Use SimOne to test in a separate test application in a controlled way.

How to use SimOne to test Event Rules topic.asp?TOPIC_ID=14038


Regards,
Johan

GpsGate Support

Alon
Posts: 180
Joined: Wed Sep 01, 2004 3:48 pm

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 10, 2014 9:54 pm

Yes, I'm using SimOne to test events, but that is not related to a simple or complex event logic.
It is related to not knowing how to use the new feature in order to show the needed variable on the notifications section. A small code example or answering my question will be appreciated.

Kerem
Posts: 23
Joined: Tue Mar 11, 2014 10:47 am
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Wed Jul 16, 2014 8:00 pm

Hi Alon,

The variables you set via Script Expression are not visible in the list of available messages but you can use them. Just use the variable name with square brackets (in your case this is [Tags]).

Please note that "session.user.getTags" function returns an array of Tag objects, while "context.setVariable" function requires string parameters. You can try to concatenate tag names and pass it to notifiers by making a call to "context.setVariable".

I would recommend the following approach:

Code: Select all

// Get user tags 
var arrUserTags = session.user.getTags();
var arrUserTagNames = [];

// Insert user tag names into a new array
for (var i = 0; i < arrUserTags.length; i++) {
  arrUserTagNames.push(arrUserTags[i].name);
}

// Concatenate tag names with comma and set variable
var strUserTags = arrUserTagNames.join(',');
context.setVariable('Tags', strUserTags);
return false;
Then you can go ahead with using variable label [Tags] in the argument notifier.

Regards,
Kerem

GpsGate Support

Alon
Posts: 180
Joined: Wed Sep 01, 2004 3:48 pm

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 17, 2014 7:32 am

Hi Kerem, thank you for your detailed answer. It looks good, just one question regarding efficiency and server load - The code snippet you wrote should be set on the event conditions ("Expressions"), so will it be validated on every incoming message of every vehicle? I have hundreds of vehicles (intend to have many more) who broadcast location every 1 min...

The real reason I started this post was because I did ask for the Tags feature on the notification variables list from your support and thought that this was the implementation. In my opinion, the user.getTags() on the event's expression is one great capability just that might not be related to my needs. What do you think?

Kerem
Posts: 23
Joined: Tue Mar 11, 2014 10:47 am
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 17, 2014 5:10 pm

Hi Alon,

If you need to email tag names of the unit (using email notifier), then this is the only way to handle your case at the moment.

About the server load, user tag data is being cached to increase the efficiency. So unless you change the user tags very often, there shouldn't be too much workload added to the server. The only critical point is when user tags are retrieved for the first time when "session.user.getTags" is called.

Regards,
Kerem

GpsGate Support

Alon
Posts: 180
Joined: Wed Sep 01, 2004 3:48 pm

RE: GUDIE: Multiple events per event rule and device.

Thu Jul 17, 2014 8:58 pm

Thank you Kerem, so just to make sure, the loop itself and the string concatenation on the JS code will not affect performance?

User avatar
johan
GpsGate
Posts: 14440
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Mon Jul 21, 2014 4:02 pm

Guidelines for testing:

1. Make a Tag e.g. named "Test new script" and only include a handful of vehicle in that Tag.
2. Set the Tag as input to the Event Rule in Step 2. of the Event Rule Wizard.

In this way you limit the effects of a new event rule if something is wrong. And you can scale up step by step.

3. Check performance/profiling data under SiteAdmin -> System Tools -> Profiler, or the same information stored hourly in files under C:\GpsGateServer\ProfilerLog

Here you can see performance statistics on each individual script you have on your server.

Regards,
Johan

GpsGate Support

Sacred90
Posts: 1
Joined: Sat Feb 21, 2015 8:05 pm
Location: Poland

RE: GUDIE: Multiple events per event rule and device.

Mon Feb 23, 2015 12:46 pm

Hello everyone

I wonder about the feature described below.

I would like to generate raport from geofence but in situation when i have contact geofence (countries from European uni) my event rule never end because devices never send localication from outside event rule. And i tried use script expression to end event if have different name us previous geofence. It is possible to do? Or have you any different idea to generate report on the visits of European countries

Reglo
Posts: 66
Joined: Wed May 27, 2015 9:09 am
Location: USA

RE: GUDIE: Multiple events per event rule and device.

Fri Sep 18, 2015 8:47 am

Hi,

I am working on a multiple-event script, and can't quite figure out how to preserve states between evaluations. The context.getState method returns an error when the state is undefined (i.e. the first time the rule is evaluated). Is there some way to get around this?

Thanks,
Reglo

User avatar
johan
GpsGate
Posts: 14440
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Fri Sep 18, 2015 9:38 am

Post a new topic where you describe your issue. Include some of your relevant scripting code to show what you have done.

Regards,
Johan

GpsGate Support

JayFF
Posts: 116
Joined: Fri Oct 03, 2014 1:03 am
Location: USA
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Fri Jan 29, 2016 1:42 am

Hi,

If I use context.setVariable in an Event Expression script, is it possible to retrieve the value that I set as a report argument? The first time my script runs, I save the current time to the context.state object. For each subsequent time the script runs I calculate the elapsed time between events. I want to capture the elapsed time and include it as a report argument.

Thanks,
Jay

J. F. Florey

User avatar
johan
GpsGate
Posts: 14440
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: GUDIE: Multiple events per event rule and device.

Fri Jan 29, 2016 9:33 am

If you want to keep variable values between calls to your Script Expression, use context.state

And then you use context.setVariable to set the Report arguments.

Since you can keep all values you need in context.state there is no need to access the values in the report arguments.

Regards,
Johan

GpsGate Support

BrettTaylor
Posts: 1
Joined: Sun Jan 31, 2016 10:31 pm
Location: Canada

RE: GUDIE: Multiple events per event rule and device.

Mon Feb 01, 2016 6:11 am

The variables you set via Script Expression are not visible in the list of available messages but you can use them. Just use the variable name with square brackets.
Please note that "session.user.getTags" function returns an array of Tag objects, while "context.setVariable" function requires string parameters. You can try to concatenate tag names and pass it to notifiers by making a call to "context.setVariable".

http://www.7pcb.com/

Return to “GpsGate for Developers”