Exemple #1
0
def eval_corr_matrix(input_file, output_file, num_types, verbose):
    """Evaluate a correlation matrix
    """
    data = io.read_npz(input_file)

    sensor_count = data.shape[0]

    in_room = []
    out_room = []

    for i in range(sensor_count):
        for j in range(sensor_count):
            if i == j:
                continue
            if i % num_types == j % num_types:
                in_room.append(data[i, j])
            else:
                out_room.append(data[i, j])

    in_summary = stats.describe(np.array(in_room))
    out_summary = stats.describe(np.array(out_room))

    table = [
        [in_summary.mean, *(in_summary.minmax), in_summary.variance],
        [out_summary.mean, *(out_summary.minmax), out_summary.variance],
    ]

    str_table = terminaltables.AsciiTable(table).table

    io.vput(str_table, verbose=verbose >= 1)
    io.save_txt(str_table, output_file)
Exemple #2
0
    def do_info(self):
        """Print out info from each client"""
        walker = self.get_local("walker")

        for idx, client in enumerate(walker.clients):
            table_data = [["attribute", "value"]]

            # TODO: add player_base and player_stat_base and all other base address (optional arg)
            client_attrs = [
                "xyz",
                "yaw",
                "roll",
                "pitch",
                "scale",
                "quest_xyz",
                "health",
                "mana",
                "potions",
                "gold",
                "energy",
                "backpack_space_used",
                "backpack_space_total",
                "move_lock",
            ]
            for attr in client_attrs:
                table_data.append([attr, self.run_coro(getattr(client, attr)())])

            table = terminaltables.AsciiTable(table_data, f"client-{idx}")
            self.write(table.table)
Exemple #3
0
 def make_details_table(obj):
     data = (
         ("ID", obj["data"].get("handle")),
         ("Name", obj["data"]["templateHistory"]["params"].get("name")),
         ("Ports", obj["data"]["templateHistory"]["params"].get("ports")),
         ("Project ID",
          obj["data"]["templateHistory"]["params"].get("project_handle")),
         ("Tuning command",
          obj["data"]["templateHistory"]["params"].get("tuning_command")),
         ("Worker command",
          obj["data"]["templateHistory"]["params"].get("worker_command")),
         ("Worker container",
          obj["data"]["templateHistory"]["params"].get("worker_container")),
         ("Worker count",
          obj["data"]["templateHistory"]["params"].get("worker_count")),
         ("Worker machine type", obj["data"]["templateHistory"]
          ["params"].get("worker_machine_type")),
         ("Worker use dockerfile", obj["data"]["templateHistory"]
          ["params"].get("worker_use_dockerfile")),
         ("Workspace URL",
          obj["data"]["templateHistory"]["params"].get("workspaceUrl")),
     )
     ascii_table = terminaltables.AsciiTable(data)
     table_string = ascii_table.table
     return table_string
Exemple #4
0
    def to_text(self, title=None, **kwargs):
        table_data = [self.fieldnames
                      ] + [[row[key] for key in self.fieldnames]
                           for row in self.get_data(**kwargs)]

        table_instance = terminaltables.AsciiTable(table_data, title=title)
        return table_instance.table
Exemple #5
0
    def execute(self, experiment_id, line, limit, follow):
        if follow:
            self.logger.log("Awaiting logs...")

        self.last_line_number = line
        table_title = "Experiment %s logs" % experiment_id
        table_data = [("JOB ID", "LINE", "MESSAGE")]
        table = terminaltables.AsciiTable(table_data, title=table_title)

        while not self.is_logs_complete:
            response = self._get_logs(experiment_id, self.last_line_number,
                                      limit)

            try:
                data = response.json()
                if not response.ok:
                    self.logger.log_error_response(data)
                    return
            except (ValueError, KeyError) as e:
                if response.status_code == 204:
                    continue
                self.logger.log(
                    "Error while parsing response data: {}".format(e))
                return
            else:
                self._log_logs_list(data, table, table_data, follow)

            if not follow:
                self.is_logs_complete = True
Exemple #6
0
def report():
    table = []
    header = ["",]
    for member in members:
        member_name, _ = member
        header.append(member_name)
    table.append(header)
    for name, metric in metrics.items():
        if metric is None:
            table.append([name,])
            continue
        mtype, query, path = metric
        url, content_type, token = apis[mtype]
        row = [name,]
        for member in members:
            _, github_id = member
            resp = requests.get(query % (url, github_id), headers={"authorization": "token %s" % token, "accept": content_type})
            if resp.ok:
                payload = resp.json()
                row.append(payload[path])
            else:
                print("error getting %s: %s" % (name, resp.json()))
                resp = requests.get("https://api.github.com/rate_limit", headers={"authorization": "token %s" % token})
                search = resp.json()["resources"]["search"]
                print(search)
                print("limit resets in %s" % (time.time() - search["reset"]))
            # respect the rate limit!
            time.sleep(3)
        table.append(row)
    ttable = terminaltables.AsciiTable(table)
    print(ttable.table)
Exemple #7
0
    def produce_execution_metrics(self, stat_source):
        res = []
        for statistics_item in stat_source:
            step_name = "{} ({})".format(
                statistics_item.step_human_readable_name,
                statistics_item.step_name)

            metrics = statistics_item.metrics
            if metrics.is_empty():
                continue

            metrics_data = [["Name", "Value"]]

            for metric_name in metrics.get_all_metrics():
                metric = metrics.get_metric(metric_name)
                metrics_data.append([
                    metric.metric_name, "{} {}".format(metric.value,
                                                       metric.units_name)
                ])

            table = terminaltables.AsciiTable(metrics_data)
            res_item = (step_name, table.table)
            res.append(res_item)

        return res
def ls_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the ls command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if tasking.input.strip() not in [
            'ls', 'dir'
    ] or tasking.agent.language != 'powershell':
        return tasking

    output = json.loads(tasking.output.decode('utf-8'))
    output_list = []
    for rec in output:
        output_list.append([
            rec.get('Mode'),
            rec.get('Owner'),
            rec.get('LastWriteTime'),
            rec.get('Length'),
            rec.get('Name')
        ])

    output_list.insert(0, ['Mode', 'Owner', 'LastWriteTime', 'Length', 'Name'])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
def test_perf():
    for i in range(1, 7):
        n = i
        m = 5

        results = score(n, m)

        ids = [tester["_id"] for tester in testers]

        table_data = []
        table_data.append(["operation"] + ids)
        table_data.append(["_gen_"] +
                          [results[id]["generation"] for id in results.keys()])
        for op in operations:
            res = [
                results[id]["operations"][op.__name__]
                for id in results.keys()
            ]
            table_data.append([op.__name__] + res)

        with open(f".results/{n}.csv", "w+") as my_csv:
            csvWriter = csv.writer(my_csv, delimiter=',')
            csvWriter.writerows(table_data)

        table_data = [table_data[0]] + [[row[0]] + color(row[1:])
                                        for row in table_data[1:]]

        table = terminaltables.AsciiTable(table_data)
        print(table.table)

    return
def print_total_bytes(large_data, do_table=True, style='ascii'):
    """

    :param large_data:
    :param do_table:
    :param style: can be ascii, markdown, or single. Sets the table style
    :return:
    """
    gbg_data = large_data[0:2] if len(large_data) > 2 else large_data
    # click.secho(f"Dbg: {gbg_data}",fg="blue")
    total_bytes = sizeof_fmt(gbg_data[1])
    gbg_bytes = sizeof_fmt(gbg_data[0])
    click.secho(f"Read {total_bytes}", fg="green")
    click.secho(f"GBG Res: {gbg_bytes}", fg="green")
    if do_table:
        headers = ['Filename', 'Bytes Read', 'Filesize']
        data = [headers]
        lgd = large_data[2]
        lgd[:, 0] = np.apply_along_axis(lambda x: x[0].name, 1, lgd)
        data = [headers]
        [data.append(v) for v in lgd]

        if style == 'markdown':
            table = terminaltables.GithubFlavoredMarkdownTable(data)
        elif style == 'ascii':
            table = terminaltables.AsciiTable(data)
        else:
            table = terminaltables.SingleTable(data)
        click.echo_via_pager(f"{table.table}")
Exemple #11
0
 def __init__(self, rows=1, cols=1, blank='---', style='ascii'):
     super().__init__()
     self.blank = blank
     header = [blank for i in range(cols)]
     self._grid = tt.AsciiTable([])
     _ = [self._grid.table_data.append(header.copy()) for _ in range(rows)]
     self._style = style
Exemple #12
0
 def initialize(self):
     # Display collection summary in log
     table_data = [[
         "Descriptor", "Linter", "Criteria", "Matching files", "Format/Fix"
     ]]
     for linter in self.master.linters:
         if linter.is_active is True:
             all_criteria = linter.file_extensions + linter.file_names_regex
             if linter.cli_lint_mode == "project":
                 files_col = "project"
             else:
                 files_col = str(len(linter.files))
             fixes_col = "yes" if linter.apply_fixes is True else "no"
             table_data += [[
                 linter.descriptor_id,
                 linter.linter_name,
                 "|".join(all_criteria),
                 files_col,
                 fixes_col,
             ]]
     table = terminaltables.AsciiTable(table_data)
     table.title = "----MATCHING LINTERS"
     logging.info("")
     for table_line in table.table.splitlines():
         logging.info(table_line)
     logging.info("")
Exemple #13
0
def ps_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the ps command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if tasking.input.strip() not in [
            "ps",
            "tasklist",
    ] or tasking.agent.language not in ["powershell", "ironpython"]:
        return tasking

    output = json.loads(tasking.output.decode("utf-8"))
    output_list = []
    for rec in output:
        output_list.append([
            rec.get("PID"),
            rec.get("ProcessName"),
            rec.get("Arch"),
            rec.get("UserName"),
            rec.get("MemUsage"),
        ])

    output_list.insert(0,
                       ["PID", "ProcessName", "Arch", "UserName", "MemUsage"])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
Exemple #14
0
 def _render_plain(self, data):
     rows = self._compute_rows(RenderTarget.plain, data)
     rows.insert(0, [
         column.title
         for column in self._flatten_columns(self.visible_columns)
     ])
     return terminaltables.AsciiTable(rows).table
Exemple #15
0
    def __str__dimensions(self):
        lst = self.__dim_to_table()

        table = terminaltables.AsciiTable(lst)
        # table.justify_columns = {2: "right", 4: "right"}
        out = table.table
        return out
 def produce_report(self):
     table_header = ["Descriptor", "Linter", "Found", "Fixed", "Errors"]
     if self.master.show_elapsed_time is True:
         table_header += ["Elapsed time"]
     table_data = [table_header]
     for linter in self.master.linters:
         if linter.is_active is True:
             nb_fixed_cell = (str(linter.number_fixed)
                              if linter.try_fix is True else "")
             if linter.cli_lint_mode == "project":
                 found = "yes"
                 errors = "yes" if linter.number_errors > 0 else "no"
                 nb_fixed_cell = "yes" if nb_fixed_cell != "" else nb_fixed_cell
             else:
                 found = str(len(linter.files))
                 errors = str(linter.number_errors)
             table_line = [
                 linter.descriptor_id,
                 linter.linter_name,
                 found,
                 nb_fixed_cell,
                 errors,
             ]
             if self.master.show_elapsed_time is True:
                 table_line += [str(round(linter.elapsed_time_s, 2)) + "s"]
             table_data += [table_line]
     table = terminaltables.AsciiTable(table_data)
     table.title = "----SUMMARY"
     # Output table in console
     logging.info("")
     for table_line in table.table.splitlines():
         logging.info(table_line)
     logging.info("")
Exemple #17
0
def ls(client: brainfm.Connection, a):
    """List stations"""
    validate_client(client)
    stations = client.list_stations()
    headers = ["id", "name", "string_id", "length"]
    data = sorted(STATIONS_PATTERN.search(stations))
    ls_title = "Available Stations"
    if a:
        ls_title = "All Stations"
    else:
        ls_title = "Playable Stations"
        data = [station for station in data if station[3]]
    for i, station in enumerate(data[:]):
        duration = int(station[3])
        if duration == 0:
            data[i][3] = "None"
        elif duration == 60:
            data[i][3] = "1 hr"
        elif duration > 60:
            data[i][3] = str(int(duration / 60)) + " hrs"
        else:
            data[i][3] = str(duration) + " mins"
    table = terminaltables.AsciiTable(table_data=[headers] + data,
                                      title=ls_title)
    print(table.table)
Exemple #18
0
    def _get_params_table(self, f_name: str) -> str:
        """
        Make parameters table.

        :param f_name: function name.
        :return: rendered parameters table (RST version)
        """
        table_data = [
            ["Parameter", "Purpose"],
        ]
        tbl = terminaltables.AsciiTable(table_data=table_data)
        tbl.inner_row_border = True
        f_docmap = self._docmap.get("doc", {}).get("tasks", {}).get(f_name, {})
        defined_parameters = f_docmap.get("parameters", {})
        for param in defined_parameters:
            param_data = f_docmap["parameters"][param]
            _req = "**required**" if param_data.get(
                "required") else "*optional*"
            _type = "type: ``{}``".format(param_data.get("type", "*object*"))
            _opt = "" if "default" not in param_data else "\n | default: ``{}``".format(
                param_data["default"])
            table_data.append([
                " ``{p}``\n\n | {r}\n | {t}{o}".format(p=param,
                                                       r=_req,
                                                       t=_type,
                                                       o=_opt),
                self._br(
                    self._wrap_description(param_data.get("description", "")))
            ])
        return self._to_rst_header_table(
            tbl.table) if defined_parameters else None
Exemple #19
0
    def print_statistics(self):
        """
        Print statistics.
        """

        table_data = []
        for n in range(len(self.norms)):
            table_headings = ['(Class) Norm', 'Metric, Epsilon', 'Raw']
            table_data.append(table_headings)
            norm = self.norms[n]

            table_row = ['    L_%.3g' % norm, 'Success Rate', '%.3g' % self.results[n]['raw_success']]
            table_data.append(table_row)

            table_row = ['    L_%.3g' % norm, 'Image Distance', '%.3g' % self.results[n]['raw_average']]
            table_data.append(table_row)

            table_row = ['    L_%.3g' % norm, 'Latent Distance', '%.3g' % self.results[n]['raw_image']]
            table_data.append(table_row)

            for c in range(self.N_class):
                table_row = ['(%d) L_%.3g' % (c, norm), 'Success Rate', '%.3g' % self.results[n]['raw_class_success'][c]]
                table_data.append(table_row)

                table_row = ['(%d) L_%.3g' % (c, norm), 'Image Distance', '%.3g' % self.results[n]['raw_class_average'][c]]
                table_data.append(table_row)

                table_row = ['(%d) L_%.3g' % (c, norm), 'Latent Distance', '%.3g' % self.results[n]['raw_class_image'][c]]
                table_data.append(table_row)
            table_data.append(['---']*(2))

        table = terminaltables.AsciiTable(table_data)
        log(table.table)
Exemple #20
0
    def on_epoch_end(self, batch, logs={}):
        self.epoch += 1

        # отберем немного сэмлов для визуализации текущего состояния модели
        samples2 = sorted(filter(lambda s: len(s.left_str) < 72, test_samples),
                          key=lambda z: random.random())[:10]
        X, y = vectorize_samples(samples2, self.computed_params)
        y_pred = model.predict(x=X, verbose=0)
        y_pred = np.argmax(y_pred, axis=-1)

        table = ['context true_output predicted_output'.split()]
        for sample, y_pred_sample in zip(samples2, y_pred):
            # Декодируем список индексов предсказанных токенов
            tokens = [self.index2token[itok] for itok in y_pred_sample]
            pred_right = ''.join(tokens).replace('▁', ' ').strip()
            if sample.right_str == pred_right:
                # выдача сетки полностью верная
                output2 = Color('{autogreen}' + pred_right + '{/autogreen}')
            elif jaccard(sample.right_str.split(), pred_right.split()) > 0.5:
                # выдача сетки частично совпала с требуемой строкой
                output2 = Color('{autoyellow}' + pred_right + '{/autoyellow}')
            else:
                # неправильная выдача сетки
                output2 = Color('{autored}' + pred_right + '{/autored}')

            table.append((sample.left_str, sample.right_str, output2))

        table = terminaltables.AsciiTable(table)
        print(table.table)
Exemple #21
0
    def diagnotistic_info(self):
        print()

        info = {
            "Maximum appendentries size": self.max_entries_in_ae,
            "Leadership changes": self.leadership_changes,
            "Log pops": self.log_pops,
            "Unique nodes": self.num_unique_nodes,
            "Membership changes": self.num_membership_changes,
            "Compactions": self.num_compactions,
        }

        for k, v in info.items():
            print(k, v)

        print()

        def abbreviate(k):
            return re.sub(r'([a-z])[a-z]*_', r'\1', k)

        # Servers
        keys = sorted(net.servers[0].debug_statistics().keys())
        print(keys)
        data = [list(map(abbreviate, keys))] + [
            [s.debug_statistics()[key] for key in keys]
            for s in net.servers
            ]
        table = terminaltables.AsciiTable(data)
        print(table.table)
Exemple #22
0
def route_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the route command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if tasking.input.strip() not in [
            "route"
    ] or tasking.agent.language != "powershell":
        return tasking

    output = json.loads(tasking.output.decode("utf-8"))

    output_list = []
    for rec in output:
        output_list.append([
            rec.get("Destination"),
            rec.get("Netmask"),
            rec.get("NextHop"),
            rec.get("Interface"),
            rec.get("Metric"),
        ])

    output_list.insert(
        0, ["Destination", "Netmask", "NextHop", "Interface", "Metric"])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
Exemple #23
0
def show_file(files, has_l, has_t):
    """
    格式化输出文件信息
    :param files: 文件列表
    :param has_l: 是否有l参数
    :param has_t: 是否有t参数
    :return:
    """
    # 根据参数信息设置表头
    if not has_l:
        if not has_t:
            table_data = [["ID", "FILE_NAME"]]
            for i in range(len(files)):
                table_data.append([i + 1, files[i]])
        else:
            table_data = [["ID", "FILE_NAME", "FILE_MTIME"]]
            for i in range(len(files)):
                table_data.append([i + 1] + files[i])
    else:
        if not has_t:
            table_data = [["ID", "FILE_NAME", "FILE_CTIME", "FILE_SIZE"]]
        else:
            table_data = [["ID", "FILE_NAME", "FILE_CTIME", "FILE_SIZE", "FILE_MTIME"]]
        for i in range(len(files)):
            table_data.append([i + 1] + files[i])

    # 创建AsciiTable对象
    table = terminaltables.AsciiTable(table_data)
    # 设置标题
    table.title = "file table"
    for i in range(len(table.column_widths)):
        if i != 1:
            # 居中显示
            table.justify_columns[i] = "center"
    print(table.table)
Exemple #24
0
def ipconfig_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the ifconfig/ipconfig command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if (tasking.input.strip() not in ["ipconfig", "ifconfig"]
            or tasking.agent.language != "powershell"):
        return tasking

    output = json.loads(tasking.output.decode("utf-8"))
    if isinstance(output,
                  dict):  # if there's only one adapter, it won't be a list.
        output = [output]

    output_list = []
    for rec in output:
        for key, value in rec.items():
            output_list.append([key, f": {value}"])
        output_list.append([])

    table = terminaltables.AsciiTable(output_list)
    table.inner_heading_row_border = False
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
Exemple #25
0
def ls_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the ls command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if (tasking.input.strip() not in ["ls", "dir"]
            or tasking.agent.language != "powershell"):
        return tasking

    output = json.loads(tasking.output.decode("utf-8"))
    output_list = []
    for rec in output:
        output_list.append([
            rec.get("Mode"),
            rec.get("Owner"),
            rec.get("LastWriteTime"),
            rec.get("Length"),
            rec.get("Name"),
        ])

    output_list.insert(0, ["Mode", "Owner", "LastWriteTime", "Length", "Name"])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
Exemple #26
0
def route_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the route command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if tasking.input.strip() not in ['route'] or tasking.agent.language != 'powershell':
        return tasking

    output = json.loads(tasking.output.decode('utf-8'))

    output_list = []
    for rec in output:
        output_list.append(
            [rec.get('Destination'), rec.get('Netmask'), rec.get('NextHop'), rec.get('Interface'), rec.get('Metric')])

    output_list.insert(0, ['Destination', 'Netmask', 'NextHop', 'Interface', 'Metric'])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
def ps_filter(tasking: models.Tasking):
    """
    This filter converts the JSON results of the ps command and converts it to a PowerShell-ish table.

    if the results are from the Python or C# agents, it does nothing.
    """
    if tasking.input.strip() not in [
            'ps', 'tasklist'
    ] or tasking.agent.language not in ['powershell', 'ironpython']:
        return tasking

    output = json.loads(tasking.output.decode('utf-8'))
    output_list = []
    for rec in output:
        output_list.append([
            rec.get('PID'),
            rec.get('ProcessName'),
            rec.get('Arch'),
            rec.get('UserName'),
            rec.get('MemUsage')
        ])

    output_list.insert(0,
                       ['PID', 'ProcessName', 'Arch', 'UserName', 'MemUsage'])

    table = terminaltables.AsciiTable(output_list)
    table.inner_row_border = False
    table.outer_border = False
    table.inner_column_border = False
    tasking.output = table.table

    return tasking
    def on_epoch_end(self, batch, logs={}):
        self.epoch += 1
        print('Epoch {} validation...'.format(self.epoch))

        # Оценка текущего качества
        score = score_model(self.model, self.test_samples, self.Xs_test,
                            self.y, self.computed_params)
        if score > self.best_score:
            print('NEW BEST SCORE={}'.format(score))
            self.best_score = score
            self.best_epoch = self.epoch
            self.wait = 0
            self.model.save_weights(self.weights_path, overwrite=True)

            # отберем немного сэмлов для визуализации текущего состояния модели
            # 16-06-2020 не будем показывать сэмплы с длиной левой части больше 71, чтобы не разваливались
            # ascii-таблицы.
            samples2 = sorted(filter(lambda s: len(s.left_str) < 72,
                                     test_samples),
                              key=lambda z: random.random())[:10]
            Xs, y = vectorize_samples(samples2, self.model_params,
                                      self.computed_params)
            y_pred = model.predict(Xs, verbose=0)
            y_pred = np.argmax(y_pred, axis=-1)

            table = ['context true_output predicted_output'.split()]
            for sample, y_pred_sample in zip(samples2, y_pred):
                # Декодируем список индексов предсказанных токенов
                tokens = [self.index2token[itok] for itok in y_pred_sample]
                pred_right = ''.join(tokens).replace('▁', ' ').strip()

                true2 = undress_output_line(sample.right_str)
                pred2 = undress_output_line(pred_right)

                if pred2 == true2:
                    # выдача сетки полностью верная
                    output2 = Color('{autogreen}' + pred_right +
                                    '{/autogreen}')
                elif jaccard(pred2.split(), true2.split()) > 0.5:
                    # выдача сетки частично совпала с требуемой строкой
                    output2 = Color('{autoyellow}' + pred_right +
                                    '{/autoyellow}')
                else:
                    # неправильная выдача сетки
                    output2 = Color('{autored}' + pred_right + '{/autored}')

                table.append((sample.left_str, sample.right_str, output2))

            table = terminaltables.AsciiTable(table)
            print(table.table)
        else:
            print(
                'val score={}; no improvement over best score={} at epoch={}'.
                format(score, self.best_score, self.best_epoch))
            self.wait += 1
            if self.wait > self.patience:
                print('Early stopping at epoch={} with best score={}'.format(
                    self.epoch, self.best_score))
                self.model.stop_training = True
Exemple #29
0
    def produce_report(self):
        table_header = ["Descriptor", "Linter", "Files", "Fixed", "Errors"]
        if self.master.show_elapsed_time is True:
            table_header += ["Elapsed time"]
        table_data = [table_header]
        for linter in self.master.linters:
            if linter.is_active is True:
                nb_fixed_cell = (str(linter.number_fixed)
                                 if linter.try_fix is True else "")
                status = ("✅" if linter.status == "success"
                          and linter.return_code == 0 else
                          "◬" if linter.status != "success"
                          and linter.return_code == 0 else "❌")
                errors = str(linter.total_number_errors)
                if linter.cli_lint_mode == "project":
                    found = "project"
                    nb_fixed_cell = "yes" if nb_fixed_cell != "" else nb_fixed_cell
                else:
                    found = str(len(linter.files))

                table_line = [
                    status + " " + linter.descriptor_id,
                    linter.linter_name,
                    found,
                    nb_fixed_cell,
                    errors,
                ]
                if self.master.show_elapsed_time is True:
                    table_line += [str(round(linter.elapsed_time_s, 2)) + "s"]
                table_data += [table_line]
        table = terminaltables.AsciiTable(table_data)
        table.title = "----SUMMARY"
        table.justify_columns = {
            0: "left",
            1: "left",
            2: "right",
            3: "right",
            4: "right",
            5: "right",
        }
        # Output table in console
        logging.info("")
        for table_line in table.table.splitlines():
            logging.info(table_line)
        logging.info("")
        if self.master.flavor_suggestions is not None:
            build_version = os.environ.get("BUILD_VERSION", "v4")
            action_version = ("v4" if "v4" in build_version else "insiders"
                              if build_version == "latest" else build_version)
            logging.warning(
                "You could have same capabilities but better runtime performances"
                " if you use a Mega-Linter flavor:")
            for suggestion in self.master.flavor_suggestions:
                action_path = f"nvuillam/mega-linter/flavors/{suggestion['flavor']}@{action_version}"
                flavor_msg = (
                    f"- [{suggestion['flavor']}] {action_path} ({suggestion['linters_number']} linters) "
                    f"{self.gh_url}/flavors/{suggestion['flavor']}/")
                logging.warning(flavor_msg)
            logging.info("")
Exemple #30
0
 def log_summary_rows(self, rows, title, window_id):
     if self.stdout:
         table_rows = [[title, ""]] + rows
         table = terminaltables.AsciiTable(table_rows)
         self.fout.write(table.table)
     else:
         for row in rows:
             self.fout.write(f"{row[0]} {row[1]}\n")