Trip & Idle with parking report

In this example we will show you how to use scripting to extend trip and idle report with parking state.


Stay with me even if you are not familiar with scripting. We provide you templates to make the setup easier, however we recommend you to get familiar with basic concepts of reporting before moving on. The vehicles must provide a variable(Ignition or Engine on) to denote the parking state when idling. You just need to follow this guide to get a report like this (click on the image to enlarge):
preview

Setup

  1. Download this Zip, you will find a report definition (Trip & Idle & Parking (Detailed).xml), and an event rule (Trip Idle Parking Rule.xml) inside that we will import shortly.   You may ask why an event rule has anything to do with a trip/idle/parking report. In this case the event rule generates the data for the report, it is only active for reporting and it contains a script expression to create events that correspond to trip states.
  2. Go to SiteAdmin -> Import. Select template from the drop-down list and browse Trip & Idle & Parking (Detailed).xml file that contains the report definition and click Import.
  3. Go to SiteAdmin -> Applications -> Search and Manage, select an application for testing. In the Privileges and Features section,   make sure you have the Admin/_ImportTemplate feature and Plugins/Reporting/_CreateReport/Trip & Idle & Parking (Detailed) enabled for your application.
  4. Log in to the application. In the Admin menu, select Import Template and pick “Trip Idle Parking Rule.xml” file to import the event rule.
  5. Navigate to Reports -> Manage Reports. At the bottom of the window select “Trip & Idle & Parking (Detailed)” report definition and click Open.
  6. Select a Tag for testing.
  7. Select the Trip Idle Parking Rule in the Event Rule list, and mark the “hide” checkbox next to it, because this report layout was made for that event rule, it does not make sense to use it with different one.
  8. Click Save.
  9. Select a period where you have test data with ignition variable and click Preview to see your report.    parameters

Customizations

     
  •   To use different variable for the indication of the parking state, you need to modify the script expression in the event rule:
             
    1. Go To Admin -> Event Rules and open the “Trip Idle Parking Rule”
    2.      
    3. Go to the expression part and click the Edit button. 
      (If the Edit button is disabled you need to enable _EditScriptExpression privilege.)
    4.      
    5. You will see this script in the script editor as show below:
       
       
      // This scipt creates events that correspond to trip states.
       
      // Use Ignition=Off to indicate parking state.
      report.tripIdle.useParkedVariable('Ignition');
       
      if (report.tripIdle.state == 'sleep') {
          return false;
      }
       
      if (report.tripIdle.hasChanged) {
          // End the ongoing event that corresponds to the previous trip state.
          context.endEvent(report.tripIdle.previousState);
      }
       
      if(report.context.isLastInDay) {
          // Avoid events to span multiple days.
          context.endAllEvents();
      } else {
          var tripState = report.tripIdle.state;
          // Start an event for the current trip state.
          // If it is started it will be kept ongoing.
          context.startEvent(tripState);
          // Set the variable for the ReportArgument notifier that stores the Trip state.
          context.setVariable('TRIP_STATE', tripState);
      }
       
      return false;

       

    6. Find the line containing report.tripIdle.useParkedVariable(‘Ignition’); and change the Ignition to another variable you want to use.
    7. Click Save and you are ready to go.

 

  •   To add a driver for the trip, you need to modify the script expression in the event rule:
  1. Go To Admin -> Event Rules and open the “Trip Idle Parking Rule”
  2. Go to the expression part and click the Edit button. 
    (If the Edit button is disabled you need to enable _EditScriptExpression privilege.)
  3. You will see this script in the script editor as shown above
  4. Find the line containing  context.endEvent(report.tripIdle.previousState);                                                                                                                                                            
  5. Add the following code on on top of that so you get  if(session.driver != null){
    context.setVariable("DriverName", session.driver.name,report.tripIdle.previousState);
    }
    context.endEvent(report.tripIdle.previousState);      
  6. Add a Report Argument using $FINAL([DriverName])
  7. Click Save and you are ready to go.

Adding more columns

You can add more columns using ReportArguments. Here is a list of variables you can add. For example [USER_DESCRIPTION]

Please note that you need to re-process the report after you have made any change to the Event Rule for the changes to take effect on historical data.

Troubleshooting

     
  • Problem: I only see ‘Run’ and ‘Parked’ trip state and I never see ‘Idle’.
    Solution: You may have problem with the variable that indicates the parking state. Check if it is mapped correctly using the DeviceMapper and TrackPoints panel.
  •  
  • Problem: I customized the event rule, but I do not see the changes I made when rendering a new report.
    Solution: Event rule modification does not affect the reporting data that has already been processed. You need to reprocess it to see the changes