1
0
mirror of https://github.com/davpapp/PowerMiner synced 2024-12-22 07:58:48 -05:00

Grid correctly working with

This commit is contained in:
davpapp 2018-01-25 04:27:39 -05:00
parent dce51e5538
commit 7d03fb4108
6 changed files with 38 additions and 41 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,14 +13,29 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Mouse { public class Mouse {
private HashMap<Integer[], ArrayList<MousePath>> gridMap; private ArrayList<ArrayList<ArrayList<MousePath>>> grid;
int granularity;
//private ArrayList<MousePath> mousePaths; //private ArrayList<MousePath> mousePaths;
private int windowWidth;
private int windowHeight;
PointerInfo pointer; PointerInfo pointer;
public Mouse(String path) { public Mouse(String path, int windowWidth, int windowHeight) {
this.windowWidth = windowWidth;
this.windowHeight = windowHeight;
granularity = 10;
// TODO: Is there another way to get the pointer location?? // TODO: Is there another way to get the pointer location??
pointer = MouseInfo.getPointerInfo(); pointer = MouseInfo.getPointerInfo();
gridMap = new HashMap<Integer[], ArrayList<MousePath>>();
grid = new ArrayList<ArrayList<ArrayList<MousePath>>>();
for (int i = 0; i < 2 * (windowWidth / granularity) + 1; i++) {
grid.add(new ArrayList<ArrayList<MousePath>>());
for (int j = 0; j < 2 * (windowHeight / granularity) + 1; j++) {
grid.get(i).add(new ArrayList<MousePath>());
}
}
System.out.println("Grid size: " + grid.size() + "x" + grid.get(0).size());
ArrayList<MousePath> mousePaths = readFile(path); ArrayList<MousePath> mousePaths = readFile(path);
assignPathsToGrid(mousePaths); assignPathsToGrid(mousePaths);
} }
@ -29,7 +44,7 @@ public class Mouse {
int[] mouseLoc = getMouseLocation(); int[] mouseLoc = getMouseLocation();
int deltaX = endingX - mouseLoc[0]; int deltaX = endingX - mouseLoc[0];
int deltaY = endingY - mouseLoc[1]; int deltaY = endingY - mouseLoc[1];
Integer[] gridKey = getGridMapKey(deltaX, deltaY); int[] gridIndex = getGridIndex(deltaX, deltaY);
// Fetch from map // Fetch from map
} }
@ -44,36 +59,23 @@ public class Mouse {
} }
public Integer[] getGridMapKey(int deltaX, int deltaY) { public int[] getGridIndex(int deltaX, int deltaY) {
Integer[] gridKey = {deltaX / 100, deltaY / 100}; int offsetX = windowWidth / granularity;
return gridKey; int offsetY = windowHeight / granularity;
int[] gridIndex = {deltaX / granularity + offsetX, deltaY / granularity + offsetY};
return gridIndex;
} }
public void assignPathsToGrid(ArrayList<MousePath> mousePaths) { public void assignPathsToGrid(ArrayList<MousePath> mousePaths) {
Integer[] key1 = getGridMapKey(0, 0); for (MousePath mousePath : mousePaths) {
Integer[] key2 = getGridMapKey(0, 0);
gridMap.put(key1, new ArrayList<MousePath>());
if (gridMap.containsKey(key2)) {
System.out.println("same key!");
}
if (gridMap.containsKey(key1)) {
System.out.println("Same key2!");
}
/*for (MousePath mousePath : mousePaths) {
int deltaX = mousePath.getDeltaX(); int deltaX = mousePath.getDeltaX();
int deltaY = mousePath.getDeltaY(); int deltaY = mousePath.getDeltaY();
Integer[] gridKey = getGridMapKey(deltaX, deltaY);
if (gridMap.containsKey(gridKey)) { int[] gridIndex = getGridIndex(deltaX, deltaY);
System.out.println("Same category!"); //System.out.println(deltaX + "," + deltaY);
gridMap.get(gridKey).add(mousePath); //System.out.println("index: " + gridIndex[0] + "," + gridIndex[1]);
} grid.get(gridIndex[0]).get(gridIndex[1]).add(mousePath);
else { }
ArrayList<MousePath> newPath = new ArrayList<MousePath>();
newPath.add(mousePath);
gridMap.put(gridKey, newPath);
}
}*/
} }
public ArrayList<MousePath> readFile(String path) { public ArrayList<MousePath> readFile(String path) {
@ -140,18 +142,13 @@ public class Mouse {
public void displayPaths() { public void displayPaths() {
System.out.println("Displaying paths in HashMap..."); for (int i = 0; i < 2 * (windowWidth / granularity) + 1; i++) {
for (HashMap.Entry<Integer[], ArrayList<MousePath>> entry : gridMap.entrySet()) { for (int j = 0; j < 2 * (windowHeight / granularity) + 1; j++) {
Integer[] gridKey = entry.getKey(); if (grid.get(i).get(j).size() > 0) {
System.out.println("Key is: (" + gridKey[0] + ", " + gridKey[1] + ")"); System.out.println("(" + i + "," + j + ")");
System.out.println("There are " + grid.get(i).get(j).size() + " paths in this delta range.");
ArrayList<MousePath> mousePaths = entry.getValue(); }
System.out.println("There are " + mousePaths.size() + " paths with these deltas.");
for (MousePath path : mousePaths) {
//path.display();
System.out.println("----------------------------------------------------------");
} }
System.out.println("Size of HashMap: " + gridMap.size());
} }
} }
} }

View File

@ -7,7 +7,7 @@ public class main {
System.out.println("Starting mouse script..."); System.out.println("Starting mouse script...");
System.out.println("Fetching mouse paths from script..."); System.out.println("Fetching mouse paths from script...");
Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt"); Mouse mouse = new Mouse("/home/dpapp/GhostMouse/coordinates.txt", 1920, 1080);
mouse.displayPaths(); mouse.displayPaths();
System.out.println("Finished..."); System.out.println("Finished...");
} }