@Override public void loop(GraphView window, Interval interval) { Graph graph = graphModel.getGraph(window); int count = graph.getEdgeCount(); graph.setAttribute(NB_EDGES, count, interval.getLow()); graph.setAttribute(NB_EDGES, count, interval.getHigh()); counts.put(interval.getLow(), count); counts.put(interval.getHigh(), count); }
@Override public String getReport() { // Time series XYSeries dSeries = ChartUtils.createXYSeries(counts, "Nb Edges Time Series"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(dSeries); JFreeChart chart = ChartFactory.createXYLineChart( "# Edges Time Series", "Time", "# Edges", dataset, PlotOrientation.VERTICAL, true, false, false); chart.removeLegend(); ChartUtils.decorateChart(chart); ChartUtils.scaleChart(chart, dSeries, false); String imageFile = ChartUtils.renderChart(chart, "nb-edges-ts.png"); NumberFormat f = new DecimalFormat("#0.000"); String report = "<HTML> <BODY> <h1>Dynamic Number of Edges Report </h1> " + "<hr>" + "<br> Bounds: from " + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window + "<br> Tick: " + tick + "<br><br><h2> Number of edges over time: </h2>" + "<br /><br />" + imageFile; /*for (Interval<Integer> count : counts) { report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />"; }*/ report += "<br /><br /></BODY></HTML>"; return report; }
private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) { GraphController graphController = Lookup.getDefault().lookup(GraphController.class); GraphModel graphModel = graphController.getGraphModel(); double window = statistics.getWindow(); double tick = statistics.getTick(); GraphView currentView = graphModel.getVisibleView(); Interval bounds = statistics.getBounds(); if (bounds == null) { if (currentView.isMainView()) { bounds = graphModel.getTimeBounds(); } else { bounds = currentView.getTimeInterval(); } statistics.setBounds(bounds); } if (dynamicLongTask != null) { // Count int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick); dynamicLongTask.start(c); } // Init statistics.execute(graphModel); // Loop for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) { double high = low + window; Graph graph = graphModel.getGraphVisible(); graph.writeLock(); GraphView view = graphModel.createView(); Subgraph g = graphModel.getGraph(view); TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView); if (Double.isInfinite(nodeIndex.getMinTimestamp()) && Double.isInfinite(nodeIndex.getMaxTimestamp())) { for (Node node : graph.getNodes()) { g.addNode(node); } } else { for (Node node : nodeIndex.get(new Interval(low, high))) { g.addNode(node); } } TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView); if (Double.isInfinite(edgeIndex.getMinTimestamp()) && Double.isInfinite(edgeIndex.getMaxTimestamp())) { for (Edge edge : graph.getEdges()) { if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) { g.addEdge(edge); } } } else { for (Edge edge : edgeIndex.get(new Interval(low, high))) { if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) { g.addEdge(edge); } } } graph.writeUnlock(); statistics.loop(g.getView(), new Interval(low, high)); // Cancelled? if (dynamicLongTask != null && dynamicLongTask.isCancelled()) { return; } else if (dynamicLongTask != null) { dynamicLongTask.progress(); } } statistics.end(); model.addReport(statistics); }