當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。