use of teamdash.wbs.WBSNode in project processdash by dtuma.
the class TeamTimeColumn method attemptToRepairTopDownBottomUpMismatch.
@Override
protected boolean attemptToRepairTopDownBottomUpMismatch(WBSNode node, double topDownValue, double bottomUpValue, WBSNode[] children, int numToInclude) {
// estimate and multiple children with no time assigned.
if (!(topDownValue > 0) || bottomUpValue > 0 || numToInclude < 2)
return false;
// Check to see if a workflow has been applied to this (parent) node.
if (node.getAttribute(WorkflowModel.WORKFLOW_SOURCE_IDS_ATTR) == null)
return false;
// Next, we get a list of the leaf tasks underneath this node, and add
// up the "Workflow Percentage" values for each one. (Basically, we
// want to do the "right thing," even if the user made a mistake and
// their numbers don't add to 100%.)
ArrayList<WBSNode> leaves = new ArrayList();
getLeavesForNode(node, false, leaves);
double totalPercent = 0;
for (WBSNode leaf : leaves) {
totalPercent += WorkflowPercentageColumn.getExplicitValueForNode(leaf);
// would indicate that this is not a percentage-driven workflow.
if (leaf.getNumericAttribute(RATE_ATTR) > 0)
return false;
}
// workflow insertion scenario.
if (!(totalPercent > 0))
return false;
// At this point, we appear to have a valid workflow insertion
// scenario. Next, check for minimum times on workflow steps, and make
// a note of the steps whose times need to be bumped up.
Map<WBSNode, Double> minTimes = new HashMap();
Map<WBSNode, Double> fixedTimePctOverrides = new HashMap();
double timeToSpread = topDownValue;
double pctToSpread = totalPercent;
while (true) {
boolean madeChangeToMinTimesDuringThisPass = false;
for (WBSNode leaf : leaves) {
if (minTimes.containsKey(leaf))
continue;
double leafMinTime = WorkflowMinTimeColumn.getMinTimeAt(leaf);
if (!(leafMinTime > 0))
continue;
double leafPercent = WorkflowPercentageColumn.getExplicitValueForNode(leaf);
if (leafPercent == 0)
// track which leaves have a fixed time (e.g. zero %)
fixedTimePctOverrides.put(leaf, null);
double leafTime = timeToSpread * leafPercent / pctToSpread;
if (leafTime < leafMinTime) {
minTimes.put(leaf, leafMinTime);
timeToSpread -= leafMinTime;
pctToSpread -= leafPercent;
madeChangeToMinTimesDuringThisPass = true;
}
}
if (madeChangeToMinTimesDuringThisPass == false)
break;
}
// (and unexpectedly) flip down to zero.
if (timeToSpread <= 0 || pctToSpread <= 0) {
timeToSpread = topDownValue;
pctToSpread = totalPercent;
for (Entry<WBSNode, Double> e : fixedTimePctOverrides.entrySet()) {
Double fixedTime = minTimes.remove(e.getKey());
if (fixedTime == null)
fixedTime = 1.0;
double fixedPct = fixedTime * totalPercent;
pctToSpread += fixedPct;
e.setValue(fixedPct);
}
minTimes.clear();
}
// Subdivide the time over the leaf tasks, based on what we've found.
for (WBSNode leaf : leaves) {
Double pctOverride = fixedTimePctOverrides.get(leaf);
double leafPercent = pctOverride != null ? pctOverride : WorkflowPercentageColumn.getExplicitValueForNode(leaf);
double leafTime = timeToSpread * leafPercent / pctToSpread;
Double leafMinTime = minTimes.get(leaf);
if (leafMinTime != null) {
WorkflowMinTimeColumn.storeReplacedTimeAt(leaf, leafTime);
leafTime = leafMinTime;
} else if (pctOverride != null) {
WorkflowMinTimeColumn.storeReplacedTimeAt(leaf, 0);
}
userChangingValue(leaf, leafTime);
leaf.setNumericAttribute(topDownAttrName, leafTime);
}
return true;
}
use of teamdash.wbs.WBSNode in project processdash by dtuma.
the class TopDownBottomUpColumn method multiplyValue.
/** Recurse over all the children of <code>node</code>, and multiply
* their top-down values by ratio.
*
* (Note: this does not modify the top-down estimate of the node
* itself).
*/
protected void multiplyValue(WBSNode node, double ratio) {
WBSNode[] children = wbsModel.getChildren(node);
for (int i = children.length; i-- > 0; ) {
WBSNode child = children[i];
if (shouldFilterFromCalculations(child))
continue;
double topDownValue = child.getNumericAttribute(topDownAttrName);
if (!Double.isNaN(topDownValue)) {
double filt = getFilteredAmount(child);
double visibleAmount = topDownValue - filt;
visibleAmount *= ratio;
userChangingValue(child, visibleAmount);
child.setNumericAttribute(topDownAttrName, visibleAmount + filt);
}
multiplyValue(child, ratio);
}
}
use of teamdash.wbs.WBSNode in project processdash by dtuma.
the class WorkflowResourcesColumn method changeInitials.
public static void changeInitials(WBSModel workflows, Map<String, String> changesToInitials) {
boolean workflowsWereChanged = false;
for (WBSNode node : workflows.getDescendants(workflows.getRoot())) {
String attr = (String) node.getAttribute(ATTR_NAME);
if (attr == null)
continue;
StringBuilder newAttrVal = new StringBuilder();
boolean nodeWasChanged = false;
Matcher m = TOKEN_PAT.matcher(attr);
while (m.find()) {
String token = m.group();
newAttrVal.append(AssignedToDocument.SEPARATOR_SPACE);
String replacement = changesToInitials.get(token);
if (replacement == null) {
newAttrVal.append(token);
} else {
newAttrVal.append(replacement);
nodeWasChanged = workflowsWereChanged = true;
}
}
if (nodeWasChanged)
node.setAttribute(ATTR_NAME, newAttrVal.substring(2));
}
if (workflowsWereChanged)
workflows.fireTableDataChanged();
}
use of teamdash.wbs.WBSNode in project processdash by dtuma.
the class WorkflowSizeUnitsColumn method isProbeTask.
private static boolean isProbeTask(JTable table, int row) {
DataTableModel dataModel = (DataTableModel) table.getModel();
WBSNode node = dataModel.getWBSModel().getNodeForRow(row);
return isProbeTask(node);
}
use of teamdash.wbs.WBSNode in project processdash by dtuma.
the class TaskDependencyColumn method recalculate.
/** Recalculate data for a node and its descendants. Return true if changes
* were made. */
private boolean recalculate(WBSModel wbs, WBSNode n) {
boolean result = false;
// retrieve the list of TaskDependencies for this node.
TaskDependencyList list = (TaskDependencyList) n.getAttribute(TASK_LIST_ATTR);
if (list != null) {
// if that list exists, update each of its tasks.
if (list.update(dependencySource))
result = true;
} else {
// the list doesn't exist. Try recalculating it.
list = readDependenciesForNode(n);
if (list != null) {
// the list wasn't there, but it needs to be. Save it.
n.setAttribute(TASK_LIST_ATTR, list);
result = true;
}
}
WBSNode[] children = wbs.getChildren(n);
for (int i = 0; i < children.length; i++) {
if (recalculate(wbs, children[i]))
result = true;
}
return result;
}
Aggregations