Driver Login Report

Here is how to create a simple report listing periods when a driver was logged in to a vehicle that can be run for either drivers or vehicles.


Prerequisites

  1. Set up an Event Rule for drivers.
  2. Enable Script Expressions.

Event Rule with a Script Expression

Create a new Event Rule, named, for example, DriverReport, and set it to Disabled. This way, the rule is not evaluated in live mode, but you can still generate reports for it.

disable rule

In the Expressions section, add a Script Expression and edit it to contain the script below.

 
// init state
var st = context.state || {};
 
// username of vehicle for a driver, or a driver for a vehicle
var linkedUsername = session.user.isDriver ? session.vehicle.username : (session.driver ? session.driver.username : null);
 
if (linkedUsername != st.linkedUsername && st.linkedUsername != null) {
  // if has changed and it has existed before, end the event on previous message
  // (as that was the last one for which the old vehicle-driver link should exist)
  report.context.endEventOnPrevious(st.linkedUsername);
}
 
if (linkedUsername != null) {
  // if not empty now, start event, using the username of associated driver/vehicle as namespace
  // (note that this does nothing if event with the same namespace is already started)
  context.startEvent(linkedUsername);
  // store for next evaulation
  st.linkedUsername = linkedUsername;
}
 
// save state
context.setState(st);
 
// return false as we start/end events explicitly by this script
return false;

 

In the Notifiers section, add Report Argument notifiers like in the picture below and save the Rule.

report args

New Report

In SiteAdmin > Reporting > Manage Reports, create a new Report based on EV1000 Event Rule report.
Click on the top header of the column labeled “Vehicle”, and choose Delete Column to remove it. We want to use the vehicle and driver data generated through Report Arguments instead.

simple event report

Now save the new report. Activate and configure this report for the application in which you created the DriverReport Rule.

You can now generate it for the DriverReport rule, for either tags denoting drivers or tags denoting vehicles.
The result should look something like this:

report result