Added configuration of max item count in time charts

This commit is contained in:
nifi 2010-10-13 22:55:47 +00:00
parent 1ca83eb314
commit 0d7f895744
2 changed files with 49 additions and 31 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: CollectServer.java,v 1.27 2010/10/12 16:28:19 nifi Exp $ * $Id: CollectServer.java,v 1.28 2010/10/13 22:55:47 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/10/12 16:28:19 $ * Updated : $Date: 2010/10/13 22:55:47 $
* $Revision: 1.27 $ * $Revision: 1.28 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -147,6 +147,7 @@ public class CollectServer implements SerialConnectionListener {
private boolean doSendInitAtStartup = false; private boolean doSendInitAtStartup = false;
private String initScript; private String initScript;
private int defaultMaxItemCount = 250;
private long nodeTimeDelta; private long nodeTimeDelta;
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -241,7 +242,6 @@ public class CollectServer implements SerialConnectionListener {
if (image != null) { if (image != null) {
mapPanel.setMapBackground(image); mapPanel.setMapBackground(image);
} }
final int defaultMaxItemCount = 250;
NodeControl nodeControl = new NodeControl(this, MAIN); NodeControl nodeControl = new NodeControl(this, MAIN);
visualizers = new Visualizer[] { visualizers = new Visualizer[] {
@ -265,7 +265,6 @@ public class CollectServer implements SerialConnectionListener {
setRangeTick(5); setRangeTick(5);
setRangeMinimumSize(10.0); setRangeMinimumSize(10.0);
setGlobalRange(true); setGlobalRange(true);
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getTemperature(); return data.getTemperature();
@ -277,7 +276,6 @@ public class CollectServer implements SerialConnectionListener {
setRangeTick(1); setRangeTick(1);
setRangeMinimumSize(4.0); setRangeMinimumSize(4.0);
setGlobalRange(true); setGlobalRange(true);
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getBatteryVoltage(); return data.getBatteryVoltage();
@ -290,7 +288,6 @@ public class CollectServer implements SerialConnectionListener {
setRangeTick(5); setRangeTick(5);
setRangeMinimumSize(10.0); setRangeMinimumSize(10.0);
setGlobalRange(true); setGlobalRange(true);
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getBatteryIndicator(); return data.getBatteryIndicator();
@ -298,7 +295,6 @@ public class CollectServer implements SerialConnectionListener {
}, },
new TimeChartPanel(this, SENSORS, "Relative Humidity", "Humidity", "Time", "%") { new TimeChartPanel(this, SENSORS, "Relative Humidity", "Humidity", "Time", "%") {
{ {
setMaxItemCount(defaultMaxItemCount);
chart.getXYPlot().getRangeAxis().setRange(0.0, 100.0); chart.getXYPlot().getRangeAxis().setRange(0.0, 100.0);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
@ -306,17 +302,11 @@ public class CollectServer implements SerialConnectionListener {
} }
}, },
new TimeChartPanel(this, SENSORS, "Light 1", "Light 1", "Time", "-") { new TimeChartPanel(this, SENSORS, "Light 1", "Light 1", "Time", "-") {
{
setMaxItemCount(defaultMaxItemCount);
}
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getLight1(); return data.getLight1();
} }
}, },
new TimeChartPanel(this, SENSORS, "Light 2", "Light 2", "Time", "-") { new TimeChartPanel(this, SENSORS, "Light 2", "Light 2", "Time", "-") {
{
setMaxItemCount(defaultMaxItemCount);
}
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getLight2(); return data.getLight2();
} }
@ -326,7 +316,6 @@ public class CollectServer implements SerialConnectionListener {
ValueAxis axis = chart.getXYPlot().getRangeAxis(); ValueAxis axis = chart.getXYPlot().getRangeAxis();
((NumberAxis)axis).setAutoRangeIncludesZero(true); ((NumberAxis)axis).setAutoRangeIncludesZero(true);
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getValue(SensorData.NUM_NEIGHBORS); return data.getValue(SensorData.NUM_NEIGHBORS);
@ -337,7 +326,6 @@ public class CollectServer implements SerialConnectionListener {
ValueAxis axis = chart.getXYPlot().getRangeAxis(); ValueAxis axis = chart.getXYPlot().getRangeAxis();
((NumberAxis)axis).setAutoRangeIncludesZero(true); ((NumberAxis)axis).setAutoRangeIncludesZero(true);
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getValue(SensorData.BEACON_INTERVAL); return data.getValue(SensorData.BEACON_INTERVAL);
@ -348,7 +336,6 @@ public class CollectServer implements SerialConnectionListener {
ValueAxis axis = chart.getXYPlot().getRangeAxis(); ValueAxis axis = chart.getXYPlot().getRangeAxis();
((NumberAxis)axis).setAutoRangeIncludesZero(true); ((NumberAxis)axis).setAutoRangeIncludesZero(true);
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getValue(SensorData.HOPS); return data.getValue(SensorData.HOPS);
@ -369,7 +356,6 @@ public class CollectServer implements SerialConnectionListener {
ValueAxis axis = chart.getXYPlot().getRangeAxis(); ValueAxis axis = chart.getXYPlot().getRangeAxis();
((NumberAxis)axis).setAutoRangeIncludesZero(true); ((NumberAxis)axis).setAutoRangeIncludesZero(true);
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getValue(SensorData.BEST_NEIGHBOR_RTMETRIC) + data.getValue(SensorData.BEST_NEIGHBOR_ETX); return data.getValue(SensorData.BEST_NEIGHBOR_RTMETRIC) + data.getValue(SensorData.BEST_NEIGHBOR_ETX);
@ -380,7 +366,6 @@ public class CollectServer implements SerialConnectionListener {
ValueAxis axis = chart.getXYPlot().getRangeAxis(); ValueAxis axis = chart.getXYPlot().getRangeAxis();
((NumberAxis)axis).setAutoRangeIncludesZero(true); ((NumberAxis)axis).setAutoRangeIncludesZero(true);
axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
setMaxItemCount(defaultMaxItemCount);
} }
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getValue(SensorData.BEST_NEIGHBOR_ETX); return data.getValue(SensorData.BEST_NEIGHBOR_ETX);
@ -415,9 +400,6 @@ public class CollectServer implements SerialConnectionListener {
} }
}, },
new TimeChartPanel(this, NETWORK, "Latency", "Latency", "Time", "Seconds") { new TimeChartPanel(this, NETWORK, "Latency", "Latency", "Time", "Seconds") {
{
setMaxItemCount(defaultMaxItemCount);
}
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getLatency(); return data.getLatency();
} }
@ -571,11 +553,6 @@ public class CollectServer implements SerialConnectionListener {
} }
}, },
new TimeChartPanel(this, POWER, "Power History", "Historical Power Consumption", "Time", "mW") { new TimeChartPanel(this, POWER, "Power History", "Historical Power Consumption", "Time", "mW") {
{
// ValueAxis axis = chart.getCategoryPlot().getRangeAxis();
// ((NumberAxis)axis).setAutoRangeIncludesZero(true);
setMaxItemCount(defaultMaxItemCount);
}
protected double getSensorDataValue(SensorData data) { protected double getSensorDataValue(SensorData data) {
return data.getAveragePower(); return data.getAveragePower();
} }
@ -715,6 +692,29 @@ public class CollectServer implements SerialConnectionListener {
toolsMenu.add(runInitScriptItem); toolsMenu.add(runInitScriptItem);
toolsMenu.addSeparator(); toolsMenu.addSeparator();
item = new JMenuItem("Set Max Item Count...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int value = getUserInputAsInteger("Specify Max Item Count",
"Please specify max item count for the time charts.\n" +
"Charts with more values will aggregate the values into fewer items.",
defaultMaxItemCount);
if (value > 0) {
defaultMaxItemCount = value;
if (visualizers != null) {
for(Visualizer v : visualizers) {
if (v instanceof TimeChartPanel) {
((TimeChartPanel)v).setMaxItemCount(defaultMaxItemCount);
}
}
}
}
}
});
toolsMenu.add(item);
final JCheckBoxMenuItem baseShapeItem = new JCheckBoxMenuItem("Base Shape Visible"); final JCheckBoxMenuItem baseShapeItem = new JCheckBoxMenuItem("Base Shape Visible");
baseShapeItem.setSelected(true); baseShapeItem.setSelected(true);
baseShapeItem.addActionListener(new ActionListener() { baseShapeItem.addActionListener(new ActionListener() {
@ -753,6 +753,19 @@ public class CollectServer implements SerialConnectionListener {
} }
} }
private int getUserInputAsInteger(String title, String message, int defaultValue) {
String s = (String)JOptionPane.showInputDialog(
window, message, title, JOptionPane.PLAIN_MESSAGE, null, null, Integer.toString(defaultValue));
if (s != null) {
try {
return Integer.parseInt(s);
} catch (Exception e) {
JOptionPane.showMessageDialog(window, "Illegal value", "Error", JOptionPane.ERROR_MESSAGE);
}
}
return -1;
}
void start(SerialConnection connection) { void start(SerialConnection connection) {
if (this.serialConnection != null) { if (this.serialConnection != null) {
throw new IllegalStateException("already started"); throw new IllegalStateException("already started");
@ -851,6 +864,10 @@ public class CollectServer implements SerialConnectionListener {
return configTable.getProperty(property, config.getProperty(property, defaultValue)); return configTable.getProperty(property, config.getProperty(property, defaultValue));
} }
public int getDefaultMaxItemCount() {
return defaultMaxItemCount;
}
public Action getMoteProgramAction() { public Action getMoteProgramAction() {
return moteProgramAction; return moteProgramAction;
} }

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: TimeChartPanel.java,v 1.7 2010/09/15 16:15:10 nifi Exp $ * $Id: TimeChartPanel.java,v 1.8 2010/10/13 22:55:47 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2010/09/15 16:15:10 $ * Updated : $Date: 2010/10/13 22:55:47 $
* $Revision: 1.7 $ * $Revision: 1.8 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -92,6 +92,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
this.chartPanel = new ChartPanel(chart); this.chartPanel = new ChartPanel(chart);
this.chartPanel.setPreferredSize(new Dimension(500, 270)); this.chartPanel.setPreferredSize(new Dimension(500, 270));
setBaseShapeVisible(true); setBaseShapeVisible(true);
setMaxItemCount(server.getDefaultMaxItemCount());
add(chartPanel, BorderLayout.CENTER); add(chartPanel, BorderLayout.CENTER);
} }
@ -197,7 +198,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
int sensorDataCount = node.getSensorDataCount(); int sensorDataCount = node.getSensorDataCount();
if (sensorDataCount > maxItemCount) { if (sensorDataCount > maxItemCount) {
int groupSize = sensorDataCount / maxItemCount; int groupSize = sensorDataCount / maxItemCount;
if (sensorDataCount / groupSize > maxItemCount) { if (sensorDataCount / groupSize >= maxItemCount) {
groupSize++; groupSize++;
} }
return groupSize; return groupSize;