Search in sources :

Example 1 with DateData

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();
    }
}
Also used : DateData(net.sourceforge.processdash.data.DateData) Iterator(java.util.Iterator) EscapeString(net.sourceforge.processdash.util.EscapeString) SaveableData(net.sourceforge.processdash.data.SaveableData) StringData(net.sourceforge.processdash.data.StringData) MalformedValueException(net.sourceforge.processdash.data.MalformedValueException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) LexerException(net.sourceforge.processdash.data.compiler.lexer.LexerException) IOException(java.io.IOException) CompilationException(net.sourceforge.processdash.data.compiler.CompilationException) ParserException(net.sourceforge.processdash.data.compiler.parser.ParserException) ExecutionException(net.sourceforge.processdash.data.compiler.ExecutionException)

Example 2 with DateData

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));
}
Also used : DateData(net.sourceforge.processdash.data.DateData) SimpleData(net.sourceforge.processdash.data.SimpleData) MalformedData(net.sourceforge.processdash.data.MalformedData)

Example 3 with DateData

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;
}
Also used : DateData(net.sourceforge.processdash.data.DateData) Iterator(java.util.Iterator)

Example 4 with DateData

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;
}
Also used : DateData(net.sourceforge.processdash.data.DateData) Iterator(java.util.Iterator)

Example 5 with DateData

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;
}
Also used : StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) DateData(net.sourceforge.processdash.data.DateData) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

DateData (net.sourceforge.processdash.data.DateData)31 SimpleData (net.sourceforge.processdash.data.SimpleData)10 Date (java.util.Date)6 Iterator (java.util.Iterator)3 SaveableData (net.sourceforge.processdash.data.SaveableData)3 DataContext (net.sourceforge.processdash.data.DataContext)2 DoubleData (net.sourceforge.processdash.data.DoubleData)2 ListData (net.sourceforge.processdash.data.ListData)2 EscapeString (net.sourceforge.processdash.util.EscapeString)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 MalformedData (net.sourceforge.processdash.data.MalformedData)1 MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)1