use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ProjectUI method createPredicates.
// setUpDragAndDrop
protected void createPredicates() {
requiresRegenerationPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication ta = project.getTaskApplication(t, design);
if (ta != null) {
Demonstration demo = ta.getDemonstration();
return demo.isObsolete();
}
return false;
}
};
hasComputableScriptsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
if (taskApp != null) {
IPredictionAlgo activeAlg = taskApp.determineActiveAlgorithm(project);
APredictionResult result = taskApp.getResult(taskApp.getFirstModelGenerator(), activeAlg);
if ((result != null) && !result.canBeRecomputed()) {
return false;
}
return taskApp.hasComputableScript() && !taskApp.getDemonstration().isInvalid();
}
return project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY;
}
};
hasComputedResultPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return ((taskApp != null) && taskApp.hasComputedResult());
}
};
hasResultStepsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasResultSteps();
}
};
hasScriptsPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasScript();
}
};
hasTracesPredicate = new ProjectSelectionPredicate(project) {
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
return (taskApp != null) && taskApp.hasResultTraces();
}
};
hasMultipleScriptsPredicate = new ProjectSelectionPredicate(project) {
protected int numScripts = 0;
@Override
protected void resetState() {
numScripts = 0;
}
@Override
protected boolean isSatisfiedBy(Design design, AUndertaking t) {
TaskApplication taskApp = project.getTaskApplication(t, design);
if (taskApp != null) {
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Script script = taskApp.getScript(modelGen);
if (script != null) {
if (++numScripts > 1) {
return true;
}
}
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ScriptViewerUI method getSelectedScript.
protected Script getSelectedScript(DefaultModelGeneratorState stepState) {
SWTList swtList = view.getScriptEditorList();
if (stepState == null) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> tasks = group.getUndertakings();
int numTasks = tasks.size();
for (int i = numTasks - 1; i >= 0; i--) {
AUndertaking t = tasks.get(i);
TaskApplication ta = project.getTaskApplication(t, design);
if (ta != null) {
return ta.getOnlyScript();
}
}
}
TableItem item = swtList.getItemList().get(stepState);
return (Script) item.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ResultDisplayPolicy method computeGroup.
// getTaskApplicationCell
/**
* Recursively computes value of script results on a particular design
* for tasks within a group.
*
* @param group the group whose resVal to calculate
* @param d the design whose script results should be used here
* @return the recursive value of script results on design d
* for tasks in the given TaskGroup; -1.0 if the group is empty
*/
public static double computeGroup(Project project, TaskGroup group, Design d) {
List<AUndertaking> children = group.getUndertakings();
if (children.size() == 0) {
// trivial case
return TimePredictionResult.UNSET_TIME;
}
GroupNature nature = group.getNature();
boolean validReturnValue = false;
double returnValue = 0.0d;
double meanDivisor = 0.0d;
for (AUndertaking child : children) {
double stepValue = TimePredictionResult.UNSET_TIME;
if (child.isTaskGroup()) {
// recursive (TaskGroup) case
stepValue = computeGroup(project, (TaskGroup) child, d);
} else {
// terminal case
TaskApplication ta = project.getTaskApplication(child, d);
if (ta != null) {
APredictionResult result = ta.getResult(ta.getFirstModelGenerator(), ta.determineActiveAlgorithm(project));
stepValue = getComputationResult(result);
}
}
if ((nature == GroupNature.SUM) || (nature == GroupNature.MEAN)) {
if (stepValue != TimePredictionResult.UNSET_TIME) {
returnValue += stepValue;
meanDivisor += 1.0d;
validReturnValue = true;
}
} else if (nature == GroupNature.MIN) {
if ((stepValue != TimePredictionResult.UNSET_TIME) && ((stepValue < returnValue) || (!validReturnValue))) {
returnValue = stepValue;
validReturnValue = true;
}
} else if (nature == GroupNature.MAX) {
if (stepValue > returnValue) {
returnValue = stepValue;
validReturnValue = true;
}
}
}
if (validReturnValue) {
if ((nature == GroupNature.MEAN) && (meanDivisor != 0.0d)) {
returnValue /= meanDivisor;
}
return returnValue;
}
return TimePredictionResult.UNSET_TIME;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class ResultDisplayPolicy method getTaskRowStrings.
public static String[] getTaskRowStrings(Project project, AUndertaking undertaking, String withSecs, int[] designOrder) {
List<Design> projectDesigns = project.getDesigns();
// Add 1 since the initial column is not a design.
String[] entries = new String[projectDesigns.size() + 1];
entries[0] = SWTStringUtil.insertEllipsis(undertaking.getName(), 300, StringUtil.EQUAL, SWTStringUtil.DEFAULT_FONT);
Iterator<Design> designIter = projectDesigns.iterator();
// advance index to "First result" position
int index = 1;
if (undertaking.isTaskGroup()) {
// TODO: Store group results instead of recomputing?
TaskGroup group = (TaskGroup) undertaking;
while (designIter.hasNext()) {
Design d = designIter.next();
double result = computeGroup(project, group, d);
updateDigits();
String formattedResult = (result == TimePredictionResult.UNSET_TIME) ? "?" : (cellNumberFormat.format(result) + withSecs);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
entries[entryIndex] = group.getNature().toString() + ": " + formattedResult;
}
} else {
while (designIter.hasNext()) {
Design d = designIter.next();
TaskApplication ta = project.getTaskApplication(undertaking, d);
int entryIndex = (designOrder != null) ? designOrder[index++] : index++;
CognitiveModelGenerator gen = null;
if (ta != null) {
gen = ta.getFirstModelGenerator();
}
entries[entryIndex] = getTaskApplicationCell(project, ta, gen, true, withSecs);
}
}
return entries;
}
use of edu.cmu.cs.hcii.cogtool.model.TaskApplication in project cogtool by cogtool.
the class DemoScriptCmd method addUndoableEditToScripts.
/**
* Adds the edit for each of the scripts in the demonstration except
* the given script.
*/
protected static void addUndoableEditToScripts(IUndoableEditSequence seq, Demonstration demo, Script exceptScript, Project project) {
TaskApplication taskApp = demo.getTaskApplication();
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Script script = taskApp.getScript(modelGen);
if (script != exceptScript) {
CommandUtil.addAsUndoableEdit(seq, script, project);
}
}
}
Aggregations