def convert_expensesummary_to_list()

in prettyprinter/textractprettyprinter/t_pretty_print_expense.py [0:0]


def convert_expensesummary_to_list(expensedocument: trp2_expense.TExpense,
                          with_confidence: bool = False,
                          with_geo: bool = False,
                          with_type: bool = True) -> List:
    """
    convert_expensesummary_to_list method for converting the Expense Summary to List for Pretty Printing.
    Arguments:
        expensedocument: The AnalyzeExpense Expense Document
        with_type: Boolean with Default value as False. Set this to True if you want the Normalized Field Type
            to be included in the pretty print output.
        with_confidence: Boolean with Default value as False. Set this to True if you want the Confidence score
            to be included in the pretty print output.
        with_geo: Boolean with default value as False. Set this to True if you want the geometry info to be included
            in the pretty print output.
    Returns:
        List of all the Expense Summary
    """
    rows_list = list()
    rows_list.append(["Key", "Value"])
    for field in expensedocument.summaryfields:
        t_key = ""
        t_value = ""
        if field.labeldetection:
            t_key = field.labeldetection.text
            if with_geo:
                t_key += f" ({field.labeldetection.geometry.boundingBox}) "
            if with_confidence:
                t_key += f" ({field.labeldetection.confidence:.1f}) "
            if with_type:
                t_key += f"({field.ftype.text})"
        else:
            if with_type:
                t_key += f"({field.ftype.text})"
        if field.valuedetection:
            t_value = field.valuedetection.text
            if with_geo:
                t_value += f" ({field.valuedetection.geometry.boundingBox}) "
            if with_confidence:
                t_value += f" ({field.valuedetection.confidence:.1f}) "
        rows_list.append([t_key, t_value])
    return rows_list