use of net.sourceforge.processdash.data.DoubleData in project processdash by dtuma.
the class Dblookupwbselement method call.
/**
* Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
// get the object for executing database queries
QueryRunner queryRunner = getDbObject(context, QueryRunner.class);
if (queryRunner == null)
return null;
// retrieve the WBS element name we are being asked to look up.
String wbsElementName = asString(getArg(arguments, 0));
if (wbsElementName == null)
return null;
if (wbsElementName.startsWith("/"))
wbsElementName = wbsElementName.substring(1);
if (wbsElementName.length() == 0)
return null;
wbsElementName = StringUtils.limitLength(wbsElementName, 255);
// retrieve the plan item ID of the item we are being asked to look up.
String planItemId = asString(getArg(arguments, 1));
// look up this WBS element in the database.
try {
int key;
List result = queryRunner.queryHql(NAME_QUERY, wbsElementName);
if ((result == null || result.isEmpty()) && StringUtils.hasValue(planItemId))
result = queryRunner.queryHql(ID_QUERY, planItemId);
if (result != null && !result.isEmpty()) {
// extract the value from the result set
key = (Integer) result.get(0);
} else {
// not found? Use an impossible WBS key to result in no matches
key = -999;
}
return new DoubleData(key, false);
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected error while calculating", e);
return null;
}
}
use of net.sourceforge.processdash.data.DoubleData in project processdash by dtuma.
the class Dbuserfiltergroup method call.
/**
* Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*
* Arguments: Project key list, dataset ID list
*/
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 dataset IDs we are searching for, and convert them
// to plain String objects
Set<String> datasetIds = new HashSet();
for (Object oneDatasetIdVal : collapseLists(arguments, 1)) {
String oneDatasetId = asStringVal(oneDatasetIdVal);
if (oneDatasetId != null)
datasetIds.add(oneDatasetId);
}
// either way, return null to indicate "no filtering"
if (datasetIds.isEmpty())
return null;
// error code signifying an empty group
if (datasetIds.contains(UserGroupManagerDash.EMPTY_GROUP_TOKEN))
return new DoubleData(-1, false);
// retrieve the study group manager
StudyGroupManager mgr = getDbObject(context, StudyGroupManager.class);
if (mgr == null)
return null;
try {
int result = mgr.getDataBlockGroup(projectKeys, datasetIds, listenerName);
return new DoubleData(result, false);
} catch (Throwable t) {
// disable user group filtering.
return null;
}
}
use of net.sourceforge.processdash.data.DoubleData in project processdash by dtuma.
the class Constrain method call.
/** Perform a procedure call.
*
* This method <b>must</b> be thread-safe.
*/
public Object call(List arguments, ExpressionContext context) {
SimpleData lowerBound = getArg(arguments, 0);
SimpleData upperBound = getArg(arguments, 1);
SimpleData data = getArg(arguments, 2);
if (data == null) {
return null;
} else if (data instanceof DoubleData) {
double d = ((DoubleData) data).getDouble();
if (Double.isNaN(d) || Double.isInfinite(d))
return data;
}
if (data.lessThan(lowerBound)) {
return lowerBound;
} else if (data.greaterThan(upperBound)) {
return upperBound;
} else {
return data;
}
}
use of net.sourceforge.processdash.data.DoubleData in project processdash by dtuma.
the class RadarChart method maybeScaleDataAxes.
private void maybeScaleDataAxes() {
for (int i = 0; i < data.numCols(); i++) {
int n = i + 1;
String target = getParameter("t" + n);
if (!StringUtils.hasValue(target))
continue;
double targetVal = 0;
try {
targetVal = FormatUtil.parseNumber(target);
} catch (Exception e) {
SaveableData val = getDataRepository().getInheritableValue(getPrefix(), target);
if (val != null) {
SimpleData sVal = val.getSimpleValue();
if (sVal instanceof NumberData)
targetVal = ((NumberData) sVal).getDouble();
}
}
if (targetVal == 0)
continue;
boolean reverse = parameters.containsKey("r" + n);
SimpleData d = data.getData(1, n);
if (d instanceof NumberData) {
NumberData num = (NumberData) d;
double val = num.getDouble();
if (Double.isInfinite(val) || Double.isNaN(val))
val = 1.0;
else if (reverse)
val = 2.0 / (1.0 + (val / targetVal));
else
val = val / targetVal;
data.setData(1, n, new DoubleData(val));
}
}
}
use of net.sourceforge.processdash.data.DoubleData in project processdash by dtuma.
the class MethodsPage method parseFormData.
public boolean parseFormData() {
buildMethods();
String what = purpose.getKey();
String method = (String) params.get(what);
if (method == null)
return false;
String qual = what + method;
SimpleData estimate, range, lpi, upi;
// Save the chosen method
putValue(getDataName(SEL_METHOD), StringData.create(method));
// Save the estimated value
estimate = getNum(qual, ProbeMethod.FLD_ESTIMATE);
if (estimate == N_A)
return false;
if (!ImmutableDoubleData.READ_ONLY_ZERO.lessThan(estimate))
return false;
putValue(targetDataElement, estimate);
estimateWasSaved(estimate);
// Save beta0 and beta1
putValue(getDataName("Beta0"), getNum(qual, ProbeMethod.FLD_BETA0));
putValue(getDataName("Beta1"), getNum(qual, ProbeMethod.FLD_BETA1));
// Save the range
putValue(getDataName("Range"), range = getNum(qual, ProbeMethod.FLD_RANGE));
// Save the interval percent
putValue(getDataName("Interval Percent"), getNum(qual, ProbeMethod.FLD_PERCENT, 1));
// Save the correlation
putValue(getDataName("R Squared"), getNum(qual, ProbeMethod.FLD_CORRELATION, 1));
// Save the LPI and UPI
if (range instanceof DoubleData) {
double est = ((DoubleData) estimate).getDouble();
double rng = ((DoubleData) range).getDouble();
upi = new DoubleData(est + rng);
lpi = new DoubleData(Math.max(0, est - rng));
} else
upi = lpi = N_A;
putValue(getDataName("LPI"), lpi);
putValue(getDataName("UPI"), upi);
// Save the input values that were used to capture data
histData.saveLastRunValues();
return true;
}
Aggregations