Exemplo n.º 1
0
    def print_candidates(self):
        try:
            # New tab
            self.driver.execute_script("window.open('');")
            # Switch to the new window
            self.driver.switch_to.window(self.driver.window_handles[1])
            # Open about:webrtc
            self.driver.get('about:webrtc')
            peer_conn_elems = self.driver.find_elements(
                By.CLASS_NAME, "peer-connection")
            for peer_conn in peer_conn_elems:
                show_details_elems = peer_conn.find_elements(
                    By.XPATH, "//*[contains(text(), 'show details')]")
                for show_details in show_details_elems:
                    show_details.click()

            print("Waiting for candidates to be checked...")
            # Get ice stats
            time.sleep(15)
            # about:webrtc page refreshes each second, so we need to
            # safe the entire HTML in a variable to have a Snapshot of the situation
            about_webrtc_html = '<html>' + self.driver.find_element(
                By.TAG_NAME, 'html').get_attribute('innerHTML') + '</html>'
            # Search the tables using a parser and print all candidates
            soup = BeautifulSoup(about_webrtc_html, 'html.parser')
            for caption in soup.findAll(
                    'caption',
                {'data-l10n-id': 'about-webrtc-trickle-caption-msg'}):
                print(from_html_one(str(caption.parent)))
            # Close about:webrtc
            self.driver.close()
        except:
            print('[Warn] Some candidates may not appear in test result')
def html_to_latex_table(html_string, table_caption):
    pt = from_html_one(html_string)
    latex_table_syntax = ["\\begin{table}[h]\n\\centering", "\\end{table}"]
    latex_caption = "\\caption{" + str(table_caption) + "}"
    latex_row_size = ""
    for i in range(len(pt.field_names)):
        latex_row_size += "1"
        if i != len(pt.field_names)-1:
            latex_row_size += " "

    latex_table_begin_syntax = ["\\begin{tabular}{" + latex_row_size + "}", "\\end{tabular}"]
    latex_hline = "\\hline"
    latex_table_header = ""
    for i in range(len(pt.field_names)):
        latex_table_header += "\\textbf{" + pt.field_names[i] + "}"
        if i != len(pt.field_names)-1:
            latex_table_header += " & "
        else:
            latex_table_header += "\\\\"
    latex_table_data = ""
    for i in range(len(pt._rows)):
        td = pt._rows[i]
        td_str = ""
        for j in range(len(td)):
            td_str += str(td[j])
            if j != len(td) - 1:
                td_str += " & "
            else:
                td_str += " \\\\"
        latex_table_data = latex_table_data + td_str + "\n"

    latex_result = latex_table_syntax[0] + "\n" + \
                   latex_table_begin_syntax[0] + "\n" + \
                   latex_hline + "\n" \
                   + latex_table_header + "\n" + \
                   latex_hline + "\n" + \
                   latex_table_data + \
                   latex_hline + "\n" + \
                   latex_table_begin_syntax[1] + "\n" + \
                   latex_caption + "\n" + \
                   latex_table_syntax[1]
    return latex_result
Exemplo n.º 3
0
 def testHtmlOneAndBack(self):
     html_string = self.x.get_html_string()
     new_table = from_html_one(html_string)
     assert new_table.get_string() == self.x.get_string()
Exemplo n.º 4
0
 def testHtmlOneFailOnMany(self):
     html_string = self.x.get_html_string()
     html_string += self.x.get_html_string()
     with pytest.raises(Exception):
         from_html_one(html_string)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# =============================================================================
# Author :  Will Grant
# =============================================================================

from prettytable import from_html_one

with open("data.html", "r") as fp:
    html = fp.read()

x = from_html_one(html)
print(x)
    total_iterations = len(data_size)
    classifier_neighbor_range = [1, 5]
    spectral_peak_table_path = os.path.join(result_base_dir, "simulated_signal_pso_knn_spectral_peaks_table.html")
    performance_table_path = result_base_dir + "simulated_signal_pso_knn_average_performance_graph.html"
    n_neighbors = 1

    classification_feature_labels = ["Average Spectral Amplitude", "Mean Frequency",
                                     "Zero Lag", "Zero Crossing rate"]
    classification_features = []
    save_features = True

    classification_result_path_test = os.path.join(result_base_dir, "average_performance_graph_test" + suffix + ".html")
    classification_result_path_val = os.path.join(result_base_dir, "average_performance_graph_validation" + suffix + ".html")
    if os.path.exists(classification_result_path_test):
        with open(classification_result_path_test, 'r') as f:
            classification_result_table_test = from_html_one(f.read())
    else:
        classification_result_table_test = PrettyTable()
        classification_result_table_test.field_names = ["SL No.", "Feature", "Avg. Test Acc.", "Avg. Test Specificity",
                                       "Avg. Test Sensitivity"]
    if os.path.exists(classification_result_path_val):
        with open(classification_result_path_val, 'r') as f:
            classification_result_table_val = from_html_one(f.read())
    else:
        classification_result_table_val = PrettyTable()
        classification_result_table_val.field_names = ["SL No.", "Feature", "Avg. Validation Acc.", "Avg. Validation Specificity",
                                       "Avg. Validation Sensitivity"]

    f_file_suffix = suffix + ".npy"
    f_file = os.path.join(result_base_dir,
                          'features_' +  f_file_suffix)
Exemplo n.º 7
0
 def testHtmlOneAndBack(self):
     html_string = self.x.get_html_string()
     new_table = from_html_one(html_string)
     assert new_table.get_string() == self.x.get_string()
Exemplo n.º 8
0
def merge_tables(table_srl, table_srh, output_name):

    if not os.path.isfile(table_srl) or not os.path.isfile(table_srh):
        return None
    
    file1 = open(table_srl).read().split('\n')
    file2 = open(table_srh).read().split('\n')

    ncols = 0
    new_lines = []
    for line1, line2 in zip(file1, file2):

        sline1 = [ i.replace('\\\\','') for i in line1.split('&') ]
        sline2 = [ i.replace('\\\\','') for i in line2.split('&') ]

        if len(sline1) == 1:
            new_line = sline1[0]

            if 'hline' in new_line:
                new_lines.append(new_line)

            continue

        if not ncols:
            ncols = len(sline1) - 1

        new_list = sline1 + sline2[1:]

        # if 'for' in new_list[0]:
        #     new_list[0] = ''

        new_line = ' & '.join(new_list)

        if not 'hline' in new_line and not 'begin' in new_line and not 'end' in new_line:
            new_line += '\\\\'

        new_lines.append(new_line)


    with open(output_name, 'w') as f:
        
        s = r'\begin{{tabular}}{{l|{RCOLS}|{RCOLS}}}\hline & \multicolumn{{{NCOLS}}}{{c|}}{{\SRL}} & \multicolumn{{{NCOLS}}}{{c}}{{\SRH}}\\'.format(RCOLS='r'*ncols, NCOLS=str(ncols))

        f.write(s)
        f.write('\n'.join(new_lines))
        f.write('\end{tabular}\n')


    # merge HTML tables
    table1 = from_html_one(open(table_srl.replace('.tex', '.html')).read())
    table2 = from_html_one(open(table_srh.replace('.tex', '.html')).read())

    field_names  = [ '%s (L)' % fn for fn in table1._field_names[1:] ]
    field_names += [ '%s (H)' % fn for fn in table2._field_names[1:] ]

    table3 = PrettyTable(['',] + field_names, align={'': 'left'})

    for row1, row2  in zip(table1._rows, table2._rows):

        if row1[0] == row2[0]:
            table3.add_row(row1 + row2[1:])
        else:
            raise

    with open(output_name.replace('.tex', '.html'), 'w+') as f:
        f.write(table3.get_html_string())