Search in sources :

Example 1 with SampleTableModel

use of gov.sandia.n2a.ui.studies.PanelStudy.SampleTableModel in project n2a by frothga.

the class Main method studyHeadless.

/**
 *        Run a study from the command line.
 *        Unlike runHeadless(), this function uses all the usual job management machinery.
 */
public static void studyHeadless(MNode record) {
    String key = record.key();
    MNode doc = AppData.models.childOrEmpty(key);
    record.mergeUnder(doc);
    MPart collated = new MPart(record);
    if (!collated.containsKey("study"))
        return;
    // Start host monitor threads (see PanelRun constructor for non-headless procedure)
    Host.restartAssignmentThread();
    for (Host h : Host.getHosts()) h.restartMonitorThread();
    MNode studyNode = PanelEquations.createStudy(collated);
    // constructed in paused state
    Study study = new Study(studyNode);
    // start
    study.togglePause();
    study.waitForCompletion();
    // Output CSV files, if requested.
    if (record.getFlag("$metadata", "csv")) {
        Path studyDir = study.getDir();
        try (BufferedWriter parms = Files.newBufferedWriter(studyDir.resolve("study.csv"))) {
            SampleTableModel samples = new SampleTableModel();
            samples.update(study);
            int rows = samples.getRowCount();
            int cols = samples.getColumnCount();
            int lastCol = cols - 1;
            // Header for study.csv file
            for (// first column is job status, so skip it
            int c = 1; // first column is job status, so skip it
            c < cols; // first column is job status, so skip it
            c++) {
                parms.write(samples.getColumnName(c));
                if (c < lastCol)
                    parms.write(",");
            }
            parms.newLine();
            // Rows for study.csv file, along with converted output of each job.
            for (int r = 0; r < rows; r++) {
                for (int c = 1; c < cols; c++) {
                    parms.write(samples.getValueAt(r, c).toString());
                    if (c < lastCol)
                        parms.write(",");
                }
                parms.newLine();
                NodeJob jobNode = study.getJob(r);
                Path jobDir = Host.getJobDir(Host.getLocalResourceDir(), jobNode.getSource());
                try {
                    Table table = new Table(jobDir.resolve("out"), false);
                    table.dumpCSV(studyDir.resolve(r + ".csv"));
                } catch (IOException e) {
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // See MainFrame window close listener
    // Save any modified data, particularly the study record.
    AppData.quit();
    // Close down any ssh sessions.
    Host.quit();
}
Also used : Path(java.nio.file.Path) Study(gov.sandia.n2a.ui.studies.Study) MPart(gov.sandia.n2a.eqset.MPart) Table(gov.sandia.n2a.ui.jobs.Table) SampleTableModel(gov.sandia.n2a.ui.studies.PanelStudy.SampleTableModel) Host(gov.sandia.n2a.host.Host) NodeJob(gov.sandia.n2a.ui.jobs.NodeJob) IOException(java.io.IOException) MNode(gov.sandia.n2a.db.MNode) BufferedWriter(java.io.BufferedWriter)

Aggregations

MNode (gov.sandia.n2a.db.MNode)1 MPart (gov.sandia.n2a.eqset.MPart)1 Host (gov.sandia.n2a.host.Host)1 NodeJob (gov.sandia.n2a.ui.jobs.NodeJob)1 Table (gov.sandia.n2a.ui.jobs.Table)1 SampleTableModel (gov.sandia.n2a.ui.studies.PanelStudy.SampleTableModel)1 Study (gov.sandia.n2a.ui.studies.Study)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1