Class PathLibrary
- java.lang.Object
-
- com.kraken.api.input.mouse.strategy.replay.PathLibrary
-
public class PathLibrary extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDATA_DIR
-
Constructor Summary
Constructors Constructor Description PathLibrary()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NormalizedPathgetSimilarPath(java.util.List<NormalizedPath> candidates, double targetDistance)Selects aNormalizedPathfrom a provided list of candidate paths that most closely matches a target distance, considering tolerance thresholds and randomization within a subset of viable matches.static java.util.List<NormalizedPath>load(java.lang.String library)Loads and normalizes a set of mouse gestures from a specified library file, converting them intoNormalizedPathobjects.
-
-
-
Method Detail
-
load
public static java.util.List<NormalizedPath> load(java.lang.String library)
Loads and normalizes a set of mouse gestures from a specified library file, converting them intoNormalizedPathobjects. The method searches for a corresponding JSON file within the directory defined byDATA_DIR. If the file is found, it parses the content, normalizes valid mouse gestures, and logs the results.Mouse gestures are read line-by-line. Invalid or malformed entries are skipped with appropriate warnings logged. Normalization is performed through the
PathNormalizer.normalize()method, which filters out gestures that cannot be reliably normalized.- Parameters:
library- The name of the library for which to load mouse gestures. This name is used to search for a JSON file in theDATA_DIR. Spaces in the library name are replaced with underscores during the filename matching.- Returns:
- A
ListofNormalizedPathobjects representing the normalized mouse gestures loaded from the library file. Returns null if no matching file is found or if an error occurs during the loading process.
-
getSimilarPath
public static NormalizedPath getSimilarPath(java.util.List<NormalizedPath> candidates, double targetDistance)
Selects aNormalizedPathfrom a provided list of candidate paths that most closely matches a target distance, considering tolerance thresholds and randomization within a subset of viable matches.The method evaluates the "fitness" of each candidate based on the absolute difference between its original distance and the target distance. Viable paths are those whose distance is within a calculated tolerance of the target distance.
If no viable paths exist, a fallback strategy is employed to select randomly from the top three closest matches. Otherwise, a standard strategy randomly selects a path from the top 50% of the viable matches, ensuring some degree of diversity and non-determinism in the selection.
- Parameters:
candidates- a list ofNormalizedPathobjects representing potential matches. This list must not be null but can be empty, in which case the method will log a warning and return null.targetDistance- the target distance to match with the candidates' original distance values. This value is used for calculating fitness and tolerance thresholds.- Returns:
- a
NormalizedPathobject selected as the best match to the target distance, or null if no candidates are provided in the list.
-
-