kwargs["index"] = False
            kwargs["multicolumn_format"] = "c"
            kwargs["multirow"] = True
            kwargs["caption"] = f"Top {num_commits} Central Code Commits"

        return dataframe_to_table(degree_data,
                                  table_format,
                                  wrap_table,
                                  wrap_landscape=True,
                                  **kwargs)


OPTIONAL_NUM_COMMITS: CLIOptionTy = make_cli_option(
    "--num-commits",
    type=int,
    default=10,
    required=False,
    metavar="NUM",
    help="Number of commits in the table.")


class TopCentralCodeCommitsTableGenerator(
        TableGenerator,
        generator_name="top-central-code-commits-table",
        options=[REQUIRE_MULTI_CASE_STUDY, OPTIONAL_NUM_COMMITS]):
    """Generates a top-central-code-commits table for the selected case
    study(ies)."""
    def generate(self) -> tp.List[Table]:
        case_studies: tp.List[CaseStudy] = self.table_kwargs.pop("case_study")

        return [
Esempio n. 2
0
        raise NotImplementedError


class CIGArcPlotGenerator(PlotGenerator,
                          generator_name="cig-arc-plot",
                          options=[REQUIRE_CASE_STUDY, REQUIRE_REVISION]):
    """Generates an arc plot for a commit interaction graph."""
    def generate(self) -> tp.List[Plot]:
        return [
            CommitInteractionGraphArcPlot(self.plot_config, **self.plot_kwargs)
        ]


OPTIONAL_SORT_METHOD: CLIOptionTy = make_cli_option(
    "--sort-by",
    type=click.Choice(["degree", "time"]),
    default="degree",
    required=False,
    help="Sort method for commit interaction graph nodes.")


class CommitInteractionGraphNodeDegreePlot(Plot, plot_name='cig_node_degrees'):
    """
    Plot node degrees of a commit interaction graph.

    Additional arguments:
      - sort: criteria to sort the revisions [degree, time]
    """
    def plot(self, view_mode: bool) -> None:
        sort = self.plot_kwargs["sort"]
        case_study = self.plot_kwargs["plot_case_study"]
        for k, v in bb.experiment.ExperimentRegistry.experiments.items()
        if not is_experiment_excluded(k)
    })


# ------------------------------------------------------------------------------
# Predefined CLI Options
# ------------------------------------------------------------------------------

REQUIRE_CASE_STUDY: CLIOptionTy = convert_value(
    "case_study", CaseStudyConverter
)(
    make_cli_option(
        "-cs",
        "--case-study",
        type=create_single_case_study_choice(),
        required=True,
        metavar="NAME",
        help="The case study to use."
    )
)
REQUIRE_MULTI_CASE_STUDY: CLIOptionTy = convert_value(
    "case_study", CaseStudyConverter
)(
    make_cli_option(
        "-cs",
        "--case-study",
        type=create_multi_case_study_choice(),
        required=True,
        metavar="NAMES",
        help="One or more case studies to use."
    )
Esempio n. 4
0
class CommonTableOptions():
    """
    Options common to all tables.

    These options are handled by the :class:`TableGenerator` base class and are
    not passed down to specific table generators.

    Args:
        view: if `True`, view the table instead of writing it to a file
        table_dir: directory to write tables to
                  (relative to config value 'tables/table_dir')
        table_format: the format for the written table file
        dry_run: if ``True``, do not generate any files
    """

    def __init__(
        self, view: bool, table_dir: Path, table_format: TableFormat,
        wrap_table: bool, dry_run: bool
    ):
        self.view = view
        # Will be overridden when generating artefacts
        self.table_base_dir = Path(str(vara_cfg()['tables']['table_dir']))
        self.table_dir = table_dir
        self.table_format = table_format
        self.wrap_table = wrap_table
        self.dry_run = dry_run

    @staticmethod
    def from_kwargs(**kwargs: tp.Any) -> 'CommonTableOptions':
        """Construct a ``CommonTableOptions`` object from a kwargs dict."""
        table_format = kwargs.get("table_format", TableFormat.PLAIN)
        if isinstance(table_format, str):
            table_format = TableFormat[table_format]

        return CommonTableOptions(
            kwargs.get("view", False), Path(kwargs.get("table_dir", ".")),
            table_format, kwargs.get("wrap_table", False),
            kwargs.get("dry_run", False)
        )

    __options = [
        make_cli_option(
            "-v",
            "--view",
            is_flag=True,
            help="View the table instead of saving it to a file."
        ),
        make_cli_option(
            "--table-dir",
            type=click.Path(path_type=Path),
            default=Path("."),
            help="Set the directory the tables will be written to "
            "(relative to config value 'tables/table_dir')."
        ),
        make_cli_option(
            "--table-format",
            type=EnumChoice(TableFormat, case_sensitive=False),
            default="PLAIN",
            help="Format for the table."
        ),
        make_cli_option(
            "--wrap-table",
            type=bool,
            default=False,
            help="Wrap tables inside a complete latex document."
        ),
        make_cli_option(
            "--dry-run",
            is_flag=True,
            help="Only log tables that would be generated but do not "
            "generate."
            "Useful for debugging table generators."
        ),
    ]

    @classmethod
    def cli_options(cls, command: tp.Any) -> tp.Any:
        """
        Decorate a command with common table CLI options.

        This function can be used as a decorator.

        Args:
            command: the command to decorate

        Returns:
            the decorated command
        """
        return add_cli_options(command, *cls.__options)

    def get_dict(self) -> tp.Dict[str, tp.Any]:
        """
        Create a dict representation for this object.

        It holds that
        ``options == CommonTableOptions.from_kwargs(**options.get_dict())``.

        Returns:
            a dict representation of this object
        """
        return {
            "view": self.view,
            "table_format": self.table_format.name,
            "wrap_table": self.wrap_table,
            "table_dir": self.table_dir,
            "dry_run": self.dry_run
        }
Esempio n. 5
0
from varats.revision.revisions import get_processed_revisions_files
from varats.table.table import Table
from varats.table.table_utils import dataframe_to_table
from varats.table.tables import TableFormat, TableGenerator
from varats.ts_utils.cli_util import CLIOptionTy, make_cli_option
from varats.ts_utils.click_param_types import (
    REQUIRE_CASE_STUDY,
    REQUIRE_MULTI_CASE_STUDY,
)

LOG = logging.Logger(__name__)

REQUIRE_GROUND_TRUTH: CLIOptionTy = make_cli_option(
    "-gt",
    "--ground-truth",
    type=str,
    required=True,
    metavar="PATHS",
    help="One or more ground truths to use."
)

OPTIONAL_FEATURES: CLIOptionTy = make_cli_option(
    "--features",
    type=str,
    required=False,
    metavar="FEATURES",
    help="The features to use explicitly."
)


def filter_report_paths_binary(
    report_files: tp.List[Path], binary: ProjectBinaryWrapper
Esempio n. 6
0
class CommonPlotOptions():
    """
    Options common to all plots.

    These options are handled by the :class:`PlotGenerator` base class and are
    not passed down to specific plot generators.

    Args:
        view: if `True`, view the plot instead of writing it to a file
        plot_dir: directory to write plots to
                  (relative to config value 'plots/plot_dir')
        file_type: the file type for the written plot file
        dry_run: if ``True``, do not generate any files
    """
    def __init__(self, view: bool, plot_dir: Path, file_type: str,
                 dry_run: bool):
        self.view = view
        # Will be overridden when generating artefacts
        self.plot_base_dir = Path(str(vara_cfg()['plots']['plot_dir']))
        self.plot_dir = plot_dir
        self.file_type = file_type
        self.dry_run = dry_run

    @staticmethod
    def from_kwargs(**kwargs: tp.Any) -> 'CommonPlotOptions':
        """Construct a ``CommonPlotOptions`` object from a kwargs dict."""
        return CommonPlotOptions(kwargs.get("view", False),
                                 Path(kwargs.get("plot_dir", ".")),
                                 kwargs.get("file_type", "svg"),
                                 kwargs.get("dry_run", False))

    __options = [
        make_cli_option("-v",
                        "--view",
                        is_flag=True,
                        help="View the plot instead of saving it to a file."),
        make_cli_option("--file-type",
                        type=click.Choice(["png", "svg", "pdf"]),
                        default="svg",
                        help="File type for the plot."),
        make_cli_option("--plot-dir",
                        type=click.Path(path_type=Path),
                        default=Path("."),
                        help="Set the directory the plots will be written to "
                        "(relative to config value 'plots/plot_dir')."),
        make_cli_option(
            "--dry-run",
            is_flag=True,
            help="Only log plots that would be generated but do not generate."
            "Useful for debugging plot generators."),
    ]

    @classmethod
    def cli_options(cls, command: tp.Any) -> tp.Any:
        """
        Decorate a command with common plot CLI options.

        This function can be used as a decorator.

        Args:
            command: the command to decorate

        Returns:
            the decorated command
        """
        return add_cli_options(command, *cls.__options)

    def get_dict(self) -> tp.Dict[str, tp.Any]:
        """
        Create a dict representation for this object.

        It holds that
        ``options == CommonPlotOptions.from_kwargs(**options.get_dict())``.

        Returns:
            a dict representation of this object
        """
        return {
            "view": self.view,
            "file_type": self.file_type,
            "plot_dir": self.plot_dir,
            "dry_run": self.dry_run
        }
Esempio n. 7
0
    REQUIRE_REPORT_TYPE,
    REQUIRE_CASE_STUDY,
)
from varats.utils.git_util import ShortCommitHash, FullCommitHash

SUCCESS_COLOR = (0.5568627450980392, 0.7294117647058823, 0.25882352941176473)
BLOCKED_COLOR = (0.20392156862745098, 0.5411764705882353, 0.7411764705882353)
FAILED_COLOR = (0.8862745098039215, 0.2901960784313726, 0.2)
COMPILE_ERROR_COLOR = (0.8862745098039215, 0.2901960784313726, 0.2)
MISSING_COLOR = (0.984313725490196, 0.7568627450980392, 0.3686274509803922)
BACKGROUND_COLOR = (0.4666666666666667, 0.4666666666666667, 0.4666666666666667)

OPTIONAL_SHOW_BLOCKED: CLIOptionTy = make_cli_option(
    "--show-blocked/--hide-blocked",
    type=bool,
    default=True,
    required=False,
    metavar="show_blocked",
    help="Shows/hides blocked revisions.")

OPTIONAL_SHOW_ALL_BLOCKED: CLIOptionTy = make_cli_option(
    "--show-all-blocked/--hide-all-blocked",
    type=bool,
    default=False,
    required=False,
    metavar="show_all_blocked",
    help="Shows/hides all blocked revisions.")


def _gen_overview_data(tag_blocked: bool,
                       **kwargs: tp.Any) -> tp.Dict[str, tp.List[int]]:
Esempio n. 8
0
        data.sort_values("score", inplace=True)
        data.sort_index(level="fix", sort_remaining=False, inplace=True)

        kwargs: tp.Dict[str, tp.Any] = {}
        if table_format.is_latex():
            kwargs["multicolumn_format"] = "c"
            kwargs["longtable"] = True

        return dataframe_to_table(
            data, table_format, wrap_table, wrap_landscape=True, **kwargs
        )


REQUIRE_SZZ_TOOL: CLIOptionTy = make_cli_option(
    "--szz-tool",
    type=EnumChoice(SZZTool, case_sensitive=False),
    required=True,
    help="The SZZ tool for which to show the data."
)


class SZZQualityMetricsTableGenerator(
    TableGenerator,
    generator_name="szz-quality-metrics-table",
    options=[REQUIRE_MULTI_CASE_STUDY, REQUIRE_SZZ_TOOL]
):
    """Generates a szz-quality-metrics table for the selected case study."""

    def generate(self) -> tp.List[Table]:
        case_studies: tp.List[CaseStudy] = self.table_kwargs.pop("case_study")

        return [
Esempio n. 9
0
from varats.plot.plot import Plot, PlotDataEmpty
from varats.plot.plot_utils import align_yaxis, pad_axes
from varats.plot.plots import PlotGenerator
from varats.plots.scatter_plot_utils import multivariate_grid
from varats.ts_utils.cli_util import CLIOptionTy, make_cli_option
from varats.ts_utils.click_param_types import (
    EnumChoice,
    REQUIRE_MULTI_CASE_STUDY,
)
from varats.utils.git_util import FullCommitHash

LOG = logging.getLogger(__name__)

REQUIRE_X_METRIC: CLIOptionTy = make_cli_option(
    "--var-x",
    type=EnumChoice(BlameDiffMetrics, case_sensitive=False),
    required=True,
    help="The metric shown on the x-axis of the distribution comparison plot.")

REQUIRE_Y_METRIC: CLIOptionTy = make_cli_option(
    "--var-y",
    type=EnumChoice(BlameDiffMetrics, case_sensitive=False),
    required=True,
    help="The metric shown on the y-axis of the distribution comparison plot.")


def annotate_correlation(
        x_values: tp.List[int],
        y_values: tp.List[int],
        ax: axes.SubplotBase = None,
        # pylint: disable=unused-argument