def array2Dtable(array_list, verbose=1, titlestr=None): """ Generate HTML table with information about for a list of designs Args: array_list (list): list of arrays verbose (int): verbosity level """ page = markup.page() page.table(style=' border-collapse: collapse;') page.tr(style='font-weight: bold; border-bottom: solid 1px black;') page.th('Array', style='padding-right:30px; ') page.th(('D-efficiency', 'Ds-efficiency', 'D1-efficiency'), style='padding-right:14px;') page.th(('GWLP'), style='padding-right:14px;') page.tr.close() for ii, al in enumerate(array_list): aidx = ii (D, Ds, D1) = al.Defficiencies() gwlp = al.GWLP() page.tr(style='font-weight: normal;') page.td('%d' % aidx, style='padding-right:10px;') for statistic in [D, Ds, D1]: page.td('%.4f' % statistic, style='padding-right:1px;') gstr = oahelper.gwlp2str(gwlp) page.td(e.small(gstr), style='padding-right:1px;') page.tr.close() page.table.close() return page
def array2Dtable(sols, verbose=1, titlestr=None): """ Generate HTML table with information about for a list of designs """ na = len(sols) page = markup.page() page.table(style=' border-collapse: collapse;') page.tr(style='font-weight: bold; border-bottom: solid 1px black;') page.th('Array', style='padding-right:30px; ') page.th(('D-efficiency', 'Ds-efficiency', 'D1-efficiency'), style='padding-right:14px;') page.th(('GWLP'), style='padding-right:14px;') page.tr.close() for ii, al in enumerate(sols): aidx = ii (D, Ds, D1) = al.Defficiencies() gwlp = al.GWLP() page.tr(style='font-weight: normal;') page.td('%d' % aidx, style='padding-right:10px;') for v in [D, Ds, D1]: page.td('%.4f' % v, style='padding-right:1px;') gstr = oahelper.gwlp2str(gwlp) page.td(e.small(gstr), style='padding-right:1px;') page.tr.close() page.table.close() # page.p.close() return page
def array2html(X, header=1, tablestyle='border-collapse: collapse;', trclass='', tdstyle='', trstyle='', thstyle=''): """ Convert Numpy array to HTML table Arguments --------- X : numpy array array to be converted header : integer use header or not Returns ------- page : markup html object generated table in HTML """ page = markup.page() page.add('<!-- Created by array2html -->\n') page.table(style=tablestyle) offset = 0 nc = X.shape[1] nr = X.shape[0] if isinstance(trstyle, str): trstyle = [trstyle] * nr if isinstance(trclass, str): trclass = [trclass] * nr ri = 0 if header: page.tr(style='font-weight: bold; border-bottom: solid 1px black;' + trstyle[ri], class_=trclass[ri]) ri = ri + 1 for ii in range(nc): if isinstance(X[offset, ii], tuple): print('array2html: tuple instance') page.th(X[offset, ii][0], style=thstyle + X[offset, ii][1]) else: page.th(X[offset, ii], style=thstyle) page.tr.close() offset = offset + 1 nr = X.shape[0] - offset for _ in range(nr): page.tr(style=trstyle[ri], _class=trclass[ri]) for ii in range(nc): if isinstance(X[offset, ii], tuple): page.td(X[offset, ii][0], style=tdstyle + X[offset, ii][1]) else: page.td(X[offset, ii], style=tdstyle) page.tr.close() offset = offset + 1 ri = ri + 1 page.table.close() return page
def testHtml(hh=None): """ Test a short snippet of HTML """ if hh is None: return page = markup.page() page.init() page.body() page.add(hh) page.body.close() tmp, f = tempfile.mkstemp('.html') with open(f, 'wt') as fname: fname.write(str(page)) fname.close() webbrowser.open(fname.name)
def testHtml(html_code=None): """ Test a short snippet of HTML """ if html_code is None: return page = markup.page() page.init() page.body() page.add(html_code) page.body.close() _, f = tempfile.mkstemp('.html') with open(f, 'wt') as fname: fname.write(str(page)) fname.close() webbrowser.open(fname.name)
def generateDpage(outputdir, arrayclass, dds, allarrays, fig=20, optimfunc=[1, 0, 0], nofig=False, urlprefix='', makeheader=True, verbose=1, lbls=None): """ Helper function to generate web page with D-optimal design results """ if verbose: print('generateDpage: dds %s' % str(dds.shape)) pp = oahelper.createPareto(dds) narrays = dds.shape[0] npareto = pp.number() if verbose: print('generateDpage: narrays %d' % narrays) xstr = oahelper.series2htmlstr(arrayclass, case=1) xstrplain = oahelper.series2htmlstr(arrayclass, html=0, case=1) if verbose: print('generateDpage: selectParetoArrays ') paretoarrays = oahelper.selectParetoArrays(allarrays, pp) at = array2Dtable(paretoarrays, verbose=1) if verbose: print('generateDpage: write file with Pareto arrays') pfile0 = 'paretoarrays.oa' pfile = os.path.join(outputdir, pfile0) oalib.writearrayfile(pfile, paretoarrays) istrlnk = markup.oneliner.a('paretoarrays.oa', href=urlprefix + pfile0) if lbls is None: lbls = ['Optimization of $D$'] hh = generateDscatter(dds, lbls=lbls, fig=fig, nofig=nofig) oahelper.niceplot(hh.get('ax', None), despine=True, legend=hh['pltlegend']) scatterfile = os.path.join(outputdir, 'scatterplot.png') if verbose: print('generateDpage: writen scatterplot to %s' % scatterfile) plt.savefig(scatterfile, bbox_inches='tight', pad_inches=0.25, dpi=160) #%% Create page page = markup.page() if makeheader: page.init( title="Class %s" % xstrplain, css=('../oastyle.css'), lang='en', htmlattrs=dict({ 'xmlns': 'http://www.w3.org/1999/xhtml', 'xml:lang': 'en' }), header="<!-- Start of page -->", bodyattrs=dict({'style': 'padding-left: 3px;'}), # doctype=markup.doctype.strict, doctype= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', metainfo=({ 'text/html': 'charset=utf-8', 'keywords': 'orthogonal arrays designs', 'robots': 'index, follow', 'description': 'Even-Odd arrays' }), footer="<!-- End of page -->") page.h1('Results for array class %s ' % xstr) # mathjax is not updated properly... ss = 'The Pareto optimaly was calculated according to the statistics \(D\), \(D1\) and \(Ds\).' ss = 'The Pareto optimaly was calculated according to the statistics D, D<sub>1</sub> and D<sub>s</sub>.' if npareto == 1: page.p('Generated %d arrays, %d is Pareto optimal. %s' % (narrays, npareto, ss)) else: page.p('Generated %d arrays, %d are Pareto optimal. %s' % (narrays, npareto, ss)) if narrays > 0: scores = calcScore(dds, optimfunc) tmp, dd, sols = selectDn(scores, dds, allarrays, nout=1) A = sols[0] bestdesignfile = os.path.join(outputdir, 'best-design.oa') oalib.writearrayfile(bestdesignfile, A) page.h2('Best design') page.p('The best design: %s.' % e.a( 'best-design.oa', href=os.path.join(urlprefix, 'best-design.oa'))) page.p() dd = dd[0] page.span('D-efficiency: %.4f, ' % A.Defficiency()) # page.br() page.span('D<sub>s</sub>-efficiency: %.4f, ' % dd[1]) # page.br() page.span('D<sub>1</sub>-efficiency: %.4f' % dd[2]) page.br() page.span('A-efficiency: %.3f' % A.Aefficiency()) page.br() gwlp = A.GWLP() # gwlp=','.join(['%.3f' % xq for xq in gwlp]) gwlp = oahelper.gwlp2str(gwlp, jstr=', ') page.span('Generalized wordlength pattern: %s' % gwlp) page.br() # page.p('D-efficiency: %.3f' % A.Defficiency() ) pec = oalib.PECsequence(A) pec = ','.join(['%.3f' % xq for xq in pec]) page.span('PEC-sequence: %s' % pec) page.br() page.h2('Table of Pareto optimal arrays ') page.span(str(at)) page.p('All Pareto optimal arrays: %s' % istrlnk) page.img( src=urlprefix + 'scatterplot.png', style= "margin: 10px; width:95%; min-width: 300px; max-width:1100px; height: auto; " ) citationstr = markup.oneliner.a( 'Complete Enumeration of Pure-Level and Mixed-Level Orthogonal Arrays', href='http://dx.doi.org/10.1002/jcd.20236') page.br(clear='both') page.p( 'Citation notice: if you make use of the results on this page, please cite the following paper:' ) page.p( '%s, Journal of Combinatorial Designs, Volume 18, Issue 2, pages 123-140, 2010.' % citationstr) page.p('Generated with oapackage %s, date %s.' % (oalib.version(), oahelper.timeString())) outfile = os.path.join(outputdir, 'Dresults.html') fid = open(outfile, 'wt') fid.write(str(page)) fid.close() print('written to file %s' % outfile) return outfile
def generateDpage(outputdir, arrayclass, dds, allarrays, fig=20, optimfunc=[1, 0, 0], nofig=False, urlprefix='', makeheader=True, verbose=1, lbls=None): """ Helper function to generate web page with D-optimal design results """ if verbose: print('generateDpage: dds %s' % str(dds.shape)) pp = oahelper.createPareto(dds) narrays = dds.shape[0] npareto = pp.number() if verbose: print('generateDpage: narrays %d' % narrays) xstr = oahelper.series2htmlstr(arrayclass, case=1) xstrplain = oahelper.series2htmlstr(arrayclass, html=0, case=1) if verbose: print('generateDpage: selectParetoArrays ') paretoarrays = oahelper.selectParetoArrays(allarrays, pp) at = array2Dtable(paretoarrays, verbose=1) if verbose: print('generateDpage: write file with Pareto arrays') pfile0 = 'paretoarrays.oa' pfile = os.path.join(outputdir, pfile0) oalib.writearrayfile(pfile, paretoarrays) istrlnk = markup.oneliner.a('paretoarrays.oa', href=urlprefix + pfile0) if lbls is None: lbls = ['Optimization of $D$'] if fig is not None: hh = generateDscatter(dds, lbls=lbls, fig=fig, nofig=nofig) oahelper.niceplot(hh.get('ax', None), despine=True, legend=hh['pltlegend']) scatterfile = os.path.join(outputdir, 'scatterplot.png') if verbose: print('generateDpage: writen scatterplot to %s' % scatterfile) plt.savefig(scatterfile, bbox_inches='tight', pad_inches=0.25, dpi=160) page = markup.page() if makeheader: page.init(title="Class %s" % xstrplain, css=('../oastyle.css'), lang='en', htmlattrs=dict({'xmlns': 'http://www.w3.org/1999/xhtml', 'xml:lang': 'en'}), header="<!-- Start of page -->", bodyattrs=dict({'style': 'padding-left: 3px;'}), doctype='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', metainfo=({'text/html': 'charset=utf-8', 'keywords': 'orthogonal arrays designs', 'robots': 'index, follow', 'description': 'Even-Odd arrays'}), footer="<!-- End of page -->") page.h1('Results for array class %s ' % xstr) ss = r'The Pareto optimaly was calculated according to the statistics D, D<sub>1</sub> and D<sub>s</sub>.' if npareto == 1: page.p('Generated %d arrays, %d is Pareto optimal. %s' % (narrays, npareto, ss)) else: page.p('Generated %d arrays, %d are Pareto optimal. %s' % (narrays, npareto, ss)) if narrays > 0: scores = calcScore(dds, optimfunc) _, dd, sols = selectDn(scores, dds, allarrays, nout=1) A = sols[0] bestdesignfile = os.path.join(outputdir, 'best-design.oa') oalib.writearrayfile(bestdesignfile, A) page.h2('Best design') page.p('The best design: %s.' % e.a('best-design.oa', href=os.path.join(urlprefix, 'best-design.oa'))) page.p() dd = dd[0] page.span('D-efficiency: %.4f, ' % A.Defficiency()) # page.br() page.span('D<sub>s</sub>-efficiency: %.4f, ' % dd[1]) # page.br() page.span('D<sub>1</sub>-efficiency: %.4f' % dd[2]) page.br() page.span('A-efficiency: %.3f' % A.Aefficiency()) page.br() gwlp = A.GWLP() # gwlp=','.join(['%.3f' % xq for xq in gwlp]) gwlp = oahelper.gwlp2str(gwlp, jstr=', ') page.span('Generalized wordlength pattern: %s' % gwlp) page.br() # page.p('D-efficiency: %.3f' % A.Defficiency() ) pec = oalib.PECsequence(A) pec = ','.join(['%.3f' % xq for xq in pec]) page.span('PEC-sequence: %s' % pec) page.br() page.h2('Table of Pareto optimal arrays ') page.span(str(at)) page.p('All Pareto optimal arrays: %s' % istrlnk) page.img(src=urlprefix + 'scatterplot.png', style="margin: 10px; width:95%; min-width: 300px; max-width:1100px; height: auto; ") citationstr = markup.oneliner.a( 'Complete Enumeration of Pure-Level and Mixed-Level Orthogonal Arrays', href='https://doi.org/10.1002/jcd.20236') page.br(clear='both') page.p( 'Citation notice: if you make use of the results on this page, please cite the following paper:') page.p('%s, Journal of Combinatorial Designs, Volume 18, Issue 2, pages 123-140, 2010.' % citationstr) page.p('Generated with oapackage %s, date %s.' % (oalib.version(), oahelper.timeString())) outfile = os.path.join(outputdir, 'Dresults.html') fid = open(outfile, 'wt') fid.write(str(page)) fid.close() print('written to file %s' % outfile) return outfile