Documentation Index
Fetch the complete documentation index at: https://samsara-showcase.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This script automates the process of assigning training courses to drivers based on their HOS violations. It interacts with Samsara APIs to fetch drivers based on tags, check existing assignments, and create new assignments for drivers based on their HOS violations.This guide assumes you are already familiar with the basics of the Samsara Training Product and the overall GET Training Assignments, POST Training Assignments, and GET Training Courses APIs.
Example use cases
- A Safety manager wants to assign the “Compliance Training” course to a driver when the driver has 2 or more HOS violations in the past 30 days.
- A Fleet manager wants to assign the “Compliance Training” course to a driver when the driver has 3 HOS violations that are marked as “shiftHour” type in the past 45 days.
Trigger conditions
- Specific HOS violation type (e.g., “shiftHours”)
- Specify conditions under which assignments will skip drivers
- Specify driver tags for assignment
- HOS violation count thresholds are exceeded (e.g., 2 violations in 45 days)
Action
- Assign training course with specific due dates
Execution flow
Fetch HOS violations
Convert
HOS_VIOLATION_LOOKBACK_START and HOS_VIOLATION_LOOKBACK_END to RFC3339 format. Retrieve HOS violation events that match HOS_VIOLATION_TYPE for the given period and driver tag ID. Count the number of violations for each driver.Filter drivers based on HOS violation threshold
Identify drivers who have exceeded the
HOS_VIOLATION_THRESHOLD. Flag these drivers for training.Identify drivers who require training
If a driver has already been assigned the course, omit those drivers from
drivers_requiring_training.Generate training due date
Call
generate_rfc3339_timestamp() with COURSE_COMPLETION_DUE_DAYS to get the training due date in RFC3339 format.Script
To run certain automations, you will need to set up a development environment. These code snippets can be copied but will need to be customized to match your organization’s specific use case.
Appendix
Constant definitions
| Constant | Type | Description |
|---|---|---|
HOS_VIOLATION_LOOKBACK_START | Integer | How many days back to look for HOS violation events. |
HOS_VIOLATION_LOOKBACK_END | Integer | End date for looking up HOS violation events. |
TARGET_DRIVER_TAG_IDS | List of Strings | Tag IDs used to filter specific drivers. |
HOS_VIOLATION_TYPE | String | Specific HOS violation type to track. |
HOS_VIOLATION_THRESHOLD | Integer | Threshold of HOS violations before a driver is flagged. |
COURSE_ID | String | ID of the training course that will be assigned. |
COURSE_COMPLETION_DUE_DAYS | Integer | Number of days from today to set as the due date. |
TRAINING_LOOKBACK_DAYS | Integer | Number of days to look back for training assignments. |
Function definitions
| Function | Description |
|---|---|
get_hos_violations | Fetches HOS violation events for a given time range, tag IDs, and violation type. |
assign_training | Creates training assignments for drivers. |
get_training_assignment_details | Retrieves training assignments filtered by assignment_interval_timestamp and course_id. |
generate_rfc3339_timestamp | Generates a UTC midnight RFC3339 timestamp. See Timestamps. |