Search in sources :

Example 1 with ListFunction

use of net.sourceforge.processdash.data.ListFunction in project processdash by dtuma.

the class RollupAutoData method buildRollupData.

private void buildRollupData(DataRepository data) {
    //System.out.println("buildRollupData for " + definesRollupID);
    Map baseDefinitions = null;
    try {
        baseDefinitions = data.loadIncludedFileDefinitions(basedOnDataFile);
        // can exit immediately.
        if (definitions != null)
            return;
    } catch (Exception e) {
        logger.log(Level.WARNING, "Caught Exception", e);
        return;
    }
    Map rollupDefinitions = new HashMap();
    StringBuffer definitionBuffer = new StringBuffer();
    definitionBuffer.append("#define ROLLUP_ID ").append(esc(definesRollupID));
    // Define macros for rolling up numbers and lists
    definitionBuffer.append("\n#define ROLLUP_NUMBER(Data) ");
    rollupDouble(definitionBuffer, "Data");
    definitionBuffer.append("\n#define ROLLUP_LIST(Data) ");
    rollupList(definitionBuffer, "Data");
    // Include the standard rollup data definitions
    definitionBuffer.append("\n").append(ROLLUP_DATA).append("\n");
    Map toDateAliasDefinitions = new HashMap();
    String toDatePrefix = "/To Date/" + definesRollupID + "/All";
    toDateAliasDefinitions.put(definesRollupID + " To Date Subset Prefix", StringData.create(toDatePrefix));
    StringBuffer toDateAliasBuffer = new StringBuffer();
    Iterator i = baseDefinitions.entrySet().iterator();
    Map.Entry definition;
    String name;
    Object value;
    while (i.hasNext()) {
        definition = (Map.Entry) i.next();
        name = (String) definition.getKey();
        value = definition.getValue();
        if (skipElement(name, value))
            // filter out elements which should not be rolled up.
            continue;
        else if (value instanceof DoubleData) {
            // roll up the values of any literal double data elements.
            rollupDouble(definitionBuffer, name);
            addAlias(toDateAliasBuffer, name, definesRollupID);
        } else if (value instanceof ListFunction)
            // roll up the values of any search()-generated lists.
            rollupList(definitionBuffer, name);
        else if (value != null) {
            if (value instanceof CompiledScript)
                addAlias(toDateAliasBuffer, name, definesRollupID);
            // DO NOT roll up dates, strings, lists, tags,
            // compiled functions, or old-style definitions - just
            // copy them into the rollup set verbatim.
            rollupDefinitions.put(name, value);
        }
    }
    // Calculate the rollup aliases
    parseDefinitions(data, toDateAliasBuffer.toString(), toDateAliasDefinitions);
    aliasDefs = toDateAliasDefinitions;
    // If the user specified a datafile for this rollup, include it.
    if (XMLUtils.hasValue(rollupDataFile))
        try {
            URLConnection conn = TemplateLoader.resolveURLConnection(rollupDataFile);
            String contents = new String(FileUtils.slurpContents(conn.getInputStream(), true));
            definitionBuffer.append("\n").append(contents).append("\n");
        } catch (IOException ioe) {
            logger.log(Level.WARNING, "IOException", ioe);
        }
    // Calculate the rollup definitions and return them.
    parseDefinitions(data, definitionBuffer.toString(), rollupDefinitions);
    definitions = rollupDefinitions;
    debugPrint(rollupDefinitions);
    try {
        // Mount this rollup data set in the repository.
        data.mountPhantomData(toDatePrefix, rollupDefinitions);
    } catch (Exception e) {
        logger.log(Level.WARNING, "Caught Exception", e);
    }
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) ListFunction(net.sourceforge.processdash.data.ListFunction) HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) DoubleData(net.sourceforge.processdash.data.DoubleData) URLConnection(java.net.URLConnection) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 DoubleData (net.sourceforge.processdash.data.DoubleData)1 ListFunction (net.sourceforge.processdash.data.ListFunction)1 CompiledScript (net.sourceforge.processdash.data.compiler.CompiledScript)1