load

To load events for a specified period into the session for later processing, use the events/load method.

After loading, retrieve the events using the events/get method. If you pass selector in the events/load request, the selected events are returned in the selector field of the same response, so a separate events/get call isn’t required.

Endpoint

Copied!
svc=events/load&params={"itemId":<long>,
            "ivalType":<int>,
            "timeFrom":<uint>,
            "timeTo":<uint>,
            "detectors":[
                {
                    "type":<text>,
                    "filter1":<long>
                },
                ...
            ],
            "selector":<object|array>,
            "measure":<uint>,
            "lang":<text>}

Parameters

Parameter Description
itemId Unit ID. For resource_drivers, specify a resource ID instead.
ivalType Time interval selection method (see below).
timeFrom Depends on ivalType:
  • For ivalType 1, 4, 5, or 6: interval start (UNIX time).
  • For ivalType 2 or 3: number of messages to load.
timeTo Interval end (UNIX time).
detectors Array of detector objects to load. Each object contains type and filter1.
type Detector object field. Event detector type.
filter1 Detector object field. Detector filter. For resource_drivers, specify a driver ID, or 0 to load the events of all drivers of the resource. For sensor-based detectors, specify a sensor ID, or 0 to load the events of all sensors of this type. For eco_driving, specify a criterion type value (1 acceleration, 2 brake, 3 turn, 4 speeding, 5 sensor, 6 smoothness, 7 idling), or 0 to load all criteria.
selector Optional. Filter applied to the events loaded by this request. The matching events are returned in the selector object of the response, so you don’t need to call events/get separately. For supported selector formats, see events/get.
measure Measurement system:
  • 0 for metric (SI);
  • 1 for US;
  • 2 for imperial;
  • 3 for metric with gallons.

If the parameter isn’t specified, the value set for the current session is used (the two lowest bits of the flags parameter of render/set_locale). If no value is set in the session, the value 0 is used.
lang Language (2-character code, for example, en or es). If the parameter isn’t specified, the value set for the current session is used (see the language parameter of render/set_locale). If no value is set in the session, the value en is used.

Interval selection method (ivalType)

Value Description
1 Loads messages from timeFrom to timeTo.
2 Loads the number of messages specified in timeFrom, starting from timeTo.
3 Loads the number of messages specified in timeFrom, up to timeTo.
4 Loads messages from timeFrom to timeTo, plus one message before timeFrom.
5 Loads messages from timeFrom to timeTo, plus one message after timeTo.
6 Loads messages from timeFrom to timeTo, plus one message before timeFrom and one after timeTo.

Response

If the request is completed successfully, the response contains the number of loaded events for each detector requested in detectors and each detector-specific ID. The states object contains the update time for each loaded detector. The selector object contains filtered results only if you pass the optional selector parameter in the request; otherwise, it’s an empty object ({}).

Copied!
{
    "events": {
        "<detector_type>": {
            "<detector_specific_id>": <uint> /* number of loaded events */
        }
    },
    "states": {
        "<detector_type>": {
            "updateTime": <uint>,       /* detector update time, UNIX time */
          "recalc": <uint>            /* recalculation status: 0 for none, 1 for queued, 2 for in progress */
        }
    },
    "selector": { ... }
}

If the request isn’t completed, an error code is returned.

The recalc field is returned for every detector in states, including when its value is 0.

Error codes

Error code Description
1 Invalid or obsolete request SID.
4 Parameter validation error.
5 Events are disabled or initializing.
6 Failed to load events.
7 The event service is unavailable, or the Request reports and messages access right is missing.

Examples

The following examples show how to load events for different use cases.

Loading events next to the requested period

The ivalType value 6 loads messages from the requested period together with one message before timeFrom and one message after timeTo. Use it when an event can start before the period or end after it. For example, if a unit stays parked for several days, the parking event starts before the requested period, and without the additional message you get only its end.

To load the trips of the unit with ID 1001 for one day (from 1659474000 to 1659560400) together with the trip before and the trip after this day, use the following request:

Copied!
svc=events/load&params={
  "itemId": 1001,
  "ivalType": 6,
  "timeFrom": 1659474000,
  "timeTo": 1659560400,
  "detectors": [
    {
      "type": "trips",
      "filter1": 0
    }
  ],
  "selector": {
    "type": "trips",
    "timeFrom": 1659387600,
    "timeTo": 1659646800,
    "detalization": 3
  },
  "measure": 0,
  "lang": "en"
}

The period in the selector is one day wider on each side than the requested period. This is required because the selector filters the events that are already loaded into the session: if its period is the same as the requested one, the messages before and after the requested period are loaded but the corresponding events aren’t returned in the response. For the same reason, the detalization value must include the flags of all the event types you need.

Response
Copied!
{
  "events": {
    "trips": {
      "0": 5
    }
  },
  "states": {
    "trips": {
      "updateTime": 1659564000,
      "recalc": 0
    }
  },
  "selector": {
    "trips": {
      "0": [
        {
          "from": { "t": 1659470100, "y": 52.2297, "x": 21.0122 },
          "to": { "t": 1659475800, "y": 52.2370, "x": 21.0174 },
          "m": 1659475800,
          "f": 0,
          "state": 1,
          "max_speed": 74,
          "avg_speed": 41,
          "distance": 12480
        },
        ...
      ]
    }
  }
}

The first trip starts at 1659470100, that is, before the requested period. The set of fields corresponds to the detalization value 3, which combines the flags 0x1 and 0x2. The updateTime value is the detector update time and can differ from the requested period’s timeTo.

Loading events from a fixed number of messages

The ivalType values 2 and 3 load a fixed number of messages instead of a period. In this case, the timeFrom parameter contains the number of messages, and timeTo contains the time to count them from.

To load the events built from the last 10 messages of the lls detector registered before 1659560400 for the unit with ID 1001, use the following request:

Copied!
svc=events/load&params={
  "itemId": 1001,
  "ivalType": 3,
  "timeFrom": 10,
  "timeTo": 1659560400,
  "detectors": [
    {
      "type": "lls",
      "filter1": 0
    }
  ],
  "measure": 0,
  "lang": "en"
}

The request doesn’t contain the selector parameter, so the response returns the number of loaded events and detector state information, but not the event data itself. To get the events, use events/get.

For example, if the unit has one matching LLS sensor, the response can look like this:

Copied!
{
  "events": {
    "lls": {
      "12345": 10 /* number of loaded events for the sensor with ID 12345 */
    }
  },
  "states": {
    "lls": {
      "updateTime": 1659564000,
      "recalc": 0
    }
  },
  "selector": {}
}

Loading driver assignment events

The resource_drivers detector registers events on a resource, not on a unit. To load the assignment events of all drivers of the resource with ID 1003, specify the resource ID in itemId and set filter1 to 0. To load the events of one driver, pass the driver ID in filter1.

Use ivalType 4 to load the data for the specified period together with one message before timeFrom. This can help restore an assignment that started before the requested period and continues within it. For the other options, see Interval selection method (ivalType).

Copied!
svc=events/load&params={
  "itemId": 1003,
  "ivalType": 4,
  "timeFrom": 1672524000,
  "timeTo": 1672610400,
  "detectors": [
    {
      "type": "resource_drivers",
      "filter1": 0
    }
  ]
}

To get the loaded events in the same request, add the optional selector parameter. In the following example, the expr field sets a custom interval in the <start>-<end> format, and only the events which intersect this interval are returned. The timeFrom and timeTo values of the selector limit the period from which the loaded events are selected, and detalization 3 returns basic event data (0x1) and detector-specific data (0x2).

Copied!
svc=events/load&params={
  "itemId": 1003,
  "ivalType": 4,
  "timeFrom": 1672524000,
  "timeTo": 1672610400,
  "detectors": [
    {
      "type": "resource_drivers",
      "filter1": 0
    }
  ],
  "selector": {
    "expr": "1672524022-1672524040",
    "timeFrom": 1672524000,
    "timeTo": 1672610400,
    "detalization": 3
  }
}

For the structure of the returned events, see resource_drivers on the events/get page.

If you find a mistake in the text, please select it and press Ctrl+Enter.