Create an empty recorder.
The x resolution of the screen to keep x value between 0 and 1. If unspecified, set to 1.
The y resolution of the screen to keep y value between 0 and 1. If unspecified, set to 1.
Private currentThe list of calculated mouse features from the beginning of this record.
Private maxThe 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.
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).
Private previousThe previous line used to compute the next mouse features, e.g. time diff = current time - previous time.
Private totalThe accumulated acceleration from the beginning of this record, used to compute average values of mouse features.
Private totalThe accumulated distance from the beginning of this record, used to compute average values of mouse features.
Private totalThe length of the trajectory, it will always be equals to currentRecord.length
unless maxSize is defined and the current record is already reached.
Private totalThe accumulated speed from the beginning of this record, used to compute average values of mouse features.
Static Readonly failStatic field describing a fail for isHuman.
Static Readonly notStatic field describing an error for isHuman.
Static Readonly successStatic field describing a success for isHuman.
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.
The same recorder instance for chain calls.
The recorded action that must contain at least timestamp, x and y positions.
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.
A list of probabilities, empty list if is not enough datas.
isHuman
Get the mouse trajectory as a list of points and action type with their calculated features.
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.
A promise of an instance of Result with two fields:
getPrediction
A Model instance, with at least getData() and getModel().
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.
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.
Default to false, if true then it prints the prediction to console.
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).
The same recorder instance for chain calls.
The string describing the trajectory.
If specified and > 0, the x normalization will be this value.
If specified and > 0, the y normalization will be this value.
Generated using TypeDoc
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
- add an event listener for mousemove or touchmove event;
- call addRecord with the timestamp and (x,y) coordinates every time the event fires;
- 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
getPredictionorisHumantoo often, these may be heavy for smaller configurations.