Search in sources :

Example 26 with TaskApplication

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;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) ProjectSelectionPredicate(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState.ProjectSelectionPredicate) Point(org.eclipse.swt.graphics.Point)

Example 27 with TaskApplication

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);
}
Also used : SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TableItem(org.eclipse.swt.widgets.TableItem) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 28 with TaskApplication

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

Example 29 with TaskApplication

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

Example 30 with TaskApplication

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

Aggregations

TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)63 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)38 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)22 Design (edu.cmu.cs.hcii.cogtool.model.Design)20 Script (edu.cmu.cs.hcii.cogtool.model.Script)20 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)17 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)16 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)15 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)12 IOException (java.io.IOException)12 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)11 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)11 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)8 File (java.io.File)8 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)5