[1040] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
[1030] | 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.usability.sandboxapp;
|
---|
| 16 |
|
---|
| 17 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
|
---|
| 18 |
|
---|
| 19 | import java.io.File;
|
---|
| 20 | import java.io.IOException;
|
---|
| 21 |
|
---|
| 22 | import org.tc33.jheatchart.HeatChart;
|
---|
| 23 |
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
| 28 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
| 29 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
|
---|
| 32 |
|
---|
[1040] | 33 | /**
|
---|
| 34 | * <p>
|
---|
| 35 | * TODO comment
|
---|
| 36 | * </p>
|
---|
| 37 | *
|
---|
| 38 | * @author Alexander Deicke
|
---|
| 39 | */
|
---|
[1030] | 40 | public class CreateHeatmapImageFromTaskTreeDemoApp {
|
---|
| 41 |
|
---|
| 42 | private static final String fileToParse = "javatrace.xml";
|
---|
[1040] | 43 |
|
---|
[1030] | 44 | private static final String heatmapFilename = "click-heatmap.png";
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * <p>
|
---|
| 48 | * TODO: comment
|
---|
| 49 | * </p>
|
---|
| 50 | *
|
---|
| 51 | * @param args
|
---|
| 52 | * @throws IOException
|
---|
| 53 | */
|
---|
| 54 | public static void main(String[] args) throws IOException {
|
---|
| 55 | ITaskTree taskTree = GenerateTaskTreeUtil.getTaskTreeFromFile(fileToParse);
|
---|
| 56 | FilterStatistic mouseInteractions = filterMouseInteractions(taskTree);
|
---|
| 57 | double[][] data = fillHeatmapDataMatrix(mouseInteractions);
|
---|
| 58 | createAndSaveHeatmapImage(mouseInteractions, data);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | private static FilterStatistic filterMouseInteractions(ITaskTree taskTree) {
|
---|
| 62 | return new TaskTreeFilter(new IterativeDFSFilterStrategy())
|
---|
| 63 | .filterByEventType(MOUSE_BUTTON_INTERACTION).from(taskTree);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | private static double[][] fillHeatmapDataMatrix(FilterStatistic mouseInteractions) {
|
---|
| 67 | double data[][] = new double[1024][768];
|
---|
| 68 | for (ITaskTreeNode node : mouseInteractions.nodesMatchedFilter()) {
|
---|
| 69 | MouseButtonInteraction interaction =
|
---|
| 70 | (MouseButtonInteraction) ((IEventTask) node).getEventType();
|
---|
| 71 | int x = interaction.getX();
|
---|
| 72 | int y = interaction.getY();
|
---|
| 73 | data[x][y]++;
|
---|
| 74 | boolean x_has_left = x - 1 >= 0;
|
---|
| 75 | boolean x_has_right = x + 1 <= 800;
|
---|
| 76 | boolean y_has_top = y - 1 >= 0;
|
---|
| 77 | boolean y_has_bottem = y + 1 <= 800;
|
---|
| 78 | if (x_has_left) {
|
---|
| 79 | data[x - 1][y]++; // left
|
---|
| 80 | if (y_has_top)
|
---|
| 81 | data[x - 1][y + 1]++; // topleft
|
---|
| 82 | if (y_has_bottem)
|
---|
| 83 | data[x - 1][y - 1]++; // bottomleft
|
---|
| 84 | }
|
---|
| 85 | if (x_has_right) {
|
---|
| 86 | data[x + 1][y]++; // right
|
---|
| 87 | if (y_has_top)
|
---|
| 88 | data[x + 1][y + 1]++; // topright
|
---|
| 89 | if (y_has_bottem)
|
---|
| 90 | data[x + 1][y - 1]++; // bottomright
|
---|
| 91 | }
|
---|
| 92 | if (y_has_top) {
|
---|
| 93 | data[x][y + 1]++; // top
|
---|
| 94 | }
|
---|
| 95 | if (y_has_bottem) {
|
---|
| 96 | data[x][y - 1]++; // bottom
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | return data;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | private static void createAndSaveHeatmapImage(FilterStatistic mouseInteractions, double[][] data)
|
---|
| 103 | throws IOException
|
---|
| 104 | {
|
---|
| 105 | HeatChart hc = new HeatChart(data);
|
---|
| 106 | hc.setTitle(mouseInteractions.nodesMatchedFilter().size() + "Mouse interactions");
|
---|
| 107 | // Cautious, took some time!
|
---|
| 108 | // Also you have to run the JVM with extended heapspace, like -Xms512m -Xmx4096m
|
---|
| 109 | hc.saveToFile(new File(heatmapFilename));
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | }
|
---|