Added shortest/longest/average period to node info panel

This commit is contained in:
nifi 2010-09-08 12:40:18 +00:00
parent 20ea27c468
commit c829c7f728
3 changed files with 73 additions and 16 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: SensorDataAggregator.java,v 1.4 2010/09/06 22:19:09 nifi Exp $ * $Id: SensorDataAggregator.java,v 1.5 2010/09/08 12:40:18 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 20 aug 2008 * Created : 20 aug 2008
* Updated : $Date: 2010/09/06 22:19:09 $ * Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.4 $ * $Revision: 1.5 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -52,6 +52,8 @@ public class SensorDataAggregator implements SensorInfo {
private int seqnoDelta = 0; private int seqnoDelta = 0;
private int dataCount; private int dataCount;
private int duplicates = 0; private int duplicates = 0;
private long shortestPeriod = Long.MAX_VALUE;
private long longestPeriod = 0;
public SensorDataAggregator(Node node) { public SensorDataAggregator(Node node) {
this.node = node; this.node = node;
@ -88,7 +90,7 @@ public class SensorDataAggregator implements SensorInfo {
if (s <= maxSeqno) { if (s <= maxSeqno) {
// Check for duplicates among the last 5 packets // Check for duplicates among the last 5 packets
for(int n = node.getSensorDataCount(), i = n > 5 ? n - 5 : 0; i < n; i++) { for(int n = node.getSensorDataCount() - 1, i = n > 5 ? n - 5 : 0; i < n; i++) {
SensorData sd = node.getSensorData(i); SensorData sd = node.getSensorData(i);
if (sd.getValue(SEQNO) != seqn || sd == data || sd.getValueCount() != data.getValueCount()) { if (sd.getValue(SEQNO) != seqn || sd == data || sd.getValueCount() != data.getValueCount()) {
// Not a duplicate // Not a duplicate
@ -130,6 +132,15 @@ public class SensorDataAggregator implements SensorInfo {
values[i] += data.getValue(i); values[i] += data.getValue(i);
} }
if (node.getSensorDataCount() > 1) {
long timeDiff = data.getNodeTime() - node.getSensorData(node.getSensorDataCount() - 2).getNodeTime();
if (timeDiff > longestPeriod) {
longestPeriod = timeDiff;
}
if (timeDiff < shortestPeriod) {
shortestPeriod = timeDiff;
}
}
// Handle wrapping sequence numbers // Handle wrapping sequence numbers
if (dataCount > 0 && maxSeqno - s > 2) { if (dataCount > 0 && maxSeqno - s > 2) {
s += maxSeqno - seqnoDelta; s += maxSeqno - seqnoDelta;
@ -151,6 +162,8 @@ public class SensorDataAggregator implements SensorInfo {
minSeqno = Integer.MAX_VALUE; minSeqno = Integer.MAX_VALUE;
maxSeqno = Integer.MIN_VALUE; maxSeqno = Integer.MIN_VALUE;
seqnoDelta = 0; seqnoDelta = 0;
shortestPeriod = Long.MAX_VALUE;
longestPeriod = 0;
} }
public String toString() { public String toString() {
@ -236,4 +249,21 @@ public class SensorDataAggregator implements SensorInfo {
return maxSeqno; return maxSeqno;
} }
public long getAveragePeriod() {
if (dataCount > 1) {
long first = node.getSensorData(0).getNodeTime();
long last = node.getSensorData(node.getSensorDataCount() - 1).getNodeTime();
return (last - first) / dataCount;
}
return 0;
}
public long getShortestPeriod() {
return shortestPeriod;
}
public long getLongestPeriod() {
return longestPeriod;
}
} }

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: NodeInfoPanel.java,v 1.1 2010/09/06 22:42:29 nifi Exp $ * $Id: NodeInfoPanel.java,v 1.2 2010/09/08 12:40:18 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 6 sep 2010 * Created : 6 sep 2010
* Updated : $Date: 2010/09/06 22:42:29 $ * Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -101,16 +101,40 @@ public class NodeInfoPanel extends JPanel implements Visualizer {
} }
} }
private StringBuilder addTime(StringBuilder sb, long time) {
time /= 1000;
if (time > 24 * 60 * 60) {
long days = time / (24 * 60 * 60);
sb.append(days).append(" days, ");
time -= days * 24 * 60 * 60;
}
if (time > 60 * 60) {
long hours = time / (60 * 60);
sb.append(hours).append(" hours, ");
time -= hours * 60 * 60;
}
sb.append(time / 60).append(" min, ").append(time % 60).append(" sec");
return sb;
}
private void updateInfoArea() { private void updateInfoArea() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (selectedNodes != null) { if (selectedNodes != null) {
for(Node node : selectedNodes) { for(Node node : selectedNodes) {
SensorDataAggregator sda = node.getSensorDataAggregator(); SensorDataAggregator sda = node.getSensorDataAggregator();
sb.append(node.getName()).append('\n'); long longest = sda.getLongestPeriod();
sb.append(" Packets Received: \t" + sda.getPacketCount() + '\n' sb.append(node.getName() + '\n'
+ " Duplicates: \t" + sda.getDuplicateCount() + '\n' + " Packets Received: \t" + sda.getPacketCount() + '\n'
+ " Unique Sensor Values:\t" + sda.getDataCount() + " Duplicates: \t" + sda.getDuplicateCount() + '\n');
+ "\n--------------------------------------------------------\n"); if (longest > 0) {
sb.append(" Average period:\t");
addTime(sb, sda.getAveragePeriod()).append('\n');
sb.append(" Shortest period:\t");
addTime(sb, sda.getShortestPeriod()).append('\n');
sb.append(" Longest period:\t");
addTime(sb, longest).append('\n');
}
sb.append("--------------------------------------------------------\n");
} }
} }
infoArea.setText(sb.toString()); infoArea.setText(sb.toString());

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: PacketChartPanel.java,v 1.1 2010/09/06 22:42:29 nifi Exp $ * $Id: PacketChartPanel.java,v 1.2 2010/09/08 12:40:18 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 6 sep 2010 * Created : 6 sep 2010
* Updated : $Date: 2010/09/06 22:42:29 $ * Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -155,8 +155,11 @@ public class PacketChartPanel extends JPanel implements Visualizer {
} else { } else {
long min = sd.getSystemTime() / 60000; long min = sd.getSystemTime() / 60000;
if (min != minute) { if (min != minute) {
for(; lastMinute < minute - 1; lastMinute++) { if (lastMinute < minute) {
series.add(new Minute(new Date(lastMinute * 60000L)), 0); series.add(new Minute(new Date(lastMinute * 60000L)), 0);
if (lastMinute < minute - 1) {
series.add(new Minute(new Date((minute - 1) * 60000L)), 0);
}
} }
series.add(new Minute(new Date(minute * 60000L)), count); series.add(new Minute(new Date(minute * 60000L)), count);
count = 0; count = 0;