use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method getTraces.
// getTraces
/**
* Utility to accumulate all of the (ACT-R) trace lines for the given
* selected task and design intersections and the given algorithm.
* <p>
* If there are no selected tasks, accumulate all trace lines for the
* selected design and all tasks. If there is no selected design,
* accumulate all trace lines for selected tasks and all designs.
* An empty list is returned if nothing is selected.
*
* @param sel the selected tasks and design for which to find results
* associated with the given algorithm
* @param modelGen the algorithm for generating cognitive models (i.e.,
* scripts) from demonstrations
* @param computeAlg the algorithm for generating results from
* cognitive models
* @author mlh/alex
*/
protected List<String> getTraces(ProjectSelectionState sel, CognitiveModelGenerator modelGen, IPredictionAlgo computeAlg) {
Design design = sel.getSelectedDesign();
AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
List<String> traces = new ArrayList<String>();
// either for selected tasks or for all tasks (if none selected).
if (design != null) {
traces.add("For Design " + design.getName());
// Get for selected tasks
if ((tasks != null) && (tasks.length > 0)) {
for (AUndertaking task : tasks) {
traces.addAll(getTraces(task, design, modelGen, computeAlg));
}
} else {
// No tasks selected; get traces from all undertakings
Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
while (allTasks.hasNext()) {
traces.addAll(getTraces(allTasks.next(), design, modelGen, computeAlg));
}
}
} else if ((tasks != null) && (tasks.length > 0)) {
// Design was null, get for selected tasks and all designs.
for (AUndertaking task : tasks) {
Iterator<Design> allDesigns = project.getDesigns().iterator();
while (allDesigns.hasNext()) {
Design d = allDesigns.next();
traces.add("For Design " + d.getName());
traces.addAll(getTraces(task, d, modelGen, computeAlg));
}
}
}
return traces;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method createCopyTaskAction.
// createRenameDesignAction
// Action for CopyTask
protected IListenerAction createCopyTaskAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
// Can only copy to clipboard if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
try {
ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
for (AUndertaking task : tasks) {
s.saveObject(task);
}
s.finish();
if (tasks.length == 1) {
interaction.setStatusMessage(TASK_COPIED);
} else {
interaction.setStatusMessage(TASKS_COPIED);
}
return true;
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Copying Tasks", error);
}
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method computeSnifAct.
// assignActions
protected boolean computeSnifAct(Design design, AUndertaking task, IUndoableEditSequence editSequence, SNIFACTGroupParameters defaults) {
// TODO: L10N required for error titles and messages.
if (design == null) {
interaction.reportProblem("SNIF-ACT", "No design is selected.");
return false;
}
if (design.getFrames().size() == 0) {
interaction.reportProblem("SNIF-ACT", "Selected design is empty.");
return false;
}
if (task.isTaskGroup()) {
// We can only recompute with this algorithm if the
// group was generated by a previous SNIF-ACT
// computation (and thus has the execution
// context attribute)
Object contextAttr = task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
if (NullSafe.equals(contextAttr, WidgetAttributes.NO_CONTEXT)) {
interaction.reportProblem("SNIF-ACT", "Can't recompute with this algorithm from this cell.");
return false;
}
}
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (dict == null) {
interaction.reportProblem("Export Dictionary", "No dictionary exists for the selected design");
return false;
}
List<Frame> sortedFrames = NamedObjectUtil.getSortedList(design.getFrames());
SNIFACTParameters parms;
int addGroupMode;
boolean hasScript = false;
final SNIFACTExecContext prevContext;
if (task.isTaskGroup()) {
// Since we got this far, we know the group already has
// parameters associated with it, so use those values as
// defaults in the dialog box
prevContext = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
parms = prevContext.getParameters();
addGroupMode = SNIFACTDialog.ENABLED;
} else {
// Otherwise, create a new set of default values for this
// execution
String defaultName = sortedFrames.get(0).getName();
List<String> targets = new ArrayList<String>();
targets.add(defaultName);
parms = new SNIFACTParameters(task.getName(), NUM_SNIF_ACT_TRIALS, SNIF_ACT_K_VALUE, defaultName, targets, ITermSimilarity.ALL);
addGroupMode = SNIFACTDialog.NONE;
prevContext = null;
TaskApplication ta = project.getTaskApplication(task, design);
hasScript = (ta != null) && ta.hasScript();
}
SNIFACTGroupParameters groupParms = null;
if (defaults == null) {
groupParms = interaction.requestSNIFACTParameters(hasScript, sortedFrames, parms, dict.getAlgorithmsInUse(), addGroupMode);
} else {
groupParms = new SNIFACTGroupParameters(defaults.taskName, defaults.numRuns, defaults.kValue, defaults.startFrame, defaults.targetFrames, defaults.algorithm, ((addGroupMode != SNIFACTDialog.NONE) && defaults.addToGroup));
}
if (groupParms == null) {
return false;
}
SNIFACTPredictionAlgo.ONLY.setParameters(groupParms);
TaskParent parent = task.getTaskGroup();
if (parent == null) {
parent = project;
}
final TaskGroup group;
if (groupParms.addToGroup) {
// user wants to add new trial tasks to the same group
group = (TaskGroup) task;
} else {
Collection<AUndertaking> siblings = parent.getUndertakings();
group = new TaskGroup(SNIFACTCmd.getGroupName(groupParms, siblings), GroupNature.MEAN);
}
final SNIFACTExecContext context = SNIFACTCmd.computeInBackground(project, design, interaction, group, groupParms);
if (context == null) {
return true;
}
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
CompoundUndoableEdit snifActEditSeq = new CompoundUndoableEdit(SNIFACT_COMPUTATION, ProjectLID.RecomputeScript);
if (!task.isTaskGroup()) {
snifActEditSeq.addEdit(HCIPACmd.replaceTask(project, parent, task, group, SNIFACT_COMPUTATION));
} else {
if (groupParms.addToGroup) {
snifActEditSeq.addEdit(SNIFACTCmd.addTasksToGroup(project, group, context, SNIFACT_COMPUTATION));
} else {
snifActEditSeq.addEdit(SNIFACTCmd.addGroup(project, parent, group, SNIFACT_COMPUTATION));
}
}
snifActEditSeq.addEdit(new AUndoableEdit(ProjectLID.RecomputeScript) {
@Override
public String getPresentationName() {
return SNIFACT_COMPUTATION;
}
@Override
public void redo() {
super.redo();
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
}
@Override
public void undo() {
super.undo();
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, prevContext);
}
});
snifActEditSeq.end();
if (editSequence != null) {
editSequence.addEdit(snifActEditSeq);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method displayTraces.
protected void displayTraces(AUndertaking task, Design design) {
if (task.isTaskGroup()) {
Iterator<AUndertaking> allSubtasks = ((TaskGroup) task).getUndertakings().iterator();
while (allSubtasks.hasNext()) {
displayTraces(allSubtasks.next(), design);
}
} else {
TaskApplication taskApp = project.getTaskApplication(task, design);
if (taskApp != null) {
StringBuilder labelText = new StringBuilder();
Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
while (modelGens.hasNext()) {
CognitiveModelGenerator modelGen = modelGens.next();
Iterator<IPredictionAlgo> computeAlgs = taskApp.getPredictionAlgs(modelGen);
while (computeAlgs.hasNext()) {
IPredictionAlgo computeAlg = computeAlgs.next();
APredictionResult result = taskApp.getResult(modelGen, computeAlg);
int resultState = result.getResultState();
if ((result != null) && ((resultState == APredictionResult.IS_COMPUTED) || (resultState == APredictionResult.COMPUTE_FAILED))) {
labelText.delete(0, labelText.length());
labelText.append(tracesWindowLabel);
labelText.append(": ");
labelText.append(project.getName());
labelText.append(" > ");
labelText.append(design.getName());
labelText.append(" > ");
labelText.append(task.getName());
String labelStr = labelText.toString();
ITraceWindow traceWin = interaction.createTraceWindow(labelStr + (OSUtils.MACOSX ? "" : UI.WINDOW_TITLE), null, labelStr);
traceWin.appendOutputLines(result.getTraceLines());
traceWin.scrollToTop();
traceWin.appendErrorLines(result.getErrorLines());
traceWin.scrollToTop();
}
}
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AUndertaking in project cogtool by cogtool.
the class ProjectController method duplicateTaskApplications.
protected void duplicateTaskApplications(Design designCopy, Map<ITaskDesign, TaskApplication> associatedTAs) {
// The undo edit for adding the Design will remove and restore
// the task-applications; all we need to do here is duplicate
// the task applications.
Iterator<TaskApplication> taskApps = associatedTAs.values().iterator();
while (taskApps.hasNext()) {
TaskApplication ta = taskApps.next();
AUndertaking task = ta.getTask();
project.setTaskApplication(ta.duplicate(task, designCopy));
}
}
Aggregations