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
* 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
* Created : 20 aug 2008
* Updated : $Date: 2010/09/06 22:19:09 $
* $Revision: 1.4 $
* Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.5 $
*/
package se.sics.contiki.collect;
@ -52,6 +52,8 @@ public class SensorDataAggregator implements SensorInfo {
private int seqnoDelta = 0;
private int dataCount;
private int duplicates = 0;
private long shortestPeriod = Long.MAX_VALUE;
private long longestPeriod = 0;
public SensorDataAggregator(Node node) {
this.node = node;
@ -88,7 +90,7 @@ public class SensorDataAggregator implements SensorInfo {
if (s <= maxSeqno) {
// 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);
if (sd.getValue(SEQNO) != seqn || sd == data || sd.getValueCount() != data.getValueCount()) {
// Not a duplicate
@ -130,6 +132,15 @@ public class SensorDataAggregator implements SensorInfo {
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
if (dataCount > 0 && maxSeqno - s > 2) {
s += maxSeqno - seqnoDelta;
@ -151,6 +162,8 @@ public class SensorDataAggregator implements SensorInfo {
minSeqno = Integer.MAX_VALUE;
maxSeqno = Integer.MIN_VALUE;
seqnoDelta = 0;
shortestPeriod = Long.MAX_VALUE;
longestPeriod = 0;
}
public String toString() {
@ -236,4 +249,21 @@ public class SensorDataAggregator implements SensorInfo {
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
* 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
* Created : 6 sep 2010
* Updated : $Date: 2010/09/06 22:42:29 $
* $Revision: 1.1 $
* Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.2 $
*/
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() {
StringBuilder sb = new StringBuilder();
if (selectedNodes != null) {
for(Node node : selectedNodes) {
SensorDataAggregator sda = node.getSensorDataAggregator();
sb.append(node.getName()).append('\n');
sb.append(" Packets Received: \t" + sda.getPacketCount() + '\n'
+ " Duplicates: \t" + sda.getDuplicateCount() + '\n'
+ " Unique Sensor Values:\t" + sda.getDataCount()
+ "\n--------------------------------------------------------\n");
long longest = sda.getLongestPeriod();
sb.append(node.getName() + '\n'
+ " Packets Received: \t" + sda.getPacketCount() + '\n'
+ " Duplicates: \t" + sda.getDuplicateCount() + '\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());

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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
* Created : 6 sep 2010
* Updated : $Date: 2010/09/06 22:42:29 $
* $Revision: 1.1 $
* Updated : $Date: 2010/09/08 12:40:18 $
* $Revision: 1.2 $
*/
package se.sics.contiki.collect.gui;
@ -155,8 +155,11 @@ public class PacketChartPanel extends JPanel implements Visualizer {
} else {
long min = sd.getSystemTime() / 60000;
if (min != minute) {
for(; lastMinute < minute - 1; lastMinute++) {
if (lastMinute < minute) {
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);
count = 0;