source: autoquest-core-usability-evaluation-test/src/main/java/de/ugoe/cs/autoquest/usability/sandboxapp/CreateHeatmapImageFromTaskTreeDemoApp.java @ 1030

Last change on this file since 1030 was 1030, checked in by adeicke, 11 years ago

Initial commit.

  • Property svn:mime-type set to text/plain
File size: 3.5 KB
Line 
1
2package de.ugoe.cs.autoquest.usability.sandboxapp;
3
4import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
5
6import java.io.File;
7import java.io.IOException;
8
9import org.tc33.jheatchart.HeatChart;
10
11import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
12import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
13import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
14import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
15import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
16import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
17import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
18import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
19
20public 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}
Note: See TracBrowser for help on using the repository browser.