From 9e1f267cea4fa7925a7116f2f575543e68a50acf Mon Sep 17 00:00:00 2001 From: jdramsey Date: Wed, 12 Jun 2024 18:12:52 -0400 Subject: [PATCH] Add resultsPath field to GridSearchModel A new field, resultsPath, has been added to the GridSearchModel class, along with its setter and getter methods. This field represents the path to the result folder. This is set after a comparison has been run, and used to add additional contents like simulation, algorithm, table columns, and verbose output to the comparison results. --- .../tetradapp/editor/GridSearchEditor.java | 40 +++++++++++++++++-- .../cmu/tetradapp/model/GridSearchModel.java | 20 ++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GridSearchEditor.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GridSearchEditor.java index a944cb5c2e..ed7a4f16a2 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GridSearchEditor.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/editor/GridSearchEditor.java @@ -34,10 +34,7 @@ import javax.swing.table.TableRowSorter; import javax.swing.text.BadLocationException; import java.awt.*; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; +import java.io.*; import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; @@ -1425,6 +1422,41 @@ public void watch() { try { model.runComparison(ps); + + String resultsPath = model.getResultsPath(); + + if (resultsPath != null && simulationChoiceTextArea != null) { + // Write contents of simulation text area to a file at resultsPath + "/simulation.txt" + try (PrintWriter writer = new PrintWriter(resultsPath + "/simulation.txt")) { + writer.println(simulationChoiceTextArea.getText()); + } catch (FileNotFoundException ex) { + throw new RuntimeException(ex); + } + + // Write contents of algorithm text area to a file at resultsPath + "/algorithm.txt" + try (PrintWriter writer = new PrintWriter(resultsPath + "/algorithm.txt")) { + writer.println(algorithmChoiceTextArea.getText()); + } catch (FileNotFoundException ex) { + throw new RuntimeException(ex); + } + + // Write contents of table columns text area to a file at resultsPath + "/tableColumns.txt" + try (PrintWriter writer = new PrintWriter(resultsPath + "/tableColumns.txt")) { + writer.println(tableColumnsChoiceTextArea.getText()); + } catch (FileNotFoundException ex) { + throw new RuntimeException(ex); + } + + // Write contents of verbose output text area to a file at resultsPath + "/verboseOutput.txt" + try (PrintWriter writer = new PrintWriter(resultsPath + "/verboseOutput.txt")) { + writer.println(verboseOutputTextArea.getText()); + } catch (FileNotFoundException ex) { + throw new RuntimeException(ex); + } + + + } + } catch (Exception ex) { throw new RuntimeException(ex); } diff --git a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GridSearchModel.java b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GridSearchModel.java index 925bddf76b..f2077c7548 100644 --- a/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GridSearchModel.java +++ b/tetrad-gui/src/main/java/edu/cmu/tetradapp/model/GridSearchModel.java @@ -133,6 +133,11 @@ public class GridSearchModel implements SessionModel { * The name of the GridSearchModel. */ private String name = "Grid Search"; + /** + * The variable resultsPath represents the path to the result folder. This is set after a comparison has been run + * and can be used to add additional files to the comparison results. + */ + private String resultsPath = null; /** * Constructs a new GridSearchModel with the specified parameters. @@ -453,6 +458,9 @@ public void runComparison(java.io.PrintStream localOut) { String outputFileName = "Comparison.txt"; comparison.compareFromSimulations(resultsPath, simulations, outputFileName, localOut, algorithms, getSelectedStatistics(), new Parameters(parameters)); + + this.resultsPath = resultsPath; + } private LinkedList getSelectedAlgorithmSpecs() { @@ -1090,6 +1098,18 @@ public DataSet getSuppliedData() { return suppliedData; } + public void setResultsPath(String resultsPath) { + this.resultsPath = resultsPath; + } + + /** + * The variable resultsPath represents the path to the result folder. This is set after a comparison has been run + * and can be used to add additional files to the comparison results. + */ + public String getResultsPath() { + return resultsPath; + } + /** * This class represents the comparison graph type for graph-based comparison algorithms. ComparisonGraphType is an * enumeration type that represents different types of comparison graphs. The available types are DAG (Directed