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();
}
Aggregations