Search in sources :

Example 6 with AUndertaking

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;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 7 with AUndertaking

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;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 8 with AUndertaking

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;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ArrayList(java.util.ArrayList) SNIFACTGroupParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTGroupParameters) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SNIFACTParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTParameters) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 9 with AUndertaking

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();
                    }
                }
            }
        }
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ITraceWindow(edu.cmu.cs.hcii.cogtool.ui.Interaction.ITraceWindow) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 10 with AUndertaking

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));
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Aggregations

AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)89 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)38 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)35 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)28 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)24 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)18 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)17 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 Script (edu.cmu.cs.hcii.cogtool.model.Script)13 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)13 IOException (java.io.IOException)12 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)11 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)9 TreeItem (org.eclipse.swt.widgets.TreeItem)9 ArrayList (java.util.ArrayList)7