Search in sources :

Example 1 with ParsedValue

use of gov.sandia.n2a.eqset.Variable.ParsedValue in project n2a by frothga.

the class PanelRun method viewJob.

public void viewJob(boolean refresh) {
    if (displayThread != null) {
        synchronized (displayText) {
            displayThread.stop = true;
            displayThread = null;
        }
    }
    StringBuilder contents = new StringBuilder();
    contents.append("Status:");
    NodeJob jobNode = (NodeJob) displayNode;
    if (jobNode.complete < 0)
        contents.append(" Waiting");
    else if (jobNode.complete == 0)
        contents.append(" Started");
    else if (jobNode.complete > 0 && jobNode.complete < 1)
        contents.append(" " + Math.round(jobNode.complete * 100) + "%");
    else if (jobNode.complete == 1)
        contents.append(" Success");
    else if (jobNode.complete == 3)
        contents.append(" Killed (lingering)");
    else if (jobNode.complete == 4)
        contents.append(" Killed");
    else
        // complete==2, or any value not specified above
        contents.append(" Failed");
    contents.append("\n");
    if (jobNode.dateStarted != null)
        contents.append("  started:  " + jobNode.dateStarted + "\n");
    if (jobNode.dateFinished != null)
        contents.append("  finished: " + jobNode.dateFinished + "\n");
    contents.append("\n");
    MNode job = jobNode.getSource();
    if (// job can be null if it is deleted while we are preparing this status text.
    job != null) {
        appendMetadata(job, contents, "backend");
        appendMetadata(job, contents, "duration");
        appendMetadata(job, contents, "host");
        appendMetadata(job, contents, "pid");
        appendMetadata(job, contents, "seed");
        contents.append("\n");
    }
    // Walk the model and display all overridden parameters.
    if (job != null && jobNode.hasSnapshot()) {
        // Obtain top-level model and collated model
        MNode doc;
        MNode model;
        String key = job.get("$inherit");
        Path localJobDir = Host.getJobDir(Host.getLocalResourceDir(), job);
        Path snapshotPath = localJobDir.resolve("snapshot");
        if (Files.exists(snapshotPath)) {
            MNode snapshot = new MDoc(snapshotPath);
            doc = snapshot.child(key);
            model = MPart.fromSnapshot(key, snapshot);
        } else {
            doc = AppData.models.childOrEmpty(key);
            model = new MDoc(localJobDir.resolve("model"), key);
        }
        doc.visit(new Visitor() {

            public boolean visit(MNode node) {
                List<String> keyList = Arrays.asList(node.keyPath(doc));
                List<String> paramPath = new ArrayList<String>(keyList);
                paramPath.add("$metadata");
                paramPath.add("param");
                Object[] paramArray = paramPath.toArray();
                // node is not a parameter
                if (!model.getFlag(paramArray))
                    return true;
                // watchable items aren't of interest for this summary
                if (model.get(paramArray).equals("watch"))
                    return true;
                String[] keyPath = keyList.toArray(new String[keyList.size()]);
                String key = keyPath[0];
                for (int i = 1; i < keyPath.length; i++) key += "." + keyPath[i];
                ParsedValue pv = new ParsedValue(model.get(keyPath));
                contents.append(key + " =" + pv.combiner + " " + pv.expression + "\n");
                if (// Could be multi-valued
                pv.expression.isEmpty()) {
                    for (MNode v : model.childOrEmpty(keyPath)) {
                        key = v.key();
                        if (key.contains("@"))
                            contents.append("\t" + v.get() + "\t" + key + "\n");
                    }
                }
                return true;
            }
        });
    }
    synchronized (displayText) {
        if (refresh) {
            Caret c = displayText.getCaret();
            int dot = c.getDot();
            int mark = c.getMark();
            Point magic = c.getMagicCaretPosition();
            if (magic == null)
                magic = new Point();
            Rectangle visible = displayPane.getViewport().getViewRect();
            if (// User has scrolled away from caret.
            !visible.contains(magic)) {
                // Scroll takes precedence over caret, so move caret back into visible area.
                Font f = displayText.getFont();
                FontMetrics fm = displayText.getFontMetrics(f);
                int h = fm.getHeight();
                int w = fm.getMaxAdvance();
                if (w < 0)
                    w = h / 2;
                h += h / 2;
                w += w / 2;
                magic.x = Math.max(magic.x, visible.x == 0 ? 0 : visible.x + w);
                magic.x = Math.min(magic.x, visible.x + visible.width - w);
                magic.y = Math.max(magic.y, visible.y == 0 ? 0 : visible.y + h);
                magic.y = Math.min(magic.y, visible.y + visible.height - h);
                dot = mark = displayText.viewToModel2D(magic);
            }
            displayText.setText(contents.toString());
            c.setDot(mark);
            if (dot != mark)
                c.moveDot(dot);
        } else {
            displayText.setText(contents.toString());
            displayText.setCaretPosition(0);
        }
    }
    displayChart.buttonBar.setVisible(false);
    if (displayPane.getViewport().getView() != displayText)
        displayPane.setViewportView(displayText);
    displayPane.repaint();
}
Also used : Path(java.nio.file.Path) TreePath(javax.swing.tree.TreePath) Visitor(gov.sandia.n2a.db.MNode.Visitor) Rectangle(java.awt.Rectangle) Point(java.awt.Point) MNode(gov.sandia.n2a.db.MNode) Point(java.awt.Point) Font(java.awt.Font) MDoc(gov.sandia.n2a.db.MDoc) ParsedValue(gov.sandia.n2a.eqset.Variable.ParsedValue) FontMetrics(java.awt.FontMetrics) List(java.util.List) ArrayList(java.util.ArrayList) Caret(javax.swing.text.Caret)

Aggregations

MDoc (gov.sandia.n2a.db.MDoc)1 MNode (gov.sandia.n2a.db.MNode)1 Visitor (gov.sandia.n2a.db.MNode.Visitor)1 ParsedValue (gov.sandia.n2a.eqset.Variable.ParsedValue)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Caret (javax.swing.text.Caret)1 TreePath (javax.swing.tree.TreePath)1