_result_handler.py 3.07 KB
Newer Older
1
2
3
4
5
6
7
8
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""SuperBench CLI result subgroup command handler."""

from knack.util import CLIError

from superbench.analyzer import DataDiagnosis
9
from superbench.analyzer import ResultSummary
10
11
12
13
from superbench.common.utils import create_sb_output_dir
from superbench.cli._handler import check_argument_file


14
def diagnosis_command_handler(
15
16
    raw_data_file,
    rule_file,
17
    baseline_file=None,
18
19
20
21
    output_dir=None,
    output_file_format='excel',
    output_all=False,
    decimal_place_value=2
22
):
23
24
25
26
27
28
29
    """Run data diagnosis.

    Args:
        raw_data_file (str): Path to raw data jsonl file.
        rule_file (str): Path to baseline yaml file.
        baseline_file (str): Path to baseline json file.
        output_dir (str): Path to output directory.
30
        output_file_format (str): Format of the output file, 'excel', 'json', 'md' or 'html'. Defaults to 'excel'.
31
        output_all (bool): output diagnosis results for all nodes
32
        decimal_place_value (int): Number of decimal places to show in output.
33
34
35
36
37
    """
    try:
        # Create output directory
        sb_output_dir = create_sb_output_dir(output_dir)
        # Check arguments
38
        supported_output_format = ['excel', 'json', 'md', 'html', 'jsonl']
39
40
        if output_file_format not in supported_output_format:
            raise CLIError('Output format must be in {}.'.format(str(supported_output_format)))
41
42
        check_argument_file('raw_data_file', raw_data_file)
        check_argument_file('rule_file', rule_file)
43
44
        if baseline_file:
            check_argument_file('baseline_file', baseline_file)
45
        # Run data diagnosis
46
        DataDiagnosis().run(
47
            raw_data_file, rule_file, baseline_file, sb_output_dir, output_file_format, output_all, decimal_place_value
48
        )
49
50
    except Exception as ex:
        raise RuntimeError('Failed to run diagnosis command.') from ex
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75


def summary_command_handler(raw_data_file, rule_file, output_dir=None, output_file_format='md', decimal_place_value=2):
    """Run result summary.

    Args:
        raw_data_file (str): Path to raw data jsonl file.
        rule_file (str): Path to baseline yaml file.
        output_dir (str): Path to output directory.
        output_file_format (str): Format of the output file, 'excel', 'md' or 'html'. Defaults to 'md'.
        decimal_place_value (int): Number of decimal places to show in output.
    """
    try:
        # Create output directory
        sb_output_dir = create_sb_output_dir(output_dir)
        # Check arguments
        supported_output_format = ['excel', 'html', 'md']
        if output_file_format not in supported_output_format:
            raise CLIError('Output format must be in {}.'.format(str(supported_output_format)))
        check_argument_file('raw_data_file', raw_data_file)
        check_argument_file('rule_file', rule_file)
        # Run result summary
        ResultSummary().run(raw_data_file, rule_file, sb_output_dir, output_file_format, decimal_place_value)
    except Exception as ex:
        raise RuntimeError('Failed to run summary command.') from ex