Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/Python/mcplot/html/mcplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_html(template_name, params, simfile):
text = open(os.path.join(os.path.dirname(__file__),template_name)).read()
text = text.replace("@PARAMS@", params)
text = text.replace("@DATAFILE@", simfile)

text = text.replace("@DATALINK@", "Click for ascii data")

logscalestr = "true" if logscale==True else "false"
text = text.replace("@LOGSCALE@", logscalestr)
text = text.replace("@LIBPATH@", libpath)
Expand Down
20 changes: 12 additions & 8 deletions tools/Python/mcplot/html/mcplotdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def get_html(template_name, params, simfile):
text = open(os.path.join(os.path.dirname(__file__), template_name)).read()
text = text.replace("@PARAMS@", params)
text = text.replace("@DATAFILE@", simfile)
text = text.replace("@DATALINK@", "Diff mode (no physical datafile)") # Nothing to link to in diff-mode

logscalestr = "true" if logscale == True else "false"
text = text.replace("@LOGSCALE@", logscalestr)
Expand Down Expand Up @@ -318,7 +319,8 @@ def write_index(outdir, entries, label_a, label_b):
outfile.write(" #sizecontrol input[type=range] { vertical-align: middle; margin: 0 8px; }\n")
outfile.write("</style>\n")
outfile.write("</head><body>\n")
outfile.write(f"<h1>Difference plots: {label_a} &minus; {label_b}</h1>\n")
outfile.write("<h1>Difference plots:</h1>\n")
outfile.write(f"<strong><ol type=\"A\"><li>{label_a} vs.<li>{label_b}</ol></strong>")
outfile.write(f"<p>diff.monitor = ({label_a}).monitor &minus; ({label_b}).monitor</p>\n")
outfile.write("<div id='sizecontrol'>\n")
outfile.write(" <label for='sizeslider'>Figure size:</label>\n")
Expand All @@ -335,28 +337,30 @@ def write_index(outdir, entries, label_a, label_b):
outfile.write(f"<iframe src='{basename}' title='{basename}' width={WIDTH} height={HEIGHT} style='transform:scale({initial_scale});'></iframe>\n")
outfile.write("</div>\n")
outfile.write("<div class='links'>\n")
outfile.write("<span class='links'>\n")
outfile.write(f"<a href='{basename}' target=_blank>[ {basename} ]</a>\n")
if fname_log:
basename_log = os.path.basename(fname_log)
outfile.write(f"<a href='{basename_log}' target=_blank>[ {basename_log} ]</a>\n")

outfile.write("</span><br>\n")
# links to the pre-existing mcplot-html plots of the two
# original monitors, if they were found on disk
a_lin = _relhref(entry.get('a_lin'), outdir)
a_log = _relhref(entry.get('a_log'), outdir)
b_lin = _relhref(entry.get('b_lin'), outdir)
b_log = _relhref(entry.get('b_log'), outdir)
if a_lin or a_log or b_lin or b_log:
outfile.write("<span class='origlinks'>|</span>\n")
outfile.write("<br><span class='origlinks'>\n")
if a_lin:
outfile.write(f"<a href='{a_lin}' target=_blank>[ {label_a} ]</a>\n")
outfile.write(f"<a href='{a_lin}' target=_blank>[ A ]</a>\n")
if a_log:
outfile.write(f"<a href='{a_log}' target=_blank>[ {label_a} (log) ]</a>\n")
outfile.write(f"<a href='{a_log}' target=_blank>[ A (log) ]</a>\n")
if b_lin:
outfile.write(f"<a href='{b_lin}' target=_blank>[ {label_b} ]</a>\n")
outfile.write(f"<a href='{b_lin}' target=_blank>[ B ]</a>\n")
if b_log:
outfile.write(f"<a href='{b_log}' target=_blank>[ {label_b} (log) ]</a>\n")

outfile.write(f"<a href='{b_log}' target=_blank>[ B (log) ]</a>\n")
if a_lin or a_log or b_lin or b_log:
outfile.write("<span class='origlinks'>\n")
outfile.write("</div>\n")
outfile.write("</div>\n")
outfile.write("</div>\n")
Expand Down
2 changes: 1 addition & 1 deletion tools/Python/mcplot/html/template_1d.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
plt.rgstrMouseRClickPlot( () => { console.log("right click"); } );
</script>
<p>
<a href="@DATAFILE@">Click for ascii data</a>
<a href="@DATAFILE@">@DATALINK@</a>
</body>
</html>
2 changes: 1 addition & 1 deletion tools/Python/mcplot/html/template_2d.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
plt.rgstrMouseRClickPlot( () => { console.log("right click"); } );
</script>
<p>
<a href="@DATAFILE@">Click for ascii data</a>
<a href="@DATAFILE@">@DATALINK@</a>
</body>
</html>
6 changes: 6 additions & 0 deletions tools/Python/mctest/main.template
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ a:visited { color: lightgrey; background-color: transparent; text-decoration: no
<td class=state_one><a href={{ c.5 }} >C:{{ c.1 }}/<strong>R:{{ c.2 }}</strong><br><strong>I={{ c.3 }}</strong> ({{ c.4 }})</a>
<br><a href={{ c.7 }} ><strong>{{ c.6 }}</strong></a>
<br>PLOTS: <a href={{ c.5 }}/02_plots.html >[Interactive HTML]</a> <a href={{ c.5 }}/01_overview.pdf >[PDF overview]</a>
{%- if c.8 %}
<hr><br>DIFF: <a href={{ c.8 }} >[vs ref]</a>
{%- endif %}
</td>
{%- elif c.0 == 2 %}
<td class=state_two><a href={{ c.5 }} >C:{{ c.1 }}/<strong>R:{{ c.2 }}</strong><br><strong>I={{ c.3 }}</strong> ({{ c.4 }})</a>
<br><a href={{ c.7 }} ><strong>{{ c.6 }}</strong></a>
<br>PLOTS: <a href={{ c.5 }}/02_plots.html >[Interactive HTML]</a> <a href={{ c.5 }}/01_overview.pdf >[PDF overview]</a>
{%- if c.8 %}
<br>DIFF: <a href={{ c.8 }} >[vs ref]</a>
{%- endif %}
</td>
{%- elif c.0 == 3 %}
<td class=state_three><a href={{ c.5 }} >C:{{ c.1 }}</a>
Expand Down
71 changes: 66 additions & 5 deletions tools/Python/mctest/mcviewtest.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_oldest_dir(directory_name):
files.sort(key=lambda x:x[0])
return files[0][1]

def run_normal_mode(testdir, reflabel):
def run_normal_mode(testdir, reflabel, nodiff=False, diffmax=300):
''' load test data and print to html label '''

def get_col_header(label, meta):
Expand All @@ -53,7 +53,55 @@ def get_header_lst(meta):
lst.append(meta["date"])
return lst

def get_cell_tuple(cellobj, refval=None):
def get_data_url(cellobj):
''' Reconstructs the relative "label/instrname/testnb/" data directory
for a cellobj, the same way get_cell_tuple() does for its own
cell - used here to also locate the *reference* column's data
directory when generating a diff link. '''
label = cellobj["localfile"].split("/")
if len(label) == 1:
label = cellobj["localfile"].split("\\")
label = label[len(label) - 3]
return label + "/" + cellobj["instrname"] + "/" + str(cellobj["testnb"]) + "/"

def generate_diff_link(refcellobj, url, label):
''' Generates (or reuses a cached) mcplotdiff-html comparison between
this cell's own test-output directory and the reference column's
corresponding directory, returning a relative URL to the diff
overview's index.html, or None if a diff isn't available/possible
(missing/incomplete data on either side, disabled via --nodiff,
or the plotter itself failing). '''
if nodiff:
return None
if refcellobj is None or refcellobj.get("testval") is None:
# no valid reference data to diff against
return None

ref_url = get_data_url(refcellobj)
test_abs = join(testdir, url)
ref_abs = join(testdir, ref_url)
if not (os.path.isfile(join(test_abs, "mccode.sim")) and os.path.isfile(join(ref_abs, "mccode.sim"))):
# NeXus-only output (mccode.h5) or otherwise nothing mcplotdiff-html can compare
return None

outdir_rel = join(url, "diff_vs_%s" % reflabel)
outdir_abs = join(testdir, outdir_rel)
index_abs = join(outdir_abs, "index.html")

if not os.path.isfile(index_abs):
diffplotter = mccode_config.configuration["MCPLOT"].split('-')[0] + "diff-html"
cmd = '%s "%s" "%s" --nobrowse -A "%s" -B "%s" --output "%s"' % (
diffplotter, test_abs, ref_abs, label, reflabel, outdir_abs)
try:
utils.run_subtool_noread(cmd, cwd=testdir, timeout=diffmax)
except Exception as e:
print("generate_diff_link: %s" % str(e))

if os.path.isfile(index_abs):
return (outdir_rel + "/index.html").replace(os.sep, '/').replace("//", "/")
return None

def get_cell_tuple(cellobj, refval=None, refcellobj=None):
''' set up and format cell data '''
state = None
compiletime = None
Expand Down Expand Up @@ -141,7 +189,9 @@ def get_cell_tuple(cellobj, refval=None):
else:
refp = "%2.f" % refp + "%"

return (state, compiletime, runtime, testval, refp, url, display, displayurl)
diffurl = generate_diff_link(refcellobj, url, label)

return (state, compiletime, runtime, testval, refp, url, display, displayurl, diffurl)

def get_empty_cell_tuple(tag=None):
''' return a "state_four" black cell, optionally with a tag, this could be "no ref" or "no test" etc. '''
Expand Down Expand Up @@ -188,7 +238,13 @@ def iterate_obj_to_populate_rows(iterobj, otherobjs, rows, ncols, use_iterobj_re
targetval = o.get("targetval", None)
if use_iterobj_refvalue:
targetval = iterobj[key]["targetval"]
row.append(get_cell_tuple(o, targetval))
# diff cells always compare against the true reference
# column (refobj), regardless of which object is
# currently driving iteration (iterobj may be a
# fallback "lead" column rather than refobj itself, in
# the untested multi-column case below)
refcellobj = refobj.get(key, None)
row.append(get_cell_tuple(o, targetval, refcellobj=refcellobj))

# delete "used" cell keys
if del_used_from_overobjs:
Expand Down Expand Up @@ -304,7 +360,10 @@ def main(args):
print("No testdir defined, will use current dir")
print("--> Using testdir=%s\n" % os.getcwd())
testdir=os.getcwd()
run_normal_mode(testdir, reflabel)
diffmax = 300
if args.diffmax:
diffmax = int(args.diffmax[0])
run_normal_mode(testdir, reflabel, nodiff=args.nodiff, diffmax=diffmax)

if not args.nobrowse:
subprocess.Popen('%s %s' % (mccode_config.configuration['BROWSER'], os.path.join(testdir,os.path.basename(testdir) +'_output.html')), shell=True)
Expand All @@ -318,6 +377,8 @@ def main(args):
parser.add_argument('--testroot', nargs="?", help='test root folder for test result management')
parser.add_argument('--verbose', action='store_true', help='output excessive information for debug purposes')
parser.add_argument('--nobrowse', action='store_true', help='Do not spawn browser on exit')
parser.add_argument('--nodiff', action='store_true', help='Do not generate mcplotdiff-html comparison cells against the reference column')
parser.add_argument('--diffmax', nargs=1, help='Maximum time (s) allowed per mcplotdiff-html comparison (default 300s)')
args = parser.parse_args()

main(args)
Expand Down
Loading