Recorder class to keep track of previously recorded mouse actions, mainly for move events. It automatically computes all mouse features needed for Data format.
A simple usage would be to

  1. add an event listener for mousemove or touchmove event;
  2. call addRecord with the timestamp and (x,y) coordinates every time the event fires;
  3. call isHuman with a preloaded model to know if the trajectory is from human or not.
Which gives something like : ``` recorder = new Recorder(window.screen.width, window.screen.height); document.addEventListener("mousemove", event => { recorder.addRecord({ time: event.timeStamp, x: event.clientX, y: event.clientY, type: "Move" // optional, not used in practice });

if (recorder.getRecords().length > 100) { const isHuman = recorder.isHuman(delbot.Models.rnn3); recorder.clearRecord(); // ... } });

``` Be careful not to call getPrediction or isHuman too often, these may be heavy for smaller configurations.

Hierarchy

  • Recorder

Constructors

  • Create an empty recorder.

    Parameters

    • scaleX: number = 1

      The x resolution of the screen to keep x value between 0 and 1. If unspecified, set to 1.

    • scaleY: number = 1

      The y resolution of the screen to keep y value between 0 and 1. If unspecified, set to 1.

    Returns Recorder

Properties

currentRecord: SingleRecord[]

The list of calculated mouse features from the beginning of this record.

maxSize: number

The max size of the record, default to -1 (unlimited size), to prevent high memory usage. If the maxSize is reached, new elements shift the entire array and are added to the end.

normalizer: number[]

A 2-array with two numbers (a,b). When a new line with (x,y) is added to the current record, we compute features with (x/a, y/b).

previousLine: SingleRecord

The previous line used to compute the next mouse features, e.g. time diff = current time - previous time.

totalAccel: number

The accumulated acceleration from the beginning of this record, used to compute average values of mouse features.

totalDistance: number

The accumulated distance from the beginning of this record, used to compute average values of mouse features.

totalLength: number

The length of the trajectory, it will always be equals to currentRecord.length unless maxSize is defined and the current record is already reached.

totalSpeed: number

The accumulated speed from the beginning of this record, used to compute average values of mouse features.

fail: Symbol = ...

Static field describing a fail for isHuman.

notEnoughProvidedData: Symbol = ...

Static field describing an error for isHuman.

success: Symbol = ...

Static field describing a success for isHuman.

Methods

  • Add a line to the current record and calculate all mouse features. You don't have to normalize the x and y components, it is done automatically with the normalizer from the constructor.

    Returns

    The same recorder instance for chain calls.

    Parameters

    • line: SingleRecord

      The recorded action that must contain at least timestamp, x and y positions.

    Returns Recorder

  • Clear the current record without creating a new object.

    Returns

    The same recorder instance for chain calls.

    Returns Recorder

  • This function takes a model Model containing a TensorFlow.js layer model and a Data instance and returns the list of probabilities for each batch element to be a bot trajectory. The batch is obtained from currentRecord.
    This function may be heavy for smaller configurations, be careful not to call it too often.

    Returns

    A list of probabilities, empty list if is not enough datas.

    See

    isHuman

    Parameters

    • model: Model<any>

      A Model instance, with at least predict().

    • uniqueDataset: boolean = false

      Default to false, if true then all datasets are merged into one unique, so there is one prediction and the average is its unique value. Might throw error if the classifier doesn't support it.

    Returns Promise<number[]>

  • This function takes a model Model containing a TensorFlow.js layer model and a Data instance and returns whether the trajectory stored in currentRecord is considered as human or bot for the model.
    There may be more than one input batch for the prediction, leading to more than one probability p for the sample to be a bot. It consequently takes the average of those probabilities and returns true if the average is less than a given threshold.
    If there is not enough input data, so we have a batch size of 0, it returns false and a reason notEnoughProvidedData.
    This function may be heavy for smaller configurations, be careful not to call it too often.

    Returns

    A promise of an instance of Result with two fields:

    • result, the boolean `true` iff it is a human trajectory
    • reason of the return, set to notEnoughProvidedData if there is not enough data.

    See

    getPrediction

    Parameters

    • model: Model<any>

      A Model instance, with at least getData() and getModel().

    • threshold: number = 0.2

      A number between 0 and 1, if the average probability to be a bot is less than this value, we consider the trajectory as human.

    • uniqueDataset: boolean = false

      Default to false, if true then all datasets are merged into one unique, so there one prediction and the average is its unique value. Might throw error if the classifier doesn't support it.

    • consoleInfo: boolean = false

      Default to false, if true then it prints the prediction to console.

    Returns Promise<Result>

  • Load an entire trajectory as string or string array into this Recorder instance. If the given input is a string, we split it with the separator \n. The string array must be of the following format :

    ["resolution:1536,864",
    "9131.1,Pressed,717,361",
    "9134.8,Move,717,361",
    "9151.8,Move,717,361",
    ...
    "10402.3,Move,722,360",
    "10419.1,Move,718,358",
    "10425.8,Released,717,360]"

    As first line we have the screen resolution to normalize X and Y and all other lines are timestamp,actionType,x,y. We then add each line with addRecord.
    Notice that the instance is cleared with clearRecord when calling this method and the first line with resolution is optional, if absent, we keep the previous normalizers (1 if unspecified in constructor).

    Returns

    The same recorder instance for chain calls.

    Parameters

    • recordString: string | string[]

      The string describing the trajectory.

    • xScale: number = -1

      If specified and > 0, the x normalization will be this value.

    • yScale: number = -1

      If specified and > 0, the y normalization will be this value.

    Returns Recorder

  • Set the max size of record. When reached, it shifts all elements.

    Parameters

    • maxSize: any

      The new max size value.

    Returns void

Generated using TypeDoc