[1030] | 1 |
|
---|
| 2 | package de.ugoe.cs.autoquest.usability.sandboxapp;
|
---|
| 3 |
|
---|
| 4 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
|
---|
| 5 |
|
---|
| 6 | import java.io.File;
|
---|
| 7 | import java.io.IOException;
|
---|
| 8 |
|
---|
| 9 | import org.tc33.jheatchart.HeatChart;
|
---|
| 10 |
|
---|
| 11 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
| 12 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
| 13 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 14 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
| 15 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
| 16 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
| 17 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
| 18 | import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
|
---|
| 19 |
|
---|
| 20 | public class CreateHeatmapImageFromTaskTreeDemoApp {
|
---|
| 21 |
|
---|
| 22 | private static final String fileToParse = "javatrace.xml";
|
---|
| 23 |
|
---|
| 24 | private static final String heatmapFilename = "click-heatmap.png";
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * <p>
|
---|
| 28 | * TODO: comment
|
---|
| 29 | * </p>
|
---|
| 30 | *
|
---|
| 31 | * @param args
|
---|
| 32 | * @throws IOException
|
---|
| 33 | */
|
---|
| 34 | public static void main(String[] args) throws IOException {
|
---|
| 35 | ITaskTree taskTree = GenerateTaskTreeUtil.getTaskTreeFromFile(fileToParse);
|
---|
| 36 | FilterStatistic mouseInteractions = filterMouseInteractions(taskTree);
|
---|
| 37 | double[][] data = fillHeatmapDataMatrix(mouseInteractions);
|
---|
| 38 | createAndSaveHeatmapImage(mouseInteractions, data);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | private static FilterStatistic filterMouseInteractions(ITaskTree taskTree) {
|
---|
| 42 | return new TaskTreeFilter(new IterativeDFSFilterStrategy())
|
---|
| 43 | .filterByEventType(MOUSE_BUTTON_INTERACTION).from(taskTree);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private static double[][] fillHeatmapDataMatrix(FilterStatistic mouseInteractions) {
|
---|
| 47 | double data[][] = new double[1024][768];
|
---|
| 48 | for (ITaskTreeNode node : mouseInteractions.nodesMatchedFilter()) {
|
---|
| 49 | MouseButtonInteraction interaction =
|
---|
| 50 | (MouseButtonInteraction) ((IEventTask) node).getEventType();
|
---|
| 51 | int x = interaction.getX();
|
---|
| 52 | int y = interaction.getY();
|
---|
| 53 | data[x][y]++;
|
---|
| 54 | boolean x_has_left = x - 1 >= 0;
|
---|
| 55 | boolean x_has_right = x + 1 <= 800;
|
---|
| 56 | boolean y_has_top = y - 1 >= 0;
|
---|
| 57 | boolean y_has_bottem = y + 1 <= 800;
|
---|
| 58 | if (x_has_left) {
|
---|
| 59 | data[x - 1][y]++; // left
|
---|
| 60 | if (y_has_top)
|
---|
| 61 | data[x - 1][y + 1]++; // topleft
|
---|
| 62 | if (y_has_bottem)
|
---|
| 63 | data[x - 1][y - 1]++; // bottomleft
|
---|
| 64 | }
|
---|
| 65 | if (x_has_right) {
|
---|
| 66 | data[x + 1][y]++; // right
|
---|
| 67 | if (y_has_top)
|
---|
| 68 | data[x + 1][y + 1]++; // topright
|
---|
| 69 | if (y_has_bottem)
|
---|
| 70 | data[x + 1][y - 1]++; // bottomright
|
---|
| 71 | }
|
---|
| 72 | if (y_has_top) {
|
---|
| 73 | data[x][y + 1]++; // top
|
---|
| 74 | }
|
---|
| 75 | if (y_has_bottem) {
|
---|
| 76 | data[x][y - 1]++; // bottom
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | return data;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | private static void createAndSaveHeatmapImage(FilterStatistic mouseInteractions, double[][] data)
|
---|
| 83 | throws IOException
|
---|
| 84 | {
|
---|
| 85 | HeatChart hc = new HeatChart(data);
|
---|
| 86 | hc.setTitle(mouseInteractions.nodesMatchedFilter().size() + "Mouse interactions");
|
---|
| 87 | // Cautious, took some time!
|
---|
| 88 | // Also you have to run the JVM with extended heapspace, like -Xms512m -Xmx4096m
|
---|
| 89 | hc.saveToFile(new File(heatmapFilename));
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | }
|
---|