Search in sources :

Example 1 with APredictionResult

use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.

the class PERTChartView method addDesignResults.

protected void addDesignResults(APredictionResult knownResult, Project project, Design design, Iterator<AUndertaking> tasks, List<NamedPredictionResult> availableResults) {
    while (tasks.hasNext()) {
        AUndertaking task = tasks.next();
        if ((design != null) && (task != null)) {
            if (task.isTaskGroup()) {
                addDesignResults(knownResult, project, design, ((TaskGroup) task).getUndertakings().iterator(), availableResults);
            } else {
                TaskApplication otherTa = project.getTaskApplication(task, design);
                if (otherTa != null) {
                    Iterator<CognitiveModelGenerator> modGenIt = otherTa.getModelGenerators();
                    while (modGenIt.hasNext()) {
                        CognitiveModelGenerator otherModGen = modGenIt.next();
                        if (otherModGen != null) {
                            Iterator<IPredictionAlgo> predAlgIt = otherTa.getPredictionAlgs(otherModGen);
                            while (predAlgIt.hasNext()) {
                                APredictionResult otherResult = otherTa.getResult(otherModGen, predAlgIt.next());
                                if ((otherResult != knownResult) && (otherResult != null)) {
                                    String name = otherTa.getDesign().getName() + " : " + otherTa.getTask().getName();
                                    NamedPredictionResult npr = new NamedPredictionResult(otherResult, name);
                                    addAvailableResult(npr, availableResults);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) 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) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 2 with APredictionResult

use of edu.cmu.cs.hcii.cogtool.model.APredictionResult 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 3 with APredictionResult

use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.

the class ProjectController method getTraces.

/**
     * Utility to accumulate all of the (ACT-R) trace lines for the given
     * task, design, and algorithm.
     * <p>
     * If the given task is an <code>TaskGroup</code>, the trace lines
     * are accumulated recursively by appending together those associated
     * with descendant tasks.
     * Traces are associated with results, which are determined for the
     * given task and design by which algorithm generated the cognitive model
     * and which prediction algorithm computed the result from that model.
     *
     * @param task the task for which to find results associated with
     *             the given algorithm
     * @param design the 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(AUndertaking task, Design design, CognitiveModelGenerator modelGen, IPredictionAlgo computeAlg) {
    List<String> traces = new ArrayList<String>();
    // and append to the current state.
    if (task.isTaskGroup()) {
        Iterator<AUndertaking> allTasks = ((TaskGroup) task).getUndertakings().iterator();
        traces.add("For TaskGroup " + task.getName());
        while (allTasks.hasNext()) {
            traces.addAll(getTraces(allTasks.next(), design, modelGen, computeAlg));
        }
        return traces;
    }
    // Base case; find the result for the given task/design/algorithm
    TaskApplication taskApp = project.getTaskApplication(task, design);
    // Result must exist and be current
    if (taskApp != null) {
        APredictionResult result = taskApp.getResult(modelGen, computeAlg);
        // Result may be null (although unlikely at this point).
        if ((result != null) && (result.getResultState() == APredictionResult.IS_COMPUTED)) {
            traces.add("Standard OUTPUT from Task " + task.getName());
            // Add the trace lines from the result
            traces.addAll(result.getTraceLines());
            traces.add("\nStandard ERROR from Task " + task.getName());
            traces.addAll(result.getErrorLines());
        }
    }
    return traces;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 4 with APredictionResult

use of edu.cmu.cs.hcii.cogtool.model.APredictionResult in project cogtool by cogtool.

the class ProjectController method createImportHumanCSVFileAction.

// Action for ImportHumanCSVFile
protected IListenerAction createImportHumanCSVFileAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            List<String> outputLines = new LinkedList<String>();
            List<String> errorLines = new LinkedList<String>();
            // Get csv file
            File dataFile = interaction.selectCSVFile();
            if (dataFile == null) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                return false;
            }
            // Read lines out of file
            FileReader reader = null;
            try {
                reader = new FileReader(dataFile);
                FileUtil.readLines(reader, outputLines);
            } catch (FileNotFoundException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                throw new RcvrIOTempException("Error in parsing csv", e);
            } catch (IOException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOREAD_MSG);
                throw new RcvrParsingException("Error in parsing csv", e);
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    reader = null;
                }
            }
            // parse ResultSteps out of trace lines
            TraceParser<ResultStep> parser = new HumanCSVParser();
            List<ResultStep> steps;
            try {
                steps = parser.parseTrace(outputLines);
            } catch (TraceParser.ParseException e) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_IMPL_MSG);
                throw new RcvrParsingException("Error in parsing implementation", e);
            }
            System.out.println(steps);
            if (steps.size() < 1) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_MSG);
                return false;
            }
            double taskTime = -1.0;
            Iterator<ResultStep> stepIt = steps.iterator();
            while (stepIt.hasNext()) {
                ResultStep step = stepIt.next();
                taskTime = Math.max(taskTime, step.startTime + step.duration);
            }
            // Scale time to seconds.
            taskTime /= 1000.0;
            // -------------- Done parsing
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final APredictionResult[] oldResults = new APredictionResult[tasks.length];
            final APredictionResult[] results = new APredictionResult[tasks.length];
            final IPredictionAlgo[] oldActiveAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                taskApps[i] = ensureTaskApplication(tasks[i], design, MODELGEN_ALG, demoMgr);
                // If for some reason there are no result steps,
                // create a TimePredictionResult that
                // reflects COMPUTATION_FAILED.
                // Otherwise, create a normal one.
                Script script = taskApps[i].getScript(MODELGEN_ALG);
                if (taskTime < 0.0) {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps);
                } else {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps, taskTime);
                }
                oldResults[i] = taskApps[i].getResult(MODELGEN_ALG, HumanDataAlgo.ONLY);
                taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                oldActiveAlgos[i] = taskApps[i].getActiveAlgorithm();
                taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
            }
            IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

                @Override
                public String getPresentationName() {
                    return IMPORT_HUMAN_CSV;
                }

                @Override
                public void redo() {
                    super.redo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                        taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, oldResults[i]);
                        taskApps[i].setActiveAlgorithm(oldActiveAlgos[i]);
                    }
                }
            };
            undoMgr.addEdit(edit);
            interaction.setStatusMessage(IMPORT_SUCCESS_MSG);
            return true;
        }
    };
}
Also used : TraceParser(edu.cmu.cs.hcii.cogtool.model.TraceParser) FileNotFoundException(java.io.FileNotFoundException) RcvrParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrParsingException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ResultStep(edu.cmu.cs.hcii.cogtool.model.ResultStep) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HumanCSVParser(edu.cmu.cs.hcii.cogtool.model.HumanCSVParser) TimePredictionResult(edu.cmu.cs.hcii.cogtool.model.TimePredictionResult) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FileReader(java.io.FileReader) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) LinkedList(java.util.LinkedList) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) RcvrIOTempException(edu.cmu.cs.hcii.cogtool.util.RcvrIOTempException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) File(java.io.File)

Example 5 with APredictionResult

use of edu.cmu.cs.hcii.cogtool.model.APredictionResult 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)

Aggregations

APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)11 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)8 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)7 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)6 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)5 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 ArrayList (java.util.ArrayList)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)2 TimePredictionResult (edu.cmu.cs.hcii.cogtool.model.TimePredictionResult)2 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)1 HumanCSVParser (edu.cmu.cs.hcii.cogtool.model.HumanCSVParser)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)1