Search in sources :

Example 26 with DoubleData

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

the class SizeEstimatingTemplate method renameLegacyDataElements.

private static void renameLegacyDataElements(DataRepository data, String path) {
    for (int i = 0; i < ELEMENTS_TO_RENAME.length; i++) {
        String legacyName = ELEMENTS_TO_RENAME[i][0];
        String newName = ELEMENTS_TO_RENAME[i][1];
        String legacyDataName = DataRepository.createDataName(path, legacyName);
        String newDataName = DataRepository.createDataName(path, newName);
        SaveableData value = data.getValue(legacyDataName);
        if (value instanceof DoubleData) {
            data.putValue(newDataName, value);
            data.restoreDefaultValue(legacyDataName);
        }
    }
}
Also used : SaveableData(net.sourceforge.processdash.data.SaveableData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 27 with DoubleData

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

the class TimeLoggingSimulation method checkTimeData.

private boolean checkTimeData(String path, long expectedValue) {
    String dataName = path + "/Time";
    SimpleData value = harness.getDashboard().getData().getSimpleValue(dataName);
    if (value == null) {
        if (expectedValue == 0)
            return true;
    } else {
        double actualValue = ((DoubleData) value).getDouble();
        if (Math.abs(actualValue - expectedValue) < 0.001) {
            return true;
        }
    }
    printErr("Time mismatch for " + path + ": expected " + expectedValue + ", got " + (value == null ? null : value.format()));
    return false;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 28 with DoubleData

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

the class DataRepository method mountData.

void mountData(DataFile dataFile, String dataPrefix, Map values) throws InvalidDatafileFormat {
    try {
        startInconsistency();
        boolean registerDataNames = false;
        String datafilePath = "internal data";
        boolean fileEditable = true;
        // if this is a regular file,
        if (dataFile != null && dataFile.file != null) {
            datafilePath = dataFile.file.getPath();
            fileEditable = dataFile.canWrite && Settings.isReadWrite();
            // register the names of data elements in this file IF it is
            // not global data.
            registerDataNames = dataPrefix.length() > 0;
        }
        Map defaultData = dataFile.inheritedDefinitions;
        if (defaultData == null)
            defaultData = Collections.EMPTY_MAP;
        boolean successful = false;
        boolean datafileModified = false;
        int retryCount = 10;
        while (!successful && retryCount-- > 0) try {
            // values map.
            for (Iterator i = values.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry defn = (Map.Entry) i.next();
                String localName = (String) defn.getKey();
                Object valueObj = defn.getValue();
                String dataName = createDataName(dataPrefix, localName);
                SaveableData o = instantiateValue(dataName, dataPrefix, valueObj, !fileEditable);
                if (o instanceof MalformedData)
                    logger.warning("Data value for '" + dataName + "' in file '" + datafilePath + "' is malformed.");
                DataElement d = (DataElement) data.get(dataName);
                if (d == null) {
                    boolean isDefaultName = defaultData.containsKey(localName);
                    if (o != null || isDefaultName) {
                        try {
                            add(dataName, isDefaultName, o, IS_NOT_DEFAULT_VAL, dataFile, DO_NOTIFY);
                        } catch (DataElementAlreadyExistsException e) {
                            d = e.elem;
                        }
                    }
                }
                if (d != null) {
                    putValue(dataName, o, IS_NOT_DEFAULT_VAL, NOT_MODIFYING_DATAFILE);
                    d = (DataElement) data.get(dataName);
                    if (d != null) {
                        d.datafile = dataFile;
                        d.isDefaultName = defaultData.containsKey(localName);
                    }
                }
                if (registerDataNames && (o instanceof DoubleData || o instanceof CompiledFunction))
                    dataElementNameSet.add(localName);
            }
            // Next, handle the default values that this datafile inherits.
            String dataPrefixSlash = dataPrefix + "/";
            for (Iterator i = defaultData.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry defn = (Map.Entry) i.next();
                String localName = (String) defn.getKey();
                Object valueObj = defn.getValue();
                // name, do nothing.
                if (values.containsKey(localName))
                    continue;
                // Ignore renaming operations; they are not relevant.
                if (valueObj instanceof DataRenamingOperation)
                    continue;
                boolean shouldCreateEagerly = shouldCreateEagerly(valueObj);
                if ("@now".equals(valueObj))
                    shouldCreateEagerly = datafileModified = true;
                String dataName = dataPrefixSlash + localName;
                DataElement d = (DataElement) data.get(dataName);
                if (d == null) {
                    if (shouldCreateEagerly) {
                        // the item doesn't exist, but we should create it anyway.
                        SaveableData o = instantiateValue(dataName, dataPrefix, valueObj, !fileEditable);
                        if (o != null) {
                            try {
                                add(dataName, IS_DEFAULT_NAME, o, IS_DEFAULT_VAL, dataFile, DO_NOT_NOTIFY);
                            } catch (DataElementAlreadyExistsException e) {
                                d = e.elem;
                            }
                        }
                    }
                }
                if (d != null) {
                    // a matching data element exists.
                    d.datafile = dataFile;
                    d.isDefaultName = true;
                    dataName = d.name;
                    if (instantiatedDataMatches(valueObj, d.getValue())) {
                    // the data element already has the proper value. (This
                    // will be common, as clients registering data listeners
                    // will cause lazy data to spring to life even as this
                    // for loop is executing.) Nothing needs to be done.
                    } else if (!d.hasListeners()) {
                        // This element has the wrong value, but no one is
                        // listening to it.  Revert the element to a lazy
                        // default value.
                        janitor.cleanup(d);
                    } else {
                        // This element has the wrong value, and clients are
                        // listening to it.  Create and save the correct value.
                        SaveableData o = instantiateValue(dataName, dataPrefix, valueObj, !fileEditable);
                        putValue(dataName, o, IS_DEFAULT_VAL, NOT_MODIFYING_DATAFILE);
                    }
                }
                // send an event stating that the element is added. (Elsewhere in
                // DataRepository, added events are never sent for data elements
                // with default names (because it cannot tell whether the item is
                // springing forth for the first time, or a subsequent time).
                repositoryListenerList.dispatchAdded(dataName);
                if (registerDataNames && (valueObj instanceof DoubleData || valueObj instanceof CompiledScript))
                    dataElementNameSet.add(localName);
            }
            // make a call to getID.  We don't need the resulting value, but
            // having made the call will cause an ID to be mapped for this
            // prefix.  This is necessary to allow users to bring up HTML pages
            // from their browser's history or bookmark list.
            getID(dataPrefix);
            if (defaultData == globalDataDefinitions)
                globalDataIsMounted = true;
            if (datafileModified)
                datafileModified(dataFile);
            successful = true;
        } catch (Throwable e) {
            if (retryCount > 0) {
                // Try again to open this datafile. Most errors are transient,
                // caused by incredibly infrequent thread-related problems.
                logger.log(Level.WARNING, "when opening " + datafilePath + " caught error; retrying.", e);
            } else {
                // We've done our best, but after 10 tries, we still can't open
                // this datafile.  Give up and throw an exception.
                dataFile.invalidate();
                closeDatafile(dataPrefix);
                throw new InvalidDatafileFormat("Caught unexpected exception " + e);
            }
        }
    } finally {
        finishInconsistency();
    }
}
Also used : CompiledScript(net.sourceforge.processdash.data.compiler.CompiledScript) EscapeString(net.sourceforge.processdash.util.EscapeString) SaveableData(net.sourceforge.processdash.data.SaveableData) MalformedData(net.sourceforge.processdash.data.MalformedData) DoubleData(net.sourceforge.processdash.data.DoubleData) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 29 with DoubleData

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

the class DashboardTimeLog method timeLoggingAllowed.

static boolean timeLoggingAllowed(PropertyKey node, DashHierarchy props, DataContext data, List timingForbiddenPaths) {
    if (node == null || props == null || data == null || Settings.isReadOnly())
        return false;
    // forbidden path), don't allow time to be logged there.
    if (Filter.matchesFilter(timingForbiddenPaths, node.path()))
        return false;
    // the node explicitly defines a "Time_Logging_Allowed" marker.
    if (props.pget(node).getNumChildren() > 0) {
        String dataName = DataRepository.createDataName(node.path(), "Time_Logging_Allowed");
        SimpleData marker = data.getSimpleValue(dataName);
        return (marker != null && marker.test());
    }
    // check to see if the current node defines time as a calculation.
    // if it does, logging time here is not allowed.
    String dataName = DataRepository.createDataName(node.path(), "Time");
    Object timeData = data.getValue(dataName);
    if (timeData == null)
        return true;
    if (!(timeData instanceof DoubleData))
        return false;
    if (timeData instanceof NumberFunction)
        return false;
    return true;
}
Also used : NumberFunction(net.sourceforge.processdash.data.NumberFunction) SimpleData(net.sourceforge.processdash.data.SimpleData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 30 with DoubleData

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

the class Report5 method buildData.

/** create the data upon which this chart is based. */
protected void buildData() {
    initValues();
    DefectAnalyzer.refineParams(parameters, getDataContext());
    DefectAnalyzer.run(getPSPProperties(), getDataRepository(), getPrefix(), parameters, this);
    int numRows = defectData.size();
    data = new ResultSet(numRows, 1);
    data.setColName(0, resources.getString("Defect_Type"));
    data.setColName(1, resources.getString(KEYS[reportType] + "_Axis"));
    if (parameters.get("title") == null)
        parameters.put("title", resources.getString(KEYS[reportType] + "_Title"));
    Iterator i = defectData.keySet().iterator();
    String defectType;
    while (i.hasNext()) {
        defectType = (String) i.next();
        data.setRowName(numRows, defectType);
        data.setData(numRows, 1, new DoubleData(getRow(defectType)[0]));
        numRows--;
    }
    data.sortBy(1, true);
}
Also used : ResultSet(net.sourceforge.processdash.data.util.ResultSet) Iterator(java.util.Iterator) DoubleData(net.sourceforge.processdash.data.DoubleData)

Aggregations

DoubleData (net.sourceforge.processdash.data.DoubleData)39 SimpleData (net.sourceforge.processdash.data.SimpleData)15 Iterator (java.util.Iterator)7 ImmutableDoubleData (net.sourceforge.processdash.data.ImmutableDoubleData)7 ListData (net.sourceforge.processdash.data.ListData)5 NumberData (net.sourceforge.processdash.data.NumberData)5 ResultSet (net.sourceforge.processdash.data.util.ResultSet)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 SaveableData (net.sourceforge.processdash.data.SaveableData)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 NumberFunction (net.sourceforge.processdash.data.NumberFunction)3 StringData (net.sourceforge.processdash.data.StringData)3 CompiledScript (net.sourceforge.processdash.data.compiler.CompiledScript)3 IOException (java.io.IOException)2 DateData (net.sourceforge.processdash.data.DateData)2 MalformedValueException (net.sourceforge.processdash.data.MalformedValueException)2 StudyGroupManager (net.sourceforge.processdash.tool.db.StudyGroupManager)2