def query_solver_info_text(col):
    """
    Get a string of text, telling the user of the current solve inputs/outputs.

    :param col: The collection to compile and query.
    :type col: Collection

    :return: Text, ready for a QLabel.setText().
    :return: str
    """
    LOG.debug('query_solver_info_text: col=%r', col)
    param_num = 0
    dev_num = 0
    frm_num = 0

    color = const.COLOR_TEXT_DEFAULT
    pre_text = ''
    text = 'Deviations {dev} | Parameters {param} | Frames {frm}'
    post_text = ''

    # NOTE: We can return HTML 'rich text' in this string to allow
    # the text to be bold or coloured to indicate warnings or
    # errors.

    if col is not None:
        assert isinstance(col, mmapi.Collection)
        compile_collection(col)
        valid, message_list, metrics_list = mmapi.validate(col)
        # TODO: When there are no attributes ready to be solved with,
        #  an empty messages list is shown.
        #
        # assert len(message_list) > 0
        # assert len(metrics_list) > 0
        if valid is not True:
            color = const.COLOR_ERROR
            pre_text = '<font color="{color}">'
            post_text = '</font>'
            message = message_list[-1]
            LOG.warn(message)
        param_num_list = [d[0] for d in metrics_list]
        dev_num_list = [d[1] for d in metrics_list]
        frame_num_list = [d[2] for d in metrics_list]
        param_num = sum(param_num_list)
        dev_num = sum(dev_num_list)
        frm_num = sum(frame_num_list)

    if len(pre_text) > 0:
        pre_text = pre_text.format(color=color)
    text = text.format(param=param_num, dev=dev_num, frm=frm_num)
    text = pre_text + text + post_text
    return text
Example #2
0
def run_solve_ui(col, options, log_level, window):
    """
    Run the active "solve" (UI state information), and update the UI.

    This is a UI focused function. Calling this function with the
    'window' argument set will update the UI and show progress to the
    user. If the UI window is not given, the solve still runs, but
    does not update the UI.

    :param col: The active collection to solve.
    :type col: Collection

    :param options: Options for the solver options.
    :type options: mmSolver.api.ExecuteOptions

    :param log_level: How much information should we print out;a
                      'error', 'warning', 'info', 'verbose' or 'debug'.
    :type log_level: str

    :param window: The SolverWindow object for the UI.
    :type window: SolverWindow or None
    """
    if window is not None:
        window.setStatusLine(const.STATUS_EXECUTING)

    try:
        if window is not None:
            window.progressBar.setValue(0)
            window.progressBar.show()

        if col is None:
            msg = 'No active collection.'
            if window is not None:
                window.setStatusLine('ERROR: ' + msg)
            LOG.error(msg)
            return

        compile_collection(col)
        valid, message_list, metrics_list = mmapi.validate(col)
        assert len(message_list) > 0
        assert len(metrics_list) > 0
        if valid is not True:
            msg = message_list[-1]
            if window is not None:
                status = 'Warning: ' + msg
                window.setStatusLine(status)
            LOG.warning(msg)
        else:
            prog_fn = LOG.warning
            status_fn = LOG.warning
            info_fn = LOG.warning
            if window is not None:
                prog_fn = window.setProgressValue
                status_fn = window.setStatusLine
                info_fn = window.setSolveInfoLine

            execute_collection(
                col,
                options=options,
                log_level=log_level,
                prog_fn=prog_fn,
                status_fn=status_fn,
                info_fn=info_fn,
            )
    finally:
        if window is not None:
            window.progressBar.setValue(100)
            window.progressBar.hide()
    return
def query_solver_info_text(col):
    """
    Get a string of text, telling the user of the current solve inputs/outputs.

    :param col: The collection to compile and query.
    :type col: Collection

    :return: Text, ready for a QLabel.setText().
    :return: str
    """
    LOG.debug('query_solver_info_text: col=%r', col)
    param_num = 0
    dev_num = 0
    frm_num = 0
    failed_num = 0
    success_num = 0

    color = const.COLOR_TEXT_DEFAULT
    pre_text = ''
    text = ('Valid Solves {good_solves} | Invalid Solves {bad_solves} | '
            'Deviations {dev} | Parameters {param} | Frames {frm}')
    post_text = ''

    # NOTE: We can return HTML 'rich text' in this string to allow
    # the text to be bold or coloured to indicate warnings or
    # errors.

    if col is not None:
        assert isinstance(col, mmapi.Collection)
        compile_collection(col)
        state_list = mmapi.validate(col, as_state=True)
        status_list = [state.status for state in state_list]
        only_failure_status = [
            x for x in status_list if x != mmapi.ACTION_STATUS_SUCCESS
        ]
        failed_num = len(only_failure_status)
        success_num = len(status_list) - failed_num
        some_failure = bool(failed_num)
        if some_failure is True:
            color = const.COLOR_WARNING
            pre_text = '<font color="{color}">'
            post_text = '</font>'
            message_hashes = set()
            for state in state_list:
                if state.status != mmapi.ACTION_STATUS_SUCCESS:
                    LOG.warn("skip frames: %r", state.frames)
                    h = hash(state.message)
                    if h not in message_hashes:
                        LOG.warn(state.message)
                    message_hashes.add(h)

        param_num_list = [state.parameter_number for state in state_list]
        dev_num_list = [state.error_number for state in state_list]
        frame_num_list = [state.frames_number for state in state_list]

        param_num = sum(param_num_list)
        dev_num = sum(dev_num_list)
        frm_num = sum(frame_num_list)

    if len(pre_text) > 0:
        pre_text = pre_text.format(color=color)
    text = text.format(
        param=param_num,
        dev=dev_num,
        frm=frm_num,
        good_solves=success_num,
        bad_solves=failed_num,
    )
    text = pre_text + text + post_text
    return text