Search in sources :

Example 1 with DoubleData

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

the class DefectTypeStandard method getNameOfMostPreferredStandard.

private static String getNameOfMostPreferredStandard() {
    if (mostPreferredName != null)
        return mostPreferredName;
    String bestName = DEFAULT_NAME;
    double bestPriority = -1;
    for (String oneName : getDefinedStandards(data)) {
        SimpleData sd = data.getSimpleValue(PRIORITY_PREFIX + oneName);
        if (sd instanceof DoubleData) {
            double onePriority = ((DoubleData) sd).getDouble();
            if (onePriority > bestPriority) {
                bestName = oneName;
                bestPriority = onePriority;
            }
        }
    }
    mostPreferredName = bestName;
    return mostPreferredName;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 2 with DoubleData

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

the class TopDownBottomUpJanitor method getValueAt.

protected double getValueAt(DataContext data, PropertyKey node) {
    String fullDataName = getDataName(node);
    SimpleData sd = data.getSimpleValue(fullDataName);
    if (sd instanceof DoubleData) {
        DoubleData dd = (DoubleData) sd;
        return dd.getDouble();
    }
    return 0;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 3 with DoubleData

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

the class PercentSpentIndicator method showEditEstimateDialog.

private void showEditEstimateDialog() {
    if (currentTaskPath == null || estTimeDataName == null || estTimeEditable == false)
        return;
    ToolTipManager.sharedInstance().mouseExited(new MouseEvent(this, MouseEvent.MOUSE_EXITED, System.currentTimeMillis(), 0, 0, -1, 0, false));
    final JTextField estimate = new JTextField();
    if (estTime > 0 && !Double.isInfinite(estTime))
        estimate.setText(FormatUtil.formatTime(estTime));
    String prompt = resources.format("Edit_Dialog.Prompt_FMT", currentTaskPath);
    JPanel p = new JPanel(new GridLayout(2, 2, 10, 2));
    p.add(new JLabel(resources.getString("Actual_Time_Label"), JLabel.TRAILING));
    p.add(new JLabel(FormatUtil.formatTime(actTime)));
    p.add(new JLabel(resources.getString("Estimated_Time_Label"), JLabel.TRAILING));
    p.add(estimate);
    String title = resources.getString("Edit_Dialog.Title");
    Object message = new Object[] { prompt, p, new JOptionPaneTweaker.GrabFocus(estimate) };
    while (true) {
        if (JOptionPane.showConfirmDialog(this, message, title, JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)
            return;
        SimpleData newEstimate;
        String userInput = estimate.getText();
        if (userInput == null || userInput.trim().length() == 0) {
            newEstimate = null;
        } else {
            long l = FormatUtil.parseTime(userInput.trim());
            if (l < 0) {
                estimate.setBackground(new Color(255, 200, 200));
                estimate.setToolTipText(resources.getString("Edit_Dialog.Invalid_Time"));
                continue;
            }
            newEstimate = new DoubleData(l, true);
        }
        dashCtx.getData().userPutValue(estTimeDataName, newEstimate);
        EST_TIME_JANITOR.cleanup(dashCtx);
        return;
    }
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) JLabel(javax.swing.JLabel) SimpleData(net.sourceforge.processdash.data.SimpleData) JTextField(javax.swing.JTextField) DoubleData(net.sourceforge.processdash.data.DoubleData)

Example 4 with DoubleData

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

the class Dbgetresultvalue method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Expected arguments: (ResultSet, String... keys, String targetColumn)
     * 
     * Each "key" should be of the form "ColumnName=Value", identifying the name
     * of a column in the result set, and the value we are searching for.
     * 
     * The targetColumn should be the name of the column we want to select when
     * we find the matching row. The targetColumn can optionally be surrounded
     * by "sum()", which will instruct this method to find all of the matching
     * rows and add their values together.
     */
public Object call(List arguments, ExpressionContext context) {
    SimpleData arg0 = getArg(arguments, 0);
    if (!(arg0 instanceof ResultSetData))
        return null;
    ResultSetData rs = (ResultSetData) arg0;
    if (!rs.test())
        return null;
    List toFind = collapseLists(arguments, 1);
    if (toFind.isEmpty())
        return null;
    boolean sum = false;
    String targetColName = asStringVal(toFind.remove(toFind.size() - 1));
    if (targetColName.toLowerCase().startsWith("sum(") && targetColName.endsWith(")")) {
        sum = true;
        targetColName = targetColName.substring(4, targetColName.length() - 1);
    }
    int targetCol = rs.getColumnPos(targetColName);
    if (targetCol == -1)
        return null;
    int[] findColumns = new int[toFind.size()];
    String[] findValues = new String[toFind.size()];
    for (int i = 0; i < findColumns.length; i++) {
        String findItem = asString(toFind.get(i));
        int eqPos = findItem.indexOf('=');
        if (eqPos == -1)
            return null;
        String findColumnName = findItem.substring(0, eqPos);
        findColumns[i] = rs.getColumnPos(findColumnName);
        if (findColumns[i] == -1)
            return null;
        findValues[i] = findItem.substring(eqPos + 1);
    }
    double sumResult = 0;
    List<Object[]> rawResultData = rs.getData();
    for (Object[] oneRow : rawResultData) {
        if (matches(oneRow, findColumns, findValues)) {
            if (targetCol >= oneRow.length) {
                return null;
            } else if (sum) {
                Object oneVal = oneRow[targetCol];
                if (oneVal instanceof Number) {
                    sumResult += ((Number) oneVal).doubleValue();
                } else if (oneVal != null) {
                    return ImmutableDoubleData.BAD_VALUE;
                }
            } else {
                return toSimpleData(oneRow[targetCol]);
            }
        }
    }
    if (sum)
        return new DoubleData(sumResult, false);
    else
        return null;
}
Also used : SimpleData(net.sourceforge.processdash.data.SimpleData) ResultSetData(net.sourceforge.processdash.data.ResultSetData) DoubleData(net.sourceforge.processdash.data.DoubleData) ImmutableDoubleData(net.sourceforge.processdash.data.ImmutableDoubleData) List(java.util.List)

Example 5 with DoubleData

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

the class Dblabelfiltergroup method call.

/**
     * Perform a procedure call.
     * 
     * This method <b>must</b> be thread-safe.
     * 
     * Arguments: Project key list, filtered task IDs
     */
public Object call(List arguments, ExpressionContext context) {
    // get the name of the data element we are calculating for
    String listenerName = asStringVal(context.get(SubscribingExpressionContext.LISTENERVAR_NAME));
    // get the database keys of the projects in question
    ListData projectKeyList = asList(getArg(arguments, 0));
    if (projectKeyList == null)
        return null;
    List<Integer> projectKeys = new ArrayList();
    for (int i = 0; i < projectKeyList.size(); i++) {
        Object oneKeyVal = projectKeyList.get(i);
        if (oneKeyVal instanceof NumberData) {
            int oneKey = ((NumberData) oneKeyVal).getInteger();
            projectKeys.add(oneKey);
        }
    }
    if (projectKeys.isEmpty())
        return null;
    // get the list of task IDs we are searching for, and convert them to
    // plain String objects
    Set<String> taskIds = new HashSet();
    for (Object oneTaskIdVal : collapseLists(arguments, 1)) {
        String oneTaskId = asStringVal(oneTaskIdVal);
        if (oneTaskId != null)
            taskIds.add(oneTaskId);
    }
    // study group.
    if (taskIds.isEmpty())
        return new DoubleData(-1, false);
    // retrieve the study group manager
    StudyGroupManager mgr = getDbObject(context, StudyGroupManager.class);
    if (mgr == null)
        return null;
    // create a study group for this list of items, and return its key
    try {
        int result = mgr.getPlanItemGroup(projectKeys, taskIds, true, listenerName);
        return new DoubleData(result, false);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected error while calculating", e);
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) DoubleData(net.sourceforge.processdash.data.DoubleData) ListData(net.sourceforge.processdash.data.ListData) StudyGroupManager(net.sourceforge.processdash.tool.db.StudyGroupManager) NumberData(net.sourceforge.processdash.data.NumberData) HashSet(java.util.HashSet)

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