Example #1
0
def go_(model_name, queries, result_like, what_to_plot_res, what_to_plot_fun, fn):
    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_queries(ndp, queries, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    print('writing to %r' % fn)
    r.to_html(fn)
Example #2
0
def get_split_test_document():
    md = test_md
    library = MCDPLibrary()
    realpath = 'internal'
    raise_errors = True
    rendered = render_complete(library=library,
                               s=md,
                               raise_errors=raise_errors,
                               realpath=realpath,
                               generate_pdf=False,
                               check_refs=True,
                               filter_soup=None)

    files_contents = [
        DocToJoin(docname='unused', source_info=None, contents=rendered)
    ]
    stylesheet = None
    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <style>
        
        </style>
        <body></body></html>
        """
    complete = manual_join(template=template,
                           files_contents=files_contents,
                           stylesheet=stylesheet,
                           remove=None,
                           extra_css=None,
                           hook_before_toc=None)

    return complete
Example #3
0
def go_(model_name, queries, result_like, what_to_plot_res, what_to_plot_fun,
        fn):
    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_queries(ndp, queries, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    print('writing to %r' % fn)
    r.to_html(fn)
Example #4
0
def check_join_not_existence():
    """ A test for finite posets where the join might not exist. """
    from mcdp_library.library import MCDPLibrary
    l = MCDPLibrary()

    add_def_poset(
        l, 'P', """
    finite_poset {
        a <= b <= c
        A <= B <= C
    }
    """)

    #     parse_wrap(Syntax.LOAD, '`')
    #     parse_wrap(Syntax.posetname, 'P')
    #     print Syntax.load_poset
    #     parse_wrap(Syntax.load_poset, '`P')
    #     parse_wrap(Syntax.space_operand, '`P')
    #     parse_wrap(Syntax.fun_statement, "provides x [`P]")

    ndp = l.parse_ndp("""
        mcdp {
            provides x [`P]
            provides y [`P]
            requires z [`P]
            
            z >= x
            z >= y
        }
    """,
                      context=Context())
    dp = ndp.get_dp()

    res1 = dp.solve(('a', 'b'))

    P = l.load_poset('P')
    UR = UpperSets(P)
    UR.check_equal(res1, UpperSet(['b'], P))

    res2 = dp.solve(('a', 'A'))

    UR.check_equal(res2, UpperSet([], P))
Example #5
0
def render_book(src_dir,
                docname,
                generate_pdf,
                main_file,
                out_part_basename,
                filter_soup=None,
                extra_css=None):
    from mcdp_docs.pipeline import render_complete

    librarian = get_test_librarian()
    librarian.find_libraries('.')

    load_library_hooks = [librarian.load_library]
    library = MCDPLibrary(load_library_hooks=load_library_hooks)
    library.add_search_dir(src_dir)
    #
    #     data = dict(path=dirname, library=l)
    #     l.library_name = library_name
    #
    #     library = librarian.load_library(libname)
    #
    #     l = library.load_library(libname)

    d = tempfile.mkdtemp()
    library.use_cache_dir(d)

    basename = docname + '.' + MCDPConstants.ext_doc_md
    f = library._get_file_data(basename)
    data = f['data']
    realpath = f['realpath']

    def filter_soup0(soup, library):
        if filter_soup is not None:
            filter_soup(soup=soup, library=library)
        add_edit_links(soup, realpath)

    html_contents = render_complete(library=library,
                                    s=data,
                                    raise_errors=True,
                                    realpath=realpath,
                                    generate_pdf=generate_pdf,
                                    filter_soup=filter_soup0)

    doc = get_minimal_document(html_contents,
                               add_markdown_css=True,
                               extra_css=extra_css)
    dirname = main_file + '.parts'
    if dirname and not os.path.exists(dirname):
        try:
            os.makedirs(dirname)
        except:
            pass
    fn = os.path.join(dirname, '%s.html' % out_part_basename)
    with open(fn, 'w') as f:
        f.write(doc)

    return (('unused', docname), html_contents)
Example #6
0
def check_join_not_existence():
    """ A test for finite posets where the join might not exist. """
    from mcdp_library.library import MCDPLibrary
    l = MCDPLibrary()

    add_def_poset(l, 'P', """
    finite_poset {
        a <= b <= c
        A <= B <= C
    }
    """)


#     parse_wrap(Syntax.LOAD, '`')
#     parse_wrap(Syntax.posetname, 'P')
#     print Syntax.load_poset
#     parse_wrap(Syntax.load_poset, '`P')
#     parse_wrap(Syntax.space_operand, '`P')
#     parse_wrap(Syntax.fun_statement, "provides x [`P]")

    ndp = l.parse_ndp("""
        mcdp {
            provides x [`P]
            provides y [`P]
            requires z [`P]
            
            z >= x
            z >= y
        }
    """, context=Context())
    dp = ndp.get_dp()

    res1 = dp.solve(('a', 'b'))

    P = l.load_poset('P')
    UR = UpperSets(P)
    UR.check_equal(res1, UpperSet(['b'], P))

    res2 = dp.solve(('a', 'A'))

    UR.check_equal(res2, UpperSet([], P))
Example #7
0
def go():
    combinations = {
        "capacity": (np.linspace(50, 3000, 10), "Wh"),
        "missions": ( 1000, "[]"),
    }
    result_like = dict(maintenance="dimensionless", cost="USD", mass='kg')
    what_to_plot_res = result_like
    what_to_plot_fun = dict(capacity="Wh", missions="[]")

    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp('batteries')

    data = solve_combinations(ndp, combinations, result_like)

    r = Report()

    plot_all_directions(r, queries=data['queries'], results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    r.to_html('out/batteries-c1.html')
Example #8
0
def go():
    fn = 'out/actuation_c1.html'
 
    model_name = 'actuation'
    queries = []
    def add(q):
        queries.append(q)

    n = 10
    lifts = np.linspace(0, 10.0, n)

    for lift,  in zip(lifts):
        q = {
            "lift": (lift, "N"),
        }
        add(q)

    result_like = dict(power="W", cost='$')
    
    what_to_plot_res = result_like
    
    what_to_plot_fun = dict(lift="N")


    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_queries(ndp, queries, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    print('writing to %r' % fn)
    r.to_html(fn)
Example #9
0
def go2():
    model_name = 'batteries_squash'
    combinations = {
        "capacity": (np.linspace(50, 3000, 10), "Wh"),
        "missions": (1000, "[]"),
    }
    result_like = dict(cost="USD", mass='kg')
    what_to_plot_res = result_like
    what_to_plot_fun = dict(capacity="Wh", missions="[]")

    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_combinations(ndp, combinations, result_like)

    r = Report()

    plot_all_directions(r, queries=data['queries'], results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    r.to_html('out/batteries_squash-c2.html')
Example #10
0
def go():
    fn = 'out/actuation_c1.html'

    model_name = 'actuation'
    queries = []

    def add(q):
        queries.append(q)

    n = 10
    lifts = np.linspace(0, 10.0, n)

    for lift, in zip(lifts):
        q = {
            "lift": (lift, "N"),
        }
        add(q)

    result_like = dict(power="W", cost='$')

    what_to_plot_res = result_like

    what_to_plot_fun = dict(lift="N")

    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_queries(ndp, queries, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    print('writing to %r' % fn)
    r.to_html(fn)
Example #11
0
def go():
    combinations = {
        "capacity": (np.linspace(50, 3000, 10), "Wh"),
        "missions": (1000, "[]"),
    }
    result_like = dict(maintenance="dimensionless", cost="USD", mass='kg')
    what_to_plot_res = result_like
    what_to_plot_fun = dict(capacity="Wh", missions="[]")

    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp('batteries')

    data = solve_combinations(ndp, combinations, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    r.to_html('out/batteries-c1.html')
Example #12
0
def go2():
    model_name = 'batteries_squash'
    combinations = {
        "capacity": (np.linspace(50, 3000, 10), "Wh"),
        "missions": (1000, "[]"),
    }
    result_like = dict(cost="USD", mass='kg')
    what_to_plot_res = result_like
    what_to_plot_fun = dict(capacity="Wh", missions="[]")

    lib = MCDPLibrary()
    lib.add_search_dir('.')
    ndp = lib.load_ndp(model_name)

    data = solve_combinations(ndp, combinations, result_like)

    r = Report()

    plot_all_directions(r,
                        queries=data['queries'],
                        results=data['results'],
                        what_to_plot_res=what_to_plot_res,
                        what_to_plot_fun=what_to_plot_fun)
    r.to_html('out/batteries_squash-c2.html')
Example #13
0
def tryit(s, write_to=None, forbid=[]):
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library,
                         s,
                         raise_errors,
                         realpath,
                         generate_pdf=False)

    if False:
        if write_to is not None:
            doc = get_minimal_document(s2, add_manual_css=True)
            with open(write_to, 'wb') as f:
                f.write(doc)
            print('written to %s' % write_to)

    tests = {
        'doctype': not 'DOCTYPE' in s2,
        'warn_caption': not 'caption' in s2,
        'warn_centering': not 'centering' in s2,
        'warn_tabular': not 'tabular' in s2,
        'funny': not '&amp;#96;' in s2,
        'dollarfix': not TAG_DOLLAR in s2,
        #     assert not '&#96;' in s2
        #     assert not '&amp;' in s2
    }
    for x in forbid:
        tests['contains %r' % x] = not x in s2
    msg = ''
    summary = {'warn': 0, 'error': 0}
    for k in sorted(tests):
        level = 'warn' if 'warn' in k else 'error'
        passed = tests[k]
        if not passed:
            summary[level] += 1
        mark = '✓' if passed else 'no'
        msg += '\n %20s : %s' % (k, mark)

    if summary['error']:
        if len(s2) < 10000:
            msg += '\n\n' + indent(s2, '> ')

        if write_to is not None:
            msg += '\nSee output in %s' % (write_to)
        raise_desc(Exception, msg)

    return s2
Example #14
0
def tags_in_titles2():
    template = """
    <html>
    <head>
        </head>
    <body>
        <div id='toc'></div>
    </body>
    </html>
"""
    s = """


<span id='frag'>I will refer to <a href="#two" class='number_name'></a></span>

# One is ok {#one}

Ignore

# Two with `program` {#two}

Another.
 
    
"""
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library, s, raise_errors, realpath, generate_pdf=False)
    files_contents= [DocToJoin(docname='one', contents=s2, source_info=None)]
    stylesheet = 'v_manual_blurb_ready'
    res_aug = manual_join(template, files_contents,
                stylesheet, remove=None, extra_css=None,
                remove_selectors=None,
                hook_before_toc=None)

    soup = bs(res_aug.get_result())
    element = soup.find(id='main_toc')
    print element
    if 'fragment' in str(element):
        raise Exception(str(element))
Example #15
0
def tags_in_titles1():
    template = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
    <html lang="en">
    <head>
        <title>The Duckietown book</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
<body>
</body>
</html>
"""
    s = """


<span id='frag'>I will refer to <a href="#two" class='number_name'></a></span>

# Two with `program` {#two}

Another.
 
    
"""
    library = MCDPLibrary()
    raise_errors = True
    realpath = 'transformations.py'
    s2 = render_complete(library, s, raise_errors, realpath, generate_pdf=False)
    files_contents= [DocToJoin(docname='one', contents=s2, source_info=None)]
    stylesheet = 'v_manual_blurb_ready'
    res_aug = manual_join(template=template, files_contents=files_contents,
                stylesheet=stylesheet, remove=None, extra_css=None,
                remove_selectors=None,
                hook_before_toc=None)
    soup = bs(res_aug.get_result())
    element = soup.find(id='frag')
    print element
    if '&lt;code&gt;' in str(element):
        raise Exception(str(element))
Example #16
0
def get_split_test_document():
    md = test_md
    library = MCDPLibrary()
    realpath = 'internal'
    raise_errors = True
    rendered = render_complete(library, md, raise_errors, realpath, generate_pdf=False,
                    check_refs=True, do_math=True, filter_soup=None,
                    raise_missing_image_errors = False)
    
    files_contents = [(('unused', 'unusued'), rendered)]
    bibfile = None
    stylesheet = None
    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <style>
        
        </style>
        <body></body></html>
        """
    complete =  manual_join(template, files_contents, bibfile, stylesheet, remove=None, extra_css=None,
                            hook_before_toc=None)
        
    return complete
Example #17
0
def get_library():
    lib = MCDPLibrary()
    lib.use_cache_dir('_cached/plot_batteries_cache')
    lib.add_search_dir('.')
    return lib
Example #18
0
def test_toc_numbers1():
    s = r"""
    
<div id='toc'></div>

# Part One {#part:one}

# Chapter One

## Sub One_point_One

Referring to [](#fig:One) and [](#fig:Two) and [](#tab:One).

Also referring only with numbers: 
<a href="#fig:One" class='only_number'></a>,
<a href="#fig:Two" class='only_number'></a>,
<a href="#tab:One" class='only_number'></a>.

<s figure-id="fig:One">Figure One</s>

### Sub sub One_point_One_point_One
#### Par a
#### Par b


## Sub One_point_Two

Referring to subfigures [](#subfig:child1) and [](#subfig:child2).
  
<div figure-id="fig:parent">
    <div figure-id="subfig:child1" figure-caption="child1">
    child1
    </div>
    <div figure-id="subfig:child2" figure-caption="child2">
    child2
    </div>
</div>


<div figure-id="code:code1">
    <pre><code>code1</code></pre>
</div>

## Sub with `code` in the <k>name</k>

# Chapter Two 

<s figure-id="fig:Two">Figure Two</s>

<s figure-id="tab:One">Table One</s>

## Sub Two_point_One

# Part Two {#part:two}

# Chapter Three

\begin{definition}[DefinitionA]\label{def:A}Definition A\end{definition}
\begin{defn}[DefinitionA2]\label{def:A2}Definition A2\end{defn}

\begin{proposition}[PropositionB]\label{prop:B}Proposition B\end{proposition}

\begin{problem}[ProblemC]\label{prob:C}Problem C\end{problem}

\begin{example}[exampleD]\label{exa:D}...\end{example}
\begin{remark}[remarkE]\label{rem:E}...\end{remark}
\begin{lemma}[lammaF]\label{lem:F}...\end{lemma}
\begin{theorem}[theoremG]\label{thm:G}...\end{theorem}
\begin{thm}[theoremG2]\label{thm:G2}...\end{thm}

Citing: 
[](#def:A),
[](#prop:B),
[](#prob:C),
[](#exa:D),
[](#rem:E),
[](#lem:F),
[](#thm:G).

Citing full name:
<a href="#def:A" class="number_name"></a>,
<a href="#prop:B" class="number_name"></a>,
<a href="#prob:C" class="number_name"></a>,
<a href="#exa:D" class="number_name"></a>,
<a href="#rem:E" class="number_name"></a>,
<a href="#lem:F" class="number_name"></a>,
<a href="#thm:G" class="number_name"></a>.

Citing only name:
<a href="#def:A" class="only_name"></a>,
<a href="#prop:B" class="only_name"></a>,
<a href="#prob:C" class="only_name"></a>,
<a href="#exa:D" class="only_name"></a>,
<a href="#rem:E" class="only_name"></a>,
<a href="#lem:F" class="only_name"></a>,
<a href="#thm:G" class="only_name"></a>.


Citing only number:
<a href="#def:A" class="only_number"></a>,
<a href="#prop:B" class="only_number"></a>,
<a href="#prob:C" class="only_number"></a>,
<a href="#exa:D" class="only_number"></a>,
<a href="#rem:E" class="only_number"></a>,
<a href="#lem:F" class="only_number"></a>,
<a href="#thm:G" class="only_number"></a>.


# Appendices {#part:appendices}

# Appendix A {#app:A}
# Appendix B {#app:B}
## App sub B_point_One 
### App subsub B_point_One_point_One

    """
    library = MCDPLibrary()
    raise_errors = True
    realpath = __name__
    s = render_complete(library, s, raise_errors, realpath)

    template = """<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head><body></body></html>
        """
    files_contents = [(('a', 'b'), s)]
    stylesheet = 'v_manual_blurb_ready'
    res = manual_join(template=template,
                      files_contents=files_contents,
                      bibfile=None,
                      stylesheet=stylesheet)

    fn = 'out/comptests/test_toc_numbers1.html'  # XXX: write on test folder
    logger.info('written on %s' % fn)
    with open(fn, 'w') as f:
        f.write(res)
Example #19
0
def get_library():
    lib = MCDPLibrary()
    lib.use_cache_dir('_cached/plot_batteries_cache')
    lib.add_search_dir('.')
    return lib