use of net.sourceforge.processdash.data.DateData in project processdash by dtuma.
the class DataRepository method dumpRepository.
/** Print textual information about the data elements in the repostory.
*
* @param out a stream to write the information to
* @param filt a collection of prefixes that should be exported
* @param style the style of information to print, should be one of
* DUMP_STYLE_TEXT, DUMP_STYLE_DATA, or DUMP_STYLE_CALC.
*/
public void dumpRepository(PrintWriter out, Collection filt, int style) {
gc(null);
Iterator k = getKeys(filt, null);
// print out all element values.
while (k.hasNext()) {
String name = (String) k.next();
if (Filter.matchesFilter(filt, name)) {
try {
DataElement de = getOrCreateDefaultDataElement(name);
if (de == null || de.datafile == null)
continue;
SaveableData sd;
if (style == DUMP_STYLE_CALC)
sd = de.getValue();
else
sd = de.getSimpleValue();
if (sd == null)
continue;
String value = null;
if (style != DUMP_STYLE_TEXT) {
value = sd.saveString();
} else if (sd instanceof DateData) {
value = ((DateData) sd).formatDate();
} else if (sd instanceof StringData) {
value = StringData.escapeString(((StringData) sd).getString());
} else
value = sd.toString();
if (style == DUMP_STYLE_TEXT) {
if (name.indexOf(',') != -1)
name = EscapeString.escape(name, '\\', ",", "c");
out.println(name + "," + value);
} else {
out.println(name.substring(1) + "==" + value);
}
} catch (Exception e) {
// System.err.println("Data error:"+e.toString()+"
// for:"+name);
}
}
Thread.yield();
}
}
use of net.sourceforge.processdash.data.DateData in project processdash by dtuma.
the class DataMessageHandler method maybeSaveValue.
private void maybeSaveValue(MessageEvent message, String dataName, SimpleData value, Date editTimestamp) {
// discard malformed data values
if (value instanceof MalformedData) {
logger.warning("When handling message with ID '" + message.getMessageId() + //
"', found malformed definition for '" + dataName + "'. Discarding value.");
return;
}
// check to see if this data element has been edited locally *after*
// the time in the message. If so, prefer the local edit and discard
// this data change.
DataRepository data = ctx.getData();
String localTimestampName = dataName + "/Edit_Timestamp";
if (editTimestamp != null) {
SimpleData localTimestamp = data.getSimpleValue(localTimestampName);
if (localTimestamp instanceof DateData) {
if (((DateData) localTimestamp).getValue().after(editTimestamp))
return;
}
}
// store the value in the data repository
data.userPutValue(dataName, value);
if (editTimestamp != null)
data.putValue(localTimestampName, new DateData(editTimestamp, true));
}
use of net.sourceforge.processdash.data.DateData in project processdash by dtuma.
the class Maxdate method maxDateOf.
private Object maxDateOf(List arguments, ExpressionContext context) {
DateData result = null;
Object val;
Iterator i = collapseLists(arguments, 0).iterator();
while (i.hasNext()) {
val = i.next();
if (val == null)
return null;
if (val instanceof DateData && (result == null || result.lessThan((DateData) val)))
result = (DateData) val;
}
return result;
}
use of net.sourceforge.processdash.data.DateData in project processdash by dtuma.
the class Maxdate method maxDateFor.
private Object maxDateFor(List arguments, ExpressionContext context) {
DateData result = null;
Object val;
String name = asString(getArg(arguments, 0));
if (name == null)
return null;
Iterator i = collapseLists(arguments, 1).iterator();
String path, dataName;
while (i.hasNext()) {
path = asStringVal(i.next());
if (path == null)
continue;
dataName = DataRepository.createDataName(path, name);
val = context.get(dataName);
if (val == null)
return null;
if (val instanceof DateData && (result == null || result.lessThan((DateData) val)))
result = (DateData) val;
}
return result;
}
use of net.sourceforge.processdash.data.DateData in project processdash by dtuma.
the class XYChart method createChart.
/** Create a scatter plot. */
@Override
public JFreeChart createChart() {
JFreeChart chart;
String xLabel = null, yLabel = null;
if (!chromeless) {
xLabel = Translator.translate(data.getColName(1));
yLabel = getSetting("yLabel");
if (yLabel == null && data.numCols() == 2)
yLabel = data.getColName(2);
if (yLabel == null)
yLabel = getSetting("units");
if (yLabel == null)
yLabel = "Value";
yLabel = Translator.translate(yLabel);
}
Object autoZero = parameters.get("autoZero");
boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData;
if (firstColumnContainsDate || parameters.get("xDate") != null) {
chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false);
if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly())
chart.getXYPlot().getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance()));
} else {
XYDataset src = data.xyDataSource();
chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false);
if (src instanceof XYToolTipGenerator) {
chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src);
}
String trendLine = getParameter("trend");
if ("none".equalsIgnoreCase(trendLine))
;
else if ("average".equalsIgnoreCase(trendLine))
addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y")));
else
addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y")));
}
if (autoZero != null) {
if (!"x".equals(autoZero))
((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true);
if (!"y".equals(autoZero))
((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true);
}
if (data.numCols() == 2)
chart.removeLegend();
return chart;
}
Aggregations