Driver Login Report

This guide shows 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.

report result

Prerequisites

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

Event rule setup

1. 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

2. In the 4. Expressions section, select 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;

3. In the 5. Notifications section, select Report Argument notifiers like in the picture below and save the Rule.

report args

Read more about report arguments here.

New Report

1. Generate a copy of the EV1000 Event Rule report.

Read more about how to generate a copy of a report here.

2. 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

3. Now save the new report. 

4. Activate and configure this report for the application in which you created the DriverReport Rule.

5. Create a new instance of the report in your application.

Now your report is ready.