Options
All
  • Public
  • Public/Protected
  • All
Menu

Insight Scripting Language - v1.1.4

Insight scripting

Insight data can be enriched using rules. A rule is a typescript script that run on a certain condition.

At the current time we support three types of rules:

  • event: run for every Event of every match in your project.
  • sequence: run for every Sequence of events of every match in your project.
  • tracking: run once per game on all the available tracking frames (maybe 5 to 60 depending on the tracking data)

General

The scope of a rule can be one of the following:

A custom rule can have several different parameters (defined through the application UI) that are available through the global object Param, every custom rule has access to the current Game in the global variable currentGame.

Custom rules can access (ready-only) the Game, Event and Sequence properties, and can use a lot of helper functions (with inline help in the editor) to make the code simpler.

Most events contain a Team and a Player associated with the event.

If tracking data is available, the tracking data "picture" is associated with the events in the GameState object available in every event.

There is an object called PositionManager that makes it easier to find distances between players or the ball, you can access it in currentEvent.position.

You can access the BallPositionManager, a position manager that measure the positions from the ball position from currentEvent.ball or the PlayerPositionManager from currentEvent.player.position, this one measures the positions from the position of the player associated with the event. You can also access the teammates or the opponents from the currentEvent.team.

NOTE: sometime an event may not have a team associated (this happens in the live scenario), and some events do not have a player associated so the access to currentEvent.team/player should always be checked.

Event rules

Event rules are the first to be executed, they have access to the current Event (in the global variable currentEvent ), they also have access to all the events of the game (accessing currentGame.events ) or directly to the previous event (in the global variable previousEvent).

A simple event rule may look like this:

if (currentEvent.is("Miss") || currentEvent.is("Attempt Saved") || currentEvent.is("Goal") || currentEvent.is("Post")) {
let customEvent = currentGame.addCustomEvent({ name: "Shot", attributes: currentEvent.attributes });

if (currentEvent.is("Goal"))
customEvent.addAttribute("Goal");
}

Tracking rules

Tracking rules are executed after the event rules, a tracking rule has access only to the active Game in the global variaiable currentGame and to the game states in currentGame.gameStates, a tracking rule should iterate by itself all the gameStates and extract the required metrics.

Tracking rules do not have access to events or sequences BUT can create them with Game.addCustomEvent() or Game.addCustomSequence().

Sequence rules

Sequence rules run on the "automatic" game sequences that are built by the data ingestion pipeline separating the game events in array of events relative to a single team sequence of play.

Sequences end when the game is stopped (out, fouls, goals, period ends...) or when the ball possession changes.

A sequence rule can access the current Sequence in the global variable currentSequence or the previous one in the global previousSequence.

In sequence rules you also have access to currentEvent (that points to the last event of the Sequence).

Simple sequence rule using tracking data:

if (currentEvent.is("Pass") && currentEvent.player?.role === "Goalkeeper") {
let freePlayers = 0;
for (const p of currentEvent.position.teammates) {
if (p.id === currentEvent.player.id)
continue;
const nearOpponents = currentEvent.position.opponentsWithDistanceFrom(p.x, p.y, Params.DISTANCE).count;
if (nearOpponents === 0)
freePlayers++;
}
if (freePlayers < 2) {
currentGame.addCustomEvent({ name: "Team High Press" });
}
}