use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.
the class ProjectController method createVisualization.
public boolean createVisualization(Design design, AUndertaking task, int strategy) {
TaskApplication ta = getVisualizationTA(design, task);
if (ta != null) {
IPredictionAlgo activeAlgo = ta.determineActiveAlgorithm(project);
CognitiveModelGenerator gen = ta.getFirstModelGenerator();
if (ta.getResult(gen, activeAlgo) != null) {
PERTChartController c = PERTChartController.openController(ta, gen, activeAlgo, project, strategy, interaction);
return (c != null);
}
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.
the class ProjectController method createSetProjDefaultAlg.
protected IListenerAction createSetProjDefaultAlg(final ProjectLID lid, final String label, final IPredictionAlgo alg) {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
final IPredictionAlgo oldDefaultAlg = project.getDefaultAlgo();
project.setDefaultAlgo(alg);
undoMgr.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return label;
}
@Override
public void redo() {
super.redo();
project.setDefaultAlgo(alg);
}
@Override
public void undo() {
super.undo();
project.setDefaultAlgo(oldDefaultAlg);
}
});
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.
the class SEDemoController method createShowModelVisualizationAction.
protected IListenerAction createShowModelVisualizationAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
CognitiveModelGenerator modelGen = script.getModelGenerator();
IPredictionAlgo activeAlgo = taskApplication.determineActiveAlgorithm(project);
if (taskApplication.getResult(modelGen, activeAlgo) != null) {
PERTChartController c = PERTChartController.openController(taskApplication, modelGen, activeAlgo, project, -1, interaction);
return (c != null);
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo in project cogtool by cogtool.
the class ResultDisplayPolicy method getTaskApplicationCell.
public static String getTaskApplicationCell(Project project, TaskApplication taskApp, CognitiveModelGenerator gen, boolean forCell, String withSecs) {
if ((gen == null) || (taskApp == null) || ((!taskApp.hasComputedResult()) && (!taskApp.hasComputableScript())) || (taskApp.getScript(gen) == null)) {
// has a TaskApp, but no Script for the current algorithm
return "";
}
Demonstration demo = taskApp.getDemonstration();
IPredictionAlgo alg = taskApp.determineActiveAlgorithm(project);
APredictionResult r = taskApp.getResult(gen, alg);
int resultState = (r == null) ? APredictionResult.NOT_COMPUTED : r.getResultState();
// ?? means the demonstration is invalid or script needs regeneration
if (forCell) {
if (demo.isInvalid() || demo.isObsolete()) {
return "?? ";
}
if ((resultState == APredictionResult.NOT_COMPUTED) || (alg.requiresDemonstration() && !demo.isStartFrameChosen())) {
// No result yet computed for the associated script
return "-- ";
}
if (resultState == APredictionResult.COMPUTATION_IN_PROGRESS) {
// Result is being computed
return "(><) ";
}
if (resultState == APredictionResult.COMPUTE_FAILED) {
// Has a result for this algorithm, but it failed
return "XX ";
}
double timing = getComputationResult(r);
if (timing < 0.0) {
return "~~";
}
updateDigits();
String result = cellNumberFormat.format(timing);
if (CogToolPref.KLM_RESULT_RANGE.getBoolean() && withSecs != null && withSecs.length() > 0) {
result += " (" + cellNumberFormat.format(0.9 * timing);
result += ", " + cellNumberFormat.format(1.1 * timing);
result += ")";
}
result += withSecs;
return result;
// return (timing >= 0.0)
//// ? (cellNumberFormat.format(timing) + withSecs)
// ? (cellNumberFormat.format(timing) + withSecs + " ±10%")
// : "~~";
}
// Long form task application state descriptions, used for tooltips
// "" means no task application or no computable script for alg
// -- / "" means computable, not computed, and demo is valid
// -- / X means not computed and demo is invalid
// -- / ? means not computed and script needs regeneration
// NN / "" means computed and demo is valid
// NN / X means computed and demo is invalid
// NN / ? means computed and script needs regeneration
// ## / "" means computation failed and demo is valid
// ## / X means computation failed and demo is invalid
// ## / ? means computation failed, script needs regeneration
// (><) / ... means result is being computed
// ~~ / ... means result resulted in a negative number (??)
String demoState;
if (demo.isInvalid()) {
// " / X ";
demoState = " / INVALID";
} else if (demo.isObsolete()) {
// " / ? ";
demoState = " / OBSOLETE";
} else {
// " / ";
demoState = "";
}
if ((resultState == APredictionResult.NOT_COMPUTED) || !demo.isStartFrameChosen()) {
// No result yet computed for the associated script
return "NOT COMPUTED" + /* "--" */
demoState;
}
if (resultState == APredictionResult.COMPUTE_FAILED) {
// Has a result for this algo, but it failed
return "COMPUTE FAILED" + /* "##" */
demoState;
}
if (resultState == APredictionResult.COMPUTATION_IN_PROGRESS) {
// Result is being computed
return "BEING COMPUTED" + /* "(><)" */
demoState;
}
double timing = getComputationResult(r);
updateDigits();
return (timing >= 0.0) ? (cellNumberFormat.format(timing) + withSecs + demoState) : ("~~" + demoState);
}
Aggregations