当前位置: 首页>>代码示例>>Python>>正文


Python yattag.Doc方法代码示例

本文整理汇总了Python中yattag.Doc方法的典型用法代码示例。如果您正苦于以下问题:Python yattag.Doc方法的具体用法?Python yattag.Doc怎么用?Python yattag.Doc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yattag的用法示例。


在下文中一共展示了yattag.Doc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_table_html

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_table_html(header, rows, row_names=None):
    def add_header(doc, header):
        with doc.tag('tr'):
            for value in header:
                doc.line('th', value)

    def add_row(doc, values, row_name=None):
        with doc.tag('tr'):
            if row_name is not None:
                doc.line('th', row_name)
            for value in values:
                doc.line('td', value)

    doc = Doc()
    if row_names is not None:
        header.insert(0, '')
    else:
        row_names = [None] * len(rows)
    with doc.tag('table', klass='table table-bordered table-responsive table-striped'):
        with doc.tag('thead', klass='thead-light'):
            add_header(doc, header)
        with doc.tag('tbody'):
            for row, row_name in zip(rows, row_names):
                add_row(doc, [round(val, 2) for val in row], row_name)
    return doc.getvalue() 
开发者ID:feralvam,项目名称:easse,代码行数:27,代码来源:report.py

示例2: genxml

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def genxml(tests):
  doc, tag, text = Doc().tagtext()

  with tag("testsuites"):
    with tag("testsuite", name="Protobuf Tests"):
      for test in tests:
        with tag("testcase", name=test["name"], classname=test["name"],
                             time=test["time"]):
          with tag("system-out"):
            text(test["stdout"])
          with tag("system-err"):
            text(test["stderr"])
          if test["failure"]:
            with tag("failure"):
              text(test["failure"])

  return doc.getvalue() 
开发者ID:apple,项目名称:coremltools,代码行数:19,代码来源:make_test_output.py

示例3: get_token

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_token(request, data):
    """ Issue a token to user after verying his API_KEY
    """
    output_format = data.get('format', 'xml')
    api_key = data.get('api_key')

    if not api_key:
        raise InvalidAPIUsage(CompatError.INVALID_PARAMETERS, output_format=output_format)   # Missing required params
    if not Token.is_valid_api_key(api_key):
        raise InvalidAPIUsage(CompatError.INVALID_API_KEY, output_format=output_format)      # Invalid API_KEY

    token = Token.generate(api_key)

    doc, tag, text = Doc().tagtext()
    with tag('lfm', status='ok'):
        with tag('token'):
            text(token.token)
    return format_response('<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue()),
                           output_format) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:21,代码来源:api_compat.py

示例4: ydump_table

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def ydump_table(doc, headings, rows, **kwargs):
    """Dump an html table using yatag

    Args:
        doc: yatag Doc instance
        headings: [str]
        rows: [[str]]
            
    """
    doc, tag, text, line = doc.ttl()
    with tag('table', **kwargs):
        with tag('tr'):
            for x in headings:
                line('th', str(x))
        for row in rows:
            with tag('tr'):
                for x in row:
                    line('td', str(x)) 
开发者ID:GlobalFishingWatch,项目名称:vessel-classification,代码行数:20,代码来源:compute_vessel_metrics.py

示例5: get_plots_html

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_plots_html(orig_sents, sys_sents, ref_sents):
    doc = Doc()
    features = {
            'Compression ratio': get_compression_ratio,
            'Levenshtein similarity': get_levenshtein_similarity,
    }
    with doc.tag('div', klass='row'):
        for feature_name, feature_extractor in features.items():
            with doc.tag('div', klass='col-auto shadow-sm p-0 m-2'):
                figure = get_plotly_histogram(orig_sents, sys_sents, ref_sents, feature_extractor, feature_name)
                doc.asis(get_plotly_html(figure))
    return doc.getvalue() 
开发者ID:feralvam,项目名称:easse,代码行数:14,代码来源:report.py

示例6: get_xml_from_daily_schedule

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_xml_from_daily_schedule(self, currentTime, bgImageURL, datalist):

        now = datetime.now()
        time = now.strftime("%B %d, %Y")
        doc, tag, text, line = Doc(

        ).ttl()
        doc.asis('<?xml version="1.0" encoding="UTF-8"?>')
        with tag('schedule', currently_playing_bg_image=bgImageURL if bgImageURL != None else ''):
            for row in datalist:
                if str(row[11]) == "Commercials" and self.DEBUG == False:
                    continue
                timeB = datetime.strptime(row[8], '%I:%M:%S %p')
                if currentTime == None:
                    with tag('time',
                            ('data-key', str(row[12])),
                            ('data-current', 'false'),
                            ('data-type', str(row[11])),
                            ('data-title', str(row[3])),
                            ('data-start-time', str(row[8])),
                        ):
                        text(row[8])
                elif currentTime.hour == timeB.hour and currentTime.minute == timeB.minute:
                    with tag('time',
                            ('data-key', str(row[12])),
                            ('data-current', 'true'),
                            ('data-type', str(row[11])),
                            ('data-title', str(row[3])),
                            ('data-start-time', str(row[8])),
                        ):
                        text(row[8])
                else:
                    with tag('time',
                            ('data-key', str(row[12])),
                            ('data-current', 'false'),
                            ('data-type', str(row[11])),
                            ('data-title', str(row[3])),
                            ('data-start-time', str(row[8])),
                        ):
                        text(row[8])
        return indent(doc.getvalue()) 
开发者ID:justinemter,项目名称:pseudo-channel,代码行数:43,代码来源:PseudoDailyScheduleController.py

示例7: __init__

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def __init__(self,scanDir, targetlist):
        self.reportDir=scanDir
        self.targetlist=targetlist
        self.doc = Doc()
        self.tag = self.doc.tag
        self.line = self.doc.line
        self.stag = self.doc.stag
        self.text = self.doc.text 
开发者ID:BishopFox,项目名称:IDontSpeakSSL,代码行数:10,代码来源:idontspeakssl_report.py

示例8: run

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def run(self):
		self.doc = Doc()
		copy_js_css(self.report_folder)
		cprint("[-] Generating the HTML report...", 'blue')
		self.doc.asis('<!DOCTYPE html>')
		self.create_header()
		self.create_body()
		self.write_report()
		cprint("[+] Report generated.", 'green')
		cprint("[+] All results can be found in {}/report.html.".format(self.report_folder), 'green') 
开发者ID:BishopFox,项目名称:IDontSpeakSSL,代码行数:12,代码来源:idontspeakssl_reporter.py

示例9: make_text_bold_html

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def make_text_bold_html(text):
    doc = Doc()
    doc.line('strong', text)
    return doc.getvalue() 
开发者ID:feralvam,项目名称:easse,代码行数:6,代码来源:report.py

示例10: get_test_set_description_html

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_test_set_description_html(test_set, orig_sents, refs_sents):
    doc = Doc()
    test_set = test_set.capitalize()
    doc.line('h4', test_set)
    orig_sents = np.array(orig_sents)
    refs_sents = np.array(refs_sents)
    df = pd.DataFrame()
    df.loc[test_set, '# of samples'] = str(len(orig_sents))
    df.loc[test_set, '# of references'] = str(len(refs_sents))
    df.loc[test_set, 'Words / source'] = np.average(np.vectorize(count_words)(orig_sents))
    df.loc[test_set, 'Words / reference'] = np.average(np.vectorize(count_words)(refs_sents.flatten()))

    def modified_count_sentences(sent):
        return max(count_sentences(sent), 1)
    orig_sent_counts = np.vectorize(modified_count_sentences)(orig_sents)
    expanded_orig_sent_counts = np.expand_dims(orig_sent_counts, 0).repeat(len(refs_sents), axis=0)
    refs_sent_counts = np.vectorize(modified_count_sentences)(refs_sents)
    ratio = np.average((expanded_orig_sent_counts == 1) & (refs_sent_counts == 1))
    df.loc[test_set, '1-to-1 alignments*'] = f'{ratio*100:.1f}%'
    ratio = np.average((expanded_orig_sent_counts == 1) & (refs_sent_counts > 1))
    df.loc[test_set, '1-to-N alignments*'] = f'{ratio*100:.1f}%'
    ratio = np.average((expanded_orig_sent_counts > 1) & (refs_sent_counts > 1))
    df.loc[test_set, 'N-to-N alignments*'] = f'{ratio*100:.1f}%'
    ratio = np.average((expanded_orig_sent_counts > 1) & (refs_sent_counts == 1))
    df.loc[test_set, 'N-to-1 alignments*'] = f'{ratio*100:.1f}%'
    doc.asis(get_table_html_from_dataframe(df.round(2)))
    doc.line('p', klass='text-muted', text_content='* Alignment detection is not 100% accurate')
    return doc.getvalue() 
开发者ID:feralvam,项目名称:easse,代码行数:30,代码来源:report.py

示例11: get_plotly_html

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_plotly_html(plotly_figure):
    doc = Doc()
    plot_id = get_random_html_id()
    # Empty div to hold the plot
    with doc.tag('div', id=plot_id):
        # Embedded javascript code that uses plotly to fill the div
        with doc.tag('script'):
            doc.asis(f"var plotlyJson = '{plotly_figure.to_json()}'; var figure = JSON.parse(plotlyJson); var plotDiv = document.getElementById('{plot_id}'); Plotly.newPlot(plotDiv, figure.data, figure.layout, {{responsive: true}});")  # noqa: E501
    return doc.getvalue() 
开发者ID:feralvam,项目名称:easse,代码行数:11,代码来源:report.py

示例12: get_html_report

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_html_report(orig_sents: List[str], sys_sents: List[str], refs_sents: List[List[str]], test_set: str,
                    lowercase: bool = False, tokenizer: str = '13a', metrics: List[str] = DEFAULT_METRICS):
    doc = Doc()
    doc.asis('<!doctype html>')
    with doc.tag('html', lang='en'):
        doc.asis(get_head_html())
        with doc.tag('body', klass='container-fluid m-2 mb-5'):
            doc.line('h1', 'EASSE report', klass='mt-4')
            with doc.tag('a', klass='btn btn-link', href='https://forms.gle/J8KVkJsqYe8GvYW46'):
                doc.text('Any feedback welcome!')
            doc.stag('hr')
            doc.line('h2', 'Test set')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_test_set_description_html(
                    test_set=test_set,
                    orig_sents=orig_sents,
                    refs_sents=refs_sents,
                ))
            doc.line('h2', 'Scores')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.line('h3', 'System vs. Reference')
                doc.stag('hr')
                doc.asis(get_score_table_html_single_system(orig_sents, sys_sents, refs_sents, lowercase, tokenizer, metrics))
                doc.line('h3', 'By sentence length (characters)')
                doc.stag('hr')
                doc.asis(get_scores_by_length_html(orig_sents, sys_sents, refs_sents))
            doc.line('h2', 'Plots')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_plots_html(orig_sents, sys_sents, refs_sents[0]))
            doc.line('h2', 'Qualitative evaluation')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_qualitative_examples_html(orig_sents, sys_sents, refs_sents))
    return indent(doc.getvalue()) 
开发者ID:feralvam,项目名称:easse,代码行数:39,代码来源:report.py

示例13: get_multiple_systems_html_report

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def get_multiple_systems_html_report(orig_sents, sys_sents_list, refs_sents, system_names, test_set, lowercase, tokenizer, metrics):
    doc = Doc()
    doc.asis('<!doctype html>')
    with doc.tag('html', lang='en'):
        doc.asis(get_head_html())
        with doc.tag('body', klass='container-fluid m-2 mb-5'):
            doc.line('h1', 'EASSE report', klass='mt-4')
            with doc.tag('a', klass='btn btn-link', href='https://forms.gle/J8KVkJsqYe8GvYW46'):
                doc.text('Any feedback welcome!')
            doc.stag('hr')
            doc.line('h2', 'Test set')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_test_set_description_html(
                    test_set=test_set,
                    orig_sents=orig_sents,
                    refs_sents=refs_sents,
                ))
            doc.line('h2', 'Scores')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.line('h3', 'System vs. Reference')
                doc.stag('hr')
                doc.asis(get_score_table_html_multiple_systems(orig_sents, sys_sents_list, refs_sents, system_names, lowercase, tokenizer, metrics))
            doc.line('h2', 'Qualitative evaluation')
            doc.stag('hr')
            with doc.tag('div', klass='container-fluid'):
                doc.asis(get_multiple_systems_qualitative_examples_html(orig_sents, sys_sents_list, refs_sents, system_names))
    return indent(doc.getvalue()) 
开发者ID:feralvam,项目名称:easse,代码行数:31,代码来源:report.py

示例14: make_index

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def make_index(self):
        doc, tag, text = yattag.Doc().tagtext()
        with tag('html'):
            for key in self.list_wheels():
                with tag('a', href=self.generate_url(key)):
                    text(key.name)
                doc.stag('br')

        return doc.getvalue() 
开发者ID:WhoopInc,项目名称:mkwheelhouse,代码行数:11,代码来源:mkwheelhouse.py

示例15: session_info

# 需要导入模块: import yattag [as 别名]
# 或者: from yattag import Doc [as 别名]
def session_info(request, data):
    try:
        sk = data['sk']
        api_key = data['api_key']
        output_format = data.get('format', 'xml')
        username = data['username']
    except KeyError:
        raise InvalidAPIUsage(CompatError.INVALID_PARAMETERS, output_format=output_format)        # Missing Required Params

    session = Session.load(sk)
    if (not session) or User.load_by_name(username).id != session.user.id:
        raise InvalidAPIUsage(CompatError.INVALID_SESSION_KEY, output_format=output_format)       # Invalid Session KEY

    print("SESSION INFO for session %s, user %s" % (session.id, session.user.name))

    doc, tag, text = Doc().tagtext()
    with tag('lfm', status='ok'):
        with tag('application'):
            with tag('session'):
                with tag('name'):
                    text(session.user.name)
                with tag('key'):
                    text(session.id)
                with tag('subscriber'):
                    text('0')
                with tag('country'):
                    text('US')

    return format_response('<?xml version="1.0" encoding="utf-8"?>\n' + yattag.indent(doc.getvalue()),
                           output_format) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:32,代码来源:api_compat.py


注:本文中的yattag.Doc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。